Skip to content

Take codegen depth as an input to @model #165

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

Open
edwardfoyle opened this issue Jan 28, 2020 · 5 comments
Open

Take codegen depth as an input to @model #165

edwardfoyle opened this issue Jan 28, 2020 · 5 comments
Labels
doc-gen Issues on graphql-doc-generator feature-request New feature or request p4

Comments

@edwardfoyle
Copy link
Contributor

Is your feature request related to a problem? Please describe.
There are lots of cases where a model is self-referential and the entities have a bi-directional relationship. Eg. posts with comments where each comment has a reference back to the post. When queries and mutations are generated for these models, the return objects can be unnecessarily nested.

Describe the solution you'd like
Be able to define optional codegen depth on a per-operation basis that will override the global default. The following is an example @model SDL where this behavior would be specified

directive @model(
  queries: ModelQueryMap,
  mutations: ModelMutationMap,
  subscriptions: ModelSubscriptionMap
) on OBJECT
input ModelMutationMap { create: String, update: String, delete: String, createDepth: Int, updateDepth: Int, deleteDepth: Int }
input ModelQueryMap { get: String, list: String, getDepth: Int, listDepth: Int }
input ModelSubscriptionMap {
  onCreate: [String]
  onUpdate: [String]
  onDelete: [String]
  level: ModelSubscriptionLevel
}
enum ModelSubscriptionLevel { off public on }

And then it could be used in the following way:

type Comment @model(queries: {getDepth: 4, listDepth: 5}) {
  id: ID
}

to generate get queries with a depth of 4 and list queries with a depth of 5.

Describe alternatives you've considered
Specify a reasonable codegen depth for the current project and create custom queries / mutations for any operations where this default doesn't work. This creates unnecessary work making sure these custom queries stay in sync with the rest of the project.

Another option that seems like it may solve most use cases is to ignore the "items" field in the depth count when generating queries for one-to-many relationships. Based on discussion in aws-amplify/amplify-cli#1013 this would generate code that is closer to developer expectations. However I would not say this is the same feature because there still may be cases where you have some models that are deeply nested and others that aren't.

Additional context
There have been some other related requests made aws-amplify/amplify-cli#1013, but they all seem to target trying to come up with more sensible defaults whereas this gives the developer total control to adjust depth for each operation. Another related issue is aws-amplify/amplify-cli#2977.

@andrestone
Copy link

I'd love to see this implemented.

@dtelaroli
Copy link

+1

@kaustavghosh06 kaustavghosh06 transferred this issue from aws-amplify/amplify-cli May 10, 2021
@AaronZyLee AaronZyLee added doc-gen Issues on graphql-doc-generator feature-request New feature or request labels May 10, 2021
@hanna-becker
Copy link

hanna-becker commented Oct 14, 2021

This would be so useful! There is no one-size-fits all w.r.t statement depth in most applications. Choosing a deep level and using auto-generated statements makes our app slow. Plus, we run into an issue with nested field-level @auth properties that we now remove from the queries with an amplify hook and complicated regexes. We also tried hand-creating queries, but maintaining them is a nightmare.

@james-e-morris
Copy link

james-e-morris commented Dec 19, 2021

I wrote a bash gist that helps with this issue by running codegen configure before codegen, while also printing out the suggested configure settings before the prompt.
https://gist.github.com/Morrious/577c57621d27498103996f63ec209ebc

Fixing this Issue would make my life so much easier and require zero user input during the codegen. I currently generate graphql files of depth 2, 3, and 4 for different use cases in my application. These need to be regenerated every time I make a change to my schemas.

@karsenkeith
Copy link

Would love to see this as well. Is there any idea if this would be picked up in the near future?

@alharris-at alharris-at added the p4 label May 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-gen Issues on graphql-doc-generator feature-request New feature or request p4
Projects
None yet
Development

No branches or pull requests

8 participants