Generates MongoDB projection objects from GraphQL resolve info, enabling automatic field selection based on GraphQL queries. Version 1.1.1 (latest) is a mature, stable package with no recent releases. It supports fields, inline fragments, fragment spreads, and the Relay Edge Node pattern. Differentiators include lightweight zero-dependency implementation (only peer dependency on graphql) and simple integration with MongoDB find operations. The package is unmaintained since 2017 but remains functional for projects using older GraphQL versions.
npm install graphql-mongodb-projectionNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to generate MongoDB projection from GraphQL info and pass it to findOne.
Use import or destructure .default if using require.
Test with your GraphQL version. Consider using alternatives like @nicokaiser/graphql-mongodb-projection or manual field extraction.
Use the second parameter for field mappings: graphqlMongodbProjection(info, { 'firstName': 'first_name' }).Manually add nested fields via the mapping object or use a different library.
Use const graphqlMongodbProjection = require('graphql-mongodb-projection').default;Run npm install graphql-mongodb-projection (note: package name is all lowercase).
Ensure the resolve function has four parameters: (parent, args, context, info) and info is the fourth.