{"id":17942725,"url":"https://github.com/b1f6c1c4/graphql-advanced-projection","last_synced_at":"2025-10-28T23:04:59.440Z","repository":{"id":30333962,"uuid":"124632862","full_name":"b1f6c1c4/graphql-advanced-projection","owner":"b1f6c1c4","description":"Fully customizable Mongoose/MongoDB projection generator.","archived":false,"fork":false,"pushed_at":"2024-08-26T10:35:47.000Z","size":1380,"stargazers_count":46,"open_issues_count":8,"forks_count":5,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-02-20T15:11:18.391Z","etag":null,"topics":["apollo","apollo-server","graphql","graphql-advanced-projection","graphql-projection","javascript","mongodb","mongoose","projection"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/graphql-advanced-projection","language":"JavaScript","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/b1f6c1c4.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","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}},"created_at":"2018-03-10T07:26:42.000Z","updated_at":"2024-06-03T19:19:34.000Z","dependencies_parsed_at":"2024-05-06T11:52:54.224Z","dependency_job_id":"db74f570-83d4-4e06-b805-9c9725cd95db","html_url":"https://github.com/b1f6c1c4/graphql-advanced-projection","commit_stats":{"total_commits":186,"total_committers":4,"mean_commits":46.5,"dds":0.4354838709677419,"last_synced_commit":"cdeae75b1295c7f03247baf720f746c895576caf"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b1f6c1c4%2Fgraphql-advanced-projection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b1f6c1c4%2Fgraphql-advanced-projection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b1f6c1c4%2Fgraphql-advanced-projection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/b1f6c1c4%2Fgraphql-advanced-projection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/b1f6c1c4","download_url":"https://codeload.github.com/b1f6c1c4/graphql-advanced-projection/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240797282,"owners_count":19859164,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["apollo","apollo-server","graphql","graphql-advanced-projection","graphql-projection","javascript","mongodb","mongoose","projection"],"created_at":"2024-10-29T03:06:59.257Z","updated_at":"2025-10-28T23:04:54.385Z","avatar_url":"https://github.com/b1f6c1c4.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# graphql-advanced-projection\n\n[![npm](https://img.shields.io/npm/v/graphql-advanced-projection.svg?style=flat-square)](https://www.npmjs.com/package/graphql-advanced-projection)\n[![npm](https://img.shields.io/npm/dt/graphql-advanced-projection.svg?style=flat-square)](https://www.npmjs.com/package/graphql-advanced-projection)\n[![GitHub last commit](https://img.shields.io/github/last-commit/b1f6c1c4/graphql-advanced-projection.svg?style=flat-square)](https://github.com/b1f6c1c4/graphql-advanced-projection)\n[![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/b1f6c1c4/graphql-advanced-projection.svg?style=flat-square)](https://github.com/b1f6c1c4/graphql-advanced-projection)\n[![license](https://img.shields.io/github/license/b1f6c1c4/graphql-advanced-projection.svg?style=flat-square)](https://github.com/b1f6c1c4/graphql-advanced-projection/blob/master/LICENSE.md)\n\n[![Appveyor Build](https://img.shields.io/appveyor/build/b1f6c1c4/graphql-advanced-projection?style=flat-square)](https://ci.appveyor.com/project/b1f6c1c4/graphql-advanced-projection)\n[![Coveralls](https://img.shields.io/coveralls/github/b1f6c1c4/graphql-advanced-projection.svg?style=flat-square)](https://coveralls.io/github/b1f6c1c4/graphql-advanced-projection)\n\n\u003e Fully customizable Mongoose/MongoDB projection generator.\n\n## Why\n\nWe already have [graphql-projection](https://github.com/bharley/graphql-projection), [graphql-mongodb-projection](https://github.com/du5rte/graphql-mongodb-projection), [graphql-db-projection](https://github.com/markshapiro/graphql-db-projection), and [graphql-fields-projection](https://github.com/Impact-Technical-Resources/graphql-fields-projection).\nBut `graphql-advanced-projection` is different from all of them above in the following ways:\n* **Separete graphql schema and mongodb projection config.** This helps you decouple schema and mongodb into two parts, each of them may change independently. Write graphql in `.graphql`, write config in javascript or `.json`.\n* **Easy customization.** No more `gqlField: { type: new GraphQLNonNull(GraphQLInt), projection: 'mongoField' }`. Simply `gqlField: 'mongoField'`.\n* **We create resolvers.** `gqlField: (parent) =\u003e parent.mongoField` can be automatically generated, even complicated ones like `first: (parent) =\u003e parent.items.data[0].value`.\n* **Fully supports interfaces, fragments, and inline fragments.** Write `typeProj: 'type'` and `switch (parent.type)` in `__resolveType`.\n\n## Installation\n\n```sh\n$ npm i graphql-advanced-projection\n```\n## Usage\n\n\u003e For a complete working demo, see the `examples` folder.\n\n### Setup `mongoose`\n\n```js\nconst UserSchema = new mongoose.Schema({\n  _id: String,\n  mongoA: String,\n});\nconst User = mongoose.model('users', UserSchema);\n```\n\n### Setup `graphql`\n\n```graphql\ntype Query {\n  user(id: ID!): User\n}\ntype User {\n  userId: ID\n  field1: String\n  field2: String\n}\n```\n\n### Setup `graphql-advanced-projection`\n\n```js\nconst { project, resolvers } = gqlProjection({\n  User: {\n    proj: {\n      userId: '_id',\n      field1: 'mongoA',\n      field2: null,\n    },\n  },\n});\n```\n\n### Combine everything together\n\n```js\nconst { makeExecutableSchema } = require('@graphql-tools/schema');\n\n/* ... */\n\nmodule.exports = makeExecutableSchema({\n  typeDefs,\n  resolvers: _.merge(resolvers, {\n    Query: {\n      async user(parent, args, context, info) {\n        const proj = project(info);\n        const result = await User.findById(args.id, proj);\n        return result.toObject();\n      },\n    },\n    User: {\n      field2: () =\u003e 'Hello World',\n    },\n  }),\n  resolverValidationOptions: { requireResolversForResolveType: false },\n});\n```\n\n### Run\n\n```graphql\nquery {\n  user(id: $id) {\n    field1\n    field2\n  }\n}\n```\n```js\nproj = {\n  _id: 0,\n  mongoA: 1,\n}\n```\n\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb1f6c1c4%2Fgraphql-advanced-projection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fb1f6c1c4%2Fgraphql-advanced-projection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fb1f6c1c4%2Fgraphql-advanced-projection/lists"}