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.
npm install graphql-projectionNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Demonstrates creating a projector from a schema and using it in a resolve function to obtain a MongoDB projection object.
Always pass a valid GraphQLSchema instance: const projector = makeProjector(schema);
Consider alternatives like graphql-parse-project or implement custom logic.
Use array syntax for clarity: projection: ['field1', 'field2']
Manually extend projection logic or use a more modern library.
Ensure you call makeProjector(schema) and assign the result: const projector = makeProjector(schema);
Always pass the 4th argument (info) from the resolve function: projector(resolveInfo);
Pass a valid GraphQLSchema instance: const schema = new GraphQLSchema({...});