aws-amplify / aws-amplify/amplify-codegen

Settings some queries/mutations/subscriptions to null in @model directive results in more GraphQL statements/types being cut out than were set to null

Open
#765 4 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
TypeScript
Stars
59
Forks
64
PR merge metrics
No merged PRs in 30d

Description

### How did you install the Amplify CLI?

npm

### If applicable, what version of Node.js are you using?

v16.20.2

### Amplify CLI Version

12.8.2

### What operating system are you using?

Ubuntu

### Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

No manual changes made

### Describe the bug

When using the @model directive in the GraphQL schema file to set queries/mutations/subscriptions to null (or specific subsets within them), things that were not set to null are still not generated. I've noticed that since my codegen is configured to go 2 levels deep, if a type that's fully nulled out in all these fields is included in the model of another that isn't, they will be generated.

For example:

```graphql
type Resume
@model(queries: null, mutations: null, subscriptions: null)
@auth(
rules: [
{ allow: owner, operations: [read] }
{ allow: private, provider: iam }
]
) {
id: ID!
owner: String
text: String
candidate: Candidate @belongsTo
status: ResumeStatus!
}

type Candidate
@model
@auth(
rules: [
{ allow: owner, operations: [read] }
{ allow: private, provider: iam }
]
) {
id: ID!
owner: String
name: String
email: AWSEmail
phoneNumber: AWSPhone
resumes: [Resume] @hasMany
}
```

This would result in the type for `Resume` to still be generated, as Candidate should be fully generated.

In this example, though:

```graphql
type Application
@model(queries: { list: null }, mutations: null, subscriptions: null)
@auth(
rules: [
{ allow: owner, operations: [read] }
{ allow: private, provider: iam }
]
) {
id: ID!
owner: String
text: String
}
```

The get query for the model would not be generated, and the type for the `Application` itself might also not be generated (not entirely sure what's causing it to be generated or not generated).

Sometimes, even if a thing is not specified, it could be not generated at all. For example, I could not specify `subscriptions` or `mutations`, and only set `queries` to be `null`, and it would still not generate the subscriptions or mutations.

### Expected behavior

The types would all still be generated (as they are useful in other contexts), and only the statements/types/resolvers that were set to null would not be created. Similarly, if `queries` is set to `{list: null}`, the get statement would still be generated. I'm also unclear if this means the associated resolvers are also not generated.

### Reproduction steps

1. Create a schema with a model that has a `@model` directive of `@model(queries: { list: null }, mutations: null, subscriptions: null)`
2. Create another model with a similar directive, but include it as a relationship with another model that has an empty `@model`
directive.
3. Make sure the codegen is configured to go 2 nested levels deep
4. Run `amplify api push --y`

### Project Identifier

_No response_

### Log output

```
# Put your logs below this line

```

### Additional information

_No response_

### Before submitting, please confirm:

- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- [X] I have removed any sensitive information from my code snippets and submission.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.