Automatically join TypeORM relations based on GraphQL query fields to reduce N+1 queries. Version 3.0.0, compatible with TypeORM v0.3.x and GraphQL v14+. Unlike DataLoader, it generates a single SQL query with joins, avoiding multiple round trips. However, large nested joins may degrade performance, and it requires careful handling of circular references and depth limits. Written in TypeScript with built-in type definitions.
npm install typeorm-relations-graphqlNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows how to use getRelations to parse GraphQL info and pass relations to TypeORM find, with allowedRelations whitelist and maxDepth limit.
If using TypeORM <0.3.0, install typeorm-relations-graphql@^1
Set a maxDepth option, e.g., { maxDepth: 5 }Ensure all allowedRelations paths are defined in your entity's relations
Use import { GraphqlRelation } from 'typeorm-relations-graphql' in v3+Avoid aliases in GraphQL queries or handle alias mapping manually
Change to import { getRelations } from 'typeorm-relations-graphql'Run 'npm install typeorm-relations-graphql' and ensure tsconfig.json has 'esModuleInterop': true
Verify entity is loaded in TypeORM and has @ManyToOne or similar decorators
Add 'owner.address' to allowedRelations or remove the field from query
Pass maxDepth option to getRelations