-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Best way to do forward resolution #5
Comments
Hey @lorefnon There is great library https://github.com/jakepusateri/graphql-list-fields that is able to give you It can be used inside @Schema()
class SuperSchema {
@Query({ type: [Issue] })
issues(
@NeededFields(['creator'])
relations: string[],
) {
console.log({ relations });
// ...
return repo.find({ relations });
}
} I've created function named import * as getFieldNames from 'graphql-list-fields';
import { Inject } from 'typegql';
function NeededFields(filterNames: string[] = []) {
return Inject(({ info }) => {
const selectionFieldNames: string[] = getFieldNames(info);
return selectionFieldNames.filter(fieldName => {
return allowed.includes(fieldName);
});
});
} It takes argument Let me know if that is helpful for you. Also, make sure to upgrade |
I've also created some example as I think it's quite common use-case: |
This is great! Thanks a lot for your work on this library. |
I am trying to prototype an application using typeorm and typegql to evaluate the feasibility of building a query efficient graphql api using this stack.
Given the following schema (Issue & User) :
I would like that when a user makes a query like:
I perform a select only on the issues table.
And when a user makes a query like:
I perform a select query on the join of two tables.
What is the best approach for doing such kind of forward query resolution of find parameters based on user query ?
So far after digging around the source and some experimentation I have arrived at what I need using the
@Inject
decorator:But I find this to be overly verbose for what I see a common use case in my application.
This can perhaps be simplified by extracting some utility functions but it will still be very repetitive when I have a dozen plus models, all exposed through the graphql api.
So I want to know if there is a better solution for this that I am missing out on ?
My familiarity with both typeorm and graphql is very limited (a few days of casual exploration).
The text was updated successfully, but these errors were encountered: