{"id":45042,"library":"graphql-projection","title":"graphql-projection","description":"A utility that creates a MongoDB projection object from a GraphQL query's resolve info, enabling efficient MongoDB queries by selecting only the fields requested in the GraphQL query. Version 0.1.2 is the latest and likely final release, with no recent updates. It supports custom projections for computed fields via a `projection` property in GraphQL type definitions. Differentiators include a simple API (one function), support for custom projections as arrays or space-separated strings, and no runtime dependencies aside from graphql peer. However, it is not actively maintained and lacks TypeScript definitions or modern ESM support.","status":"maintenance","version":"0.1.2","language":"javascript","source_language":"en","source_url":"https://github.com/bharley/graphql-projection","tags":["javascript","mongo","mongodb","graphql","project","projection","select"],"install":[{"cmd":"npm install graphql-projection","lang":"bash","label":"npm"},{"cmd":"yarn add graphql-projection","lang":"bash","label":"yarn"},{"cmd":"pnpm add graphql-projection","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency for parsing GraphQL schemas and queries","package":"graphql","optional":false}],"imports":[{"note":"Default export; CommonJS require works but TypeScript may need esModuleInterop.","wrong":"const makeProjector = require('graphql-projection');","symbol":"makeProjector","correct":"import makeProjector from 'graphql-projection'"},{"note":"There is no named export; only a default export.","wrong":"import { makeProjector } from 'graphql-projection'","symbol":null,"correct":"import makeProjector from 'graphql-projection'"},{"note":"makeProjector requires a GraphQL schema argument; omitting it will throw.","wrong":"const projector = makeProjector();","symbol":null,"correct":"const projector = makeProjector(schema);"}],"quickstart":{"code":"import { GraphQLSchema, GraphQLObjectType, GraphQLString, GraphQLNonNull, GraphQLInt, graphql } from 'graphql';\nimport makeProjector from 'graphql-projection';\n\nconst schema = new GraphQLSchema({\n  query: new GraphQLObjectType({\n    name: 'Query',\n    fields: () => ({\n      user: {\n        type: new GraphQLObjectType({\n          name: 'User',\n          fields: () => ({\n            id: { type: new GraphQLNonNull(GraphQLInt) },\n            name: { type: new GraphQLNonNull(GraphQLString) },\n          }),\n        }),\n        args: { id: { type: new GraphQLNonNull(GraphQLInt) } },\n        resolve: (root, args, context, info) => {\n          const projector = makeProjector(schema);\n          const projection = projector(info);\n          console.log(projection); // e.g., { id: 1, name: 1 }\n          return { id: args.id, name: 'Alice' };\n        },\n      },\n    }),\n  }),\n});\n\ngraphql(schema, '{ user(id: 1) { name } }').then(console.log);","lang":"javascript","description":"Demonstrates creating a projector from a schema and using it in a resolve function to obtain a MongoDB projection object."},"warnings":[{"fix":"Always pass a valid GraphQLSchema instance: const projector = makeProjector(schema);","message":"makeProjector must be called with a GraphQL schema; calling it without arguments will throw an error.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Consider alternatives like graphql-parse-project or implement custom logic.","message":"Package appears unmaintained; last release in 2016, no repository activity.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Use array syntax for clarity: projection: ['field1', 'field2']","message":"Custom projections defined as space-separated strings may have subtle bugs if field names contain spaces.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Manually extend projection logic or use a more modern library.","message":"Does not support fragments or inline fragments for nested types; projections may be incomplete.","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'0.1.2':34 'activ':91 'api':65 'array':73 'asid':83 'comput':51 'creat':7 'custom':48,70 'definit':60,96 'depend':82 'differenti':61 'effici':20 'enabl':19 'esm':99 'field':27,52 'final':40 'function':67 'graphql':2,14,31,58,85,104 'graphql-project':1 'howev':87 'includ':62 'info':18 'javascript':101 'lack':94 'latest':37 'like':39 'maintain':92 'modern':98 'mongo':102 'mongodb':9,21,103 'object':11 'one':66 'peer':86 'project':3,10,49,55,71,105,106 'properti':56 'queri':15,22,32 'recent':44 'releas':41 'request':28 'resolv':17 'runtim':81 'select':24,107 'separ':77 'simpl':64 'space':76 'space-separ':75 'string':78 'support':47,68,100 'type':59 'typescript':95 'updat':45 'util':5 'version':33 'via':53","created_at":"2026-06-07T12:53:05.391991+00:00","updated_at":"2026-06-07T12:53:05.391991+00:00","problems":[{"fix":"Ensure you call makeProjector(schema) and assign the result: const projector = makeProjector(schema);","cause":"Forgetting to call makeProjector with the schema before using it as a function.","error":"TypeError: projector is not a function"},{"fix":"Always pass the 4th argument (info) from the resolve function: projector(resolveInfo);","cause":"Passing an undefined or malformed resolveInfo object to the projector.","error":"Cannot read property 'fieldNodes' of undefined"},{"fix":"Pass a valid GraphQLSchema instance: const schema = new GraphQLSchema({...});","cause":"Passing a non-schema or invalid object to makeProjector.","error":"Expected schema to be a GraphQLSchema"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/bharley/graphql-projection#readme","github":"https://github.com/bharley/graphql-projection","docs":null,"changelog":null,"pypi":null,"npm":"graphql-projection","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}