Replies: 2 comments 5 replies
-
You will need to use the info method and dynamically build your query based on the data the client asks for. We currently do this in production, but I can't share much more than that. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Have look at type-graphql-data loader which is easy to set up and also solves the GraphQL N+1 problem. Once set up, in most cases, you just need to add |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Let me start by saying that I'm not sure if this question should be linked to TypeGraphQL or to TypeORM. Maybe someone could help me better understand.
The problem (taken from the example directory):
If I want to fetch a recipe by ID (including the author and the ratings), I'd have to do something like this
That's great if the client wants everything. However, if the client only needs the
author
, but not theratings
, my Query would still fetch the ratings from the DB, it would just not return it.Maybe the client only wants the author ID, not the entire user object, etc.
Alternatively, I can use the
QueryBuilder
and do joins on the user/rating. But the same issue occurs since the joins are not done dynamically based on what the client wants/selects.Is there a way to only fetch the fields from the DB that the client wants?
Otherwise, the main GraphQL advantage of "solving under or overfetching" is kinda wasted for me...
Note: When using TypeGraphQL with Prisma, there is a plugin that helps solve this issue. However, I couldn't find any solution for TypeGraphQL + TypeORM.
Beta Was this translation helpful? Give feedback.
All reactions