A GraphQL utility that extracts relation strings from GraphQL query fields for use with MikroORM's populate feature. Version 1.0.5 is the latest stable release; the package is maintained but sees infrequent updates. It specifically targets MikroORM users who need to dynamically populate relations based on client queries, reducing over-fetching. Unlike generic graphql-fields packages, this one outputs nested relation paths in the format MikroORM expects.
npm install graphql-fields-to-relationsNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to extract relation paths from GraphQL query info and pass them to MikroORM's populate option.
Ensure your MikroORM entities use the same relation names as your GraphQL field names.
Limit query depth or add a max depth check before calling fieldsToRelations.
Ensure field names in queries match entity property names.
Migrate to graphql-fields with a MikroORM adapter if needed.
Use const fieldsToRelations = require('graphql-fields-to-relations').default or enable esModuleInterop.Ensure the resolver receives the fourth argument (info) from GraphQL.
Add a depth limit or use a query complexity analyzer.