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

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

Open
2 tasks done
ok-martin opened this issue Mar 16, 2024 · 9 comments
Open
2 tasks done
Labels
bug Something isn't working transferred Issue has been transferred from another Amplify repository

Comments

@ok-martin
Copy link

ok-martin commented Mar 16, 2024

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:
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
}
  1. 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

  1. Then I call
await API.graphql<GraphQLQuery<UpdateDbDirTableMutation>>(graphqlOperation(updateDbDirTable, { input: inputData }));

where inputData is:

{
  {
    "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

[
    {
        "path": null,
        "locations": null,
        "message": "The variables input contains a field that is not defined for input object type 'DirListInput' "
    }
]
  1. 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

Before submitting, please confirm:

  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.
@ok-martin ok-martin added the pending-triage Issues that need further discussion to determine label Mar 16, 2024
@josefaidt
Copy link
Contributor

Hey @ok-martin 👋 thanks for raising this! I'm going to transfer this over to our API repo for tracking 🙂

@josefaidt josefaidt transferred this issue from aws-amplify/amplify-cli Mar 19, 2024
@josefaidt josefaidt added the transferred Issue has been transferred from another Amplify repository label Mar 19, 2024
@phani-srikar
Copy link
Contributor

phani-srikar commented Mar 22, 2024

Hi @ok-martin, the changeset from 12.0.0 to 12.10.1 includes this codegen change which might have caused this. I've tried to reproduce this and noticed the typeName additions as well. However I have some questions:

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

I am confused by this part since the types defined here are independent of the mutation that is failing for you. Do you happen to have a diff of mutations.ts that is generated? I see that in my repro, there is an additional diff other than the __typeName as seen below:

image

@ok-martin
Copy link
Author

ok-martin commented Mar 27, 2024

Hi @phani-srikar I am confused by that too.

Here is the diff on the mutation file:

image

It is essentially the same but with __typename added

@dpilch
Copy link
Contributor

dpilch commented Apr 4, 2024

As a workaround, you can disable the addition of __typename in the query. In your .graphqlconfig.yml file set typenameIntrospection to false.

projects:
  typename:
    extensions:
      amplify:
        typenameIntrospection: false

Another thing to try, could you add a newline somewhere in GraphQL schema and then try to amplify push. This will force the API resource to update.

@dpilch dpilch added pending-response and removed pending-triage Issues that need further discussion to determine labels Apr 4, 2024
@AnilMaktala
Copy link

Hey @ok-martin, Are you still experiencing this issue?

@AnilMaktala
Copy link

Hey 👋 , This issue is being closed due to inactivity. If you are still experiencing the same problem and need further assistance, please feel free to leave a comment. This will enable us to reopen the issue and provide you with the necessary support.

Copy link

This issue is now closed. Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.

@ok-martin
Copy link
Author

I am still experiencing the issue.

It seems that it only fails to update on objects that are already in the database. If I insert a new row and then try to update it, then it all works ok.

However, when I try to update a row that was already there (from version 12.0.0) then the update fails.

@ok-martin
Copy link
Author

ok-martin commented May 1, 2024

I can confirm that the problem occurs when updating sub-fields that are missing __typename.

Is there a way to auto populate those sub-fields with __typename?

P.S thank you @dpilch. Your workaround works but I would rather solve it the proper way in case this becomes an issue with the future versions of Amplify :)

@dpilch dpilch added the bug Something isn't working label May 1, 2024
@dpilch dpilch transferred this issue from aws-amplify/amplify-category-api May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working transferred Issue has been transferred from another Amplify repository
Projects
None yet
Development

No branches or pull requests

5 participants