aws-amplify / aws-amplify/amplify-codegen

Mutations break after aws-amplify/cli update: "input contains a field that is not defined"

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

Description

### How did you install the Amplify CLI?

npm install -g @aws-amplify/cli@12.10.1

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

21.7.1

### Amplify CLI Version

12.10.1

GraphQL transformer version: 2

### What operating system are you using?

Windows

### 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

After upgrading from `@aws-amplify/cli@12.0.0` to `@aws-amplify/cli@12.10.1` I am unable to do any mutations. All of them return the error: `"The variables input contains a field that is not defined for input object type 'DirListInput' "`

### Expected behavior

Carry out the mutation successfully without throwing an error as it did in `@aws-amplify/cli@12.0.0`

### Reproduction steps

I am running a react app with `"aws-amplify": "5.3.17"`

1. (simplified) schema.graphql:
```graphql
type DbDirTable @model(timestamps: { createdAt: "createdAt", updatedAt: "modifiedAt" }) {
id: ID!
createdAt: AWSDateTime!
modifiedAt: AWSDateTime!
dirList: [DirList!]!
copiedFromId: String
}

type DirList {
id: ID!
items: [DirListItem!]!
title: String
colour: String
}

type DirListItem {
id: ID!
note: String
visited: Boolean
}
```

2. After running `amplify push --y` it changed:
```
src/API.ts
src/graphql/mutations.ts
src/graphql/queries.ts
src/graphql/schema.json
src/graphql/subscriptions.ts
```

The difference in those files was that it added `__typename` to every type, input, mutation and query

3. Then I call
```ts
await API.graphql>(graphqlOperation(updateDbDirTable, { input: inputData }));
```

where inputData is:
```ts
{
{
"id": "3894a81b-4e93-4627-aae1-0a0617a8ed75",
"dirList": [
{
"id": "a9cb6ec9-0254-4d37-ac96-e25e46f50a42",
"items": [],
"title": "One",
"colour": null,
},
{
"id": "09701984-fe07-4140-b36a-c9ecd8ca0549",
"items": [
{
"id": "6535fb67-f55d-475c-b32d-065f5b26f4ee",
"note": null,
"visited": null,
}
],
"title": "Two",
"colour": null,
}
]
}
```

But it throws the error
```json
[
{
"path": null,
"locations": null,
"message": "The variables input contains a field that is not defined for input object type 'DirListInput' "
}
]
```

4. `updateDbDirTable` is auto-generated in `src/graphql/mutations`. I am not using any custom resolvers or overrides

### Project Identifier

_No response_

### Log output

```
# Put your logs below this line

```

### Additional information

If I discard changes in the graphql the code in step 3 works ok

If I downgrade to 12.0.0 and re-generate the graphql files the code in step 3 works ok

Same issue on 12.4.0 because it adds the same changes as 12.10.1 to the auto-generated graphql and API

**I noticed that if I keep all of the regenerated changes and only discard the `src/graphql/queries.ts` then the code works ok**

The **only** new change in `src/graphql/queries.ts` is that it added `__typename` everywhere.

This is strange since all my queries, when called directly, work fine with the newly generated file and they fetch the data ok.

![image](https://github.com/aws-amplify/amplify-cli/assets/22411906/b02fe292-5b7d-410a-b2d4-c940b500032b)

### 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.