How to get this working with Nestjs #272
SamCullin
started this conversation in
Show and tell
Replies: 2 comments 3 replies
-
It's actually slightly easier than that! You don't need to create your own decorator: So the resolver method from your example should look something like this: @Resolver(of => Entity)
export class EntityQueries {
constructor(
@InjectRepository(Entity)
private readonly entityRepository: Repository<Entity>,
private readonly relationMapper: RelationMapper
) { }
@Query(returns => [Entity])
async entities(
@Args() query: Query,
@Info() info: GraphQLResolveInfo
): Promise<Entity[]> {
query.relations = Array.from(this.relationMapper.buildRelationListForQuery(Entity, info))
return this.entityRepository.find(query)
}
} |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi, thanks for the anwer, but how does Nest.js find relationMapper? Is there a Nest.js module or service? |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Spent some time trying to get this working with nestjs graphql. So I thought Id just note down my finding for anyone else looking to use this with nestjs.
You will need to create a custom paramer decorator
This will give you access to the Gql Execution Context which you will need to run the mapper
Note: I have provided the Relation Mapper to the module already.
Hopefully, this can save some other people some time. And thanks madscience for this package.
Beta Was this translation helpful? Give feedback.
All reactions