{"id":13624505,"url":"https://github.com/woovibr/graphql-mongoose-loader","last_synced_at":"2026-01-16T05:39:27.210Z","repository":{"id":38307938,"uuid":"95105554","full_name":"woovibr/graphql-mongoose-loader","owner":"woovibr","description":"GraphQL Mongoose Loader helpers","archived":false,"fork":false,"pushed_at":"2025-06-23T13:01:54.000Z","size":1885,"stargazers_count":115,"open_issues_count":4,"forks_count":16,"subscribers_count":14,"default_branch":"main","last_synced_at":"2025-11-06T21:22:38.650Z","etag":null,"topics":["entria","graphql","loader","mongoose","resolver"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/woovibr.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-06-22T10:50:06.000Z","updated_at":"2025-11-01T17:07:32.000Z","dependencies_parsed_at":"2024-01-14T08:22:44.829Z","dependency_job_id":"a24d1846-8e98-434b-8de4-5a426cb31988","html_url":"https://github.com/woovibr/graphql-mongoose-loader","commit_stats":{"total_commits":283,"total_committers":20,"mean_commits":14.15,"dds":0.657243816254417,"last_synced_commit":"3b01c21eba7b674934616aeafb541a5b9f9394a9"},"previous_names":["woovibr/graphql-mongoose-loader","entria/graphql-mongoose-loader"],"tags_count":29,"template":false,"template_full_name":null,"purl":"pkg:github/woovibr/graphql-mongoose-loader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/woovibr%2Fgraphql-mongoose-loader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/woovibr%2Fgraphql-mongoose-loader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/woovibr%2Fgraphql-mongoose-loader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/woovibr%2Fgraphql-mongoose-loader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/woovibr","download_url":"https://codeload.github.com/woovibr/graphql-mongoose-loader/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/woovibr%2Fgraphql-mongoose-loader/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28477382,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-16T03:13:13.607Z","status":"ssl_error","status_checked_at":"2026-01-16T03:11:47.863Z","response_time":107,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["entria","graphql","loader","mongoose","resolver"],"created_at":"2024-08-01T21:01:43.249Z","updated_at":"2026-01-16T05:39:27.173Z","avatar_url":"https://github.com/woovibr.png","language":"TypeScript","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"readme":"# GraphQL Mongoose Loader\n\n## Install\n```\nnpm i @woovi/graphql-mongoose-loader --save\nyarn add @woovi/graphql-mongoose-loader\n```\n\n## Mongoose Dataloader Batch\n\nAdd batch to your GraphQL resolvers/loaders\n\nDefine a mongoose schema for your model\n```jsx\nimport mongoose from 'mongoose';\n\nconst Schema = new mongoose.Schema(\n  {\n    name: {\n      type: String,\n    },\n    email: {\n      type: String,\n      required: true,\n      index: true,\n    },\n    password: {\n      type: String,\n      hidden: true,\n    },\n  },\n  {\n    collection: 'User',\n  },\n);\n\nexport default mongoose.model('User', Schema);\n```\n\nCreate a Dataloader for it\n\n```jsx\nimport { mongooseLoader } from '@woovi/graphql-mongoose-loader';\nimport UserModel from './User';\n\nexport const getLoader = () =\u003e new DataLoader(ids =\u003e mongooseLoader(UserModel, ids));\n```\n\n## Connection from Mongoose Cursor\n\nCreate a connection from mongoose cursor\n\n```jsx\nimport { connectionFromMongoCursor } from '@woovi/graphql-mongoose-loader';\n\nexport const loadUsers = async (context: GraphQLContext, args: ConnectionArguments) =\u003e {\n  const where = args.search\n    ? {\n        name: {\n          $regex: new RegExp(`^${args.search}`, 'ig'),\n        },\n      }\n    : {};\n  const users = UserModel.find(where, { _id: 1 }).sort({\n    createdAt: -1,\n  });\n\n  return connectionFromMongoCursor({\n    cursor: users,\n    context,\n    args,\n    loader: load,\n  });\n};\n```\n\n## Connection from Mongoose Aggregate\n\nCreate a connection from mongoose aggregate\n\n```jsx\nimport { connectionFromMongoAggregate } from '@woovi/graphql-mongoose-loader';\n\nexport const loadUsersThatHaveGroup = async (context: GraphQLContext, args: ConnectionArguments) =\u003e {\n  const aggregate = GroupModel.aggregate([\n    {\n      $lookup: {\n        from: 'User',\n        localField: 'users',\n        foreignField: '_id',\n        as: 'users',\n      },\n    },\n    {\n      // remove empty groups\n      $match: { users: { $exists: true, $ne: [] } },\n    },\n    {\n      // promote each user to a new document\n      $unwind: '$users',\n    },\n    {\n      $sort: {\n        _id: 1,\n      },\n    },\n    {\n      $replaceRoot: { newRoot: '$users' },\n    },\n  ]);\n\n  return connectionFromMongoAggregate({\n    aggregate,\n    context,\n    args,\n    loader: load,\n  });\n};\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwoovibr%2Fgraphql-mongoose-loader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwoovibr%2Fgraphql-mongoose-loader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwoovibr%2Fgraphql-mongoose-loader/lists"}