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

Provide the ability to generate queries/mutations/subscriptions to different depths #2671

Open
1 of 2 tasks
pr0g opened this issue Jun 28, 2024 · 2 comments
Open
1 of 2 tasks
Labels
feature-request New feature or request

Comments

@pr0g
Copy link

pr0g commented Jun 28, 2024

Describe the feature you'd like to request

Currently in Amplify there is a setting in graphqlconfig.yml under the extensions/amplify section called maxDepth which controls the depth of queries to generate for GraphQL queries, mutations, and subscriptions:

extensions:
  amplify:
    codeGenTarget: typescript
    generatedFileName: src/API.ts
    docsFilePath: src/graphql
    maxDepth: 4 <---- # this value

Due to the recent change to mutations and subscriptions to not allow relationships to be returned unless the authorization matches exactly, it is possible for mutations to fail and report the error:

"message": "GraphQL error: Cannot return null for non-nullable type: 'ID' within parent '<NestedModel>' (/update<Model>/<NestedModel>/id)

If the relationships are removed, things work as expected. It would be very convenient to be able to granularly control the depth of queries for mutations/queries/subscriptions separately (e.g. queries maybe set to say 3 or 4, and subscriptions and mutations set to 1).

Describe the solution you'd like

A solution like this might be useful to independently control mutations/subscriptions/queries:

extensions:
  amplify:
    codeGenTarget: typescript
    generatedFileName: src/API.ts
    docsFilePath: src/graphql
    maxQueryDepth: 4
    maxMutationDepth: 1
    maxSubscriptionDepth: 1

Or maxDepth could only apply to queries and not subscriptions and mutations by default, unless some other setting is applied or an override is set.

This is just an idea, there might be a better way to solve the problem.

The unfortunate issue today is if you have a relatively large maxDepth set (we use 4 right now), in many cases this makes default generated mutations (which up until recently have been very useful) essentially unusable given the problem described above.

Describe alternatives you've considered

This workaround described by @chrisbonifacio is a good stop-gap, but a bit clunky to rely on long-term.

Another alternative is to rely on creating custom mutations and to manually remove the nested types (relationships) as mentioned here, however this does somewhat negate the utility of the codegen for mutations.ts so would be nice to avoid if possible.

Additional context

See https://github.com/aws-amplify/docs/pull/7768/files which describes the recent change to mutations/subscriptions.

Is this something that you'd be interested in working on?

  • 👋 I may be able to implement this feature request

Would this feature include a breaking change?

  • ⚠️ This feature might incur a breaking change
@dpilch
Copy link
Member

dpilch commented Jul 1, 2024

We are investigating options so that the errors will not be present in the response. This may be done with setting different depth for some statements, but we are still researching other options.

@pr0g
Copy link
Author

pr0g commented Jul 2, 2024

Understood, thank you for the update @dpilch 👍

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

No branches or pull requests

4 participants