Skip to content
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

Ability to extend or shape the graphql queries generated by codegen without writing completely new queries/mutations #45

Open
hisham opened this issue Jan 25, 2019 · 5 comments
Labels

Comments

@hisham
Copy link
Contributor

hisham commented Jan 25, 2019

Is your feature request related to a problem? Please describe.
Codgen is great for getting started, but there's often cases where we need to customize the queries and create new custom queries. Cases where certain fields would be too expensive to resolve, or more nesting depth is required, or including optional variables in nested fields (codegen I believe defaults to only retrieving required variables for nested objects). If there are field resolvers that are slow, or highly relational data, then the default queries codegen generates could degrade performance unnecessarily. One can argue Apollo has a great caching layer so what's wrong with asking for as much info as possible in a query since it's a one time hit but I think you can still run into cases like mutations where the query that is run after a mutation could be more than what you want.

As background, this came out from this discussion here: aws-amplify/amplify-cli#745

Describe the solution you'd like
The current solution is to write your own custom queries, disregarding what codgen produces from the GraphQL schema. I think a better solution at minimum is for the codgen code to use fragments when generating queries (see https://www.apollographql.com/docs/react/advanced/fragments.html). And maybe then during runtime, in different parts of the code if a query needs to be customized, we can just pass in a different fragment instead completely writing the new query.

Another possible solution is some kind of dynamic query generator that works off of a base query codegen generates but then you pass it fields to include or omit (kind of like lodash's pick or omit functionality (https://lodash.com/docs/4.17.11#omit)) and it gives you the customized query back as requested.

Describe alternatives you've considered
The current solution is to write your own custom queries and include them in the dir that codgen scans to generate types and APIs. This works fine but these custom queries have to then be manually updated when the GraphQL schema changes. Also you can run into cases where codgen generates multiple variations of types that all refer to the same object but the compiler or transpiler doesn't recognize them as so and so then you have to re-cast to unknown and then back to the type you want.

Additional context
I am new to graphql and still learning. Above are my suggestions based on what I know and ran into developing a graphql client but the community may have an already established way to to do this. There might be things to learn from the sql world as well since this is very similar, codegen is essentially generating "select *" sql scripts for us when all I need is something similar to Rails' Active Record "select" method to pass in the variables I need (https://guides.rubyonrails.org/active_record_querying.html#selecting-specific-fields).

@regenrek
Copy link

regenrek commented Apr 6, 2019

Hey @hisham did you find any workaround for this scenario?

@hisham
Copy link
Contributor Author

hisham commented Apr 7, 2019

@regenrek not really. I'm just writing custom queries for now. See aws-amplify/amplify-cli#745 (comment)

@AaronZyLee AaronZyLee transferred this issue from aws-amplify/amplify-cli Jan 29, 2021
@phani-srikar phani-srikar added doc-gen Issues on graphql-doc-generator type-gen Issues on graphql-type-generator feature-request New feature or request plugins-support labels Feb 3, 2021
@phani-srikar phani-srikar removed doc-gen Issues on graphql-doc-generator type-gen Issues on graphql-type-generator labels Mar 29, 2022
@judygab
Copy link

judygab commented May 30, 2023

any updates on this?

@B33fb0n3
Copy link

any update? :(

@klausroeller
Copy link

yes, any update?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants