Amplify-js: Error when doing API.graphql update - `Unhandled Rejection (Error): Invalid AST Node: undefined`

Created on 15 Sep 2020  路  3Comments  路  Source: aws-amplify/amplify-js

Describe the bug

This is what i was trying to do:

await API.graphql({ query: updateBlog, variables: { input } });

This is what i got:

image

I have no idea what this Unhandled Rejection (Error): Invalid AST Node: undefined means and the error is very unhelpful.

To Reproduce

https://github.com/sw-yx/talk-react-summit-demo-cms

add this to updateBlog:

    return async function (newValues: Blog) {
      const timestamp = new Date();
      const newBlog: Blog = {
        ...newValues,
        createdAt: oldValues.createdAt,
        updatedAt: timestamp,
      };
      setBlogs([...blogs.filter((x) => x.id !== oldValues.id), newBlog]);
      const { createdAt, updatedAt, ...input } = newBlog;
      console.log({ input }); // i have checked that the input here should be valid
      await API.graphql({ query: updateBlog, variables: { input } }); // the problem is here
    };
  }

Expected behavior

it should just work

What is Configured?
If applicable, please provide what is configured for Amplify CLI:

  • Which steps did you follow via Amplify CLI when configuring your resources.
  • Which resources do you have configured?

    • If applicable, please provide your aws-exports file:

```
const awsmobile = {
"aws_project_region": "us-east-1",
"aws_appsync_graphqlEndpoint": "https://hl5cqmuevvatjlsg7pidqllhpa.appsync-api.us-east-1.amazonaws.com/graphql",
"aws_appsync_region": "us-east-1",
"aws_appsync_authenticationType": "API_KEY",
"aws_appsync_apiKey": "da2-ptzhxarenzdf7ljabwlkxbjdxu"
};

export default awsmobile;

```


Environment

npx: installed 1 in 1.408s

  System:
    OS: macOS Mojave 10.14.6
    CPU: (8) x64 Intel(R) Core(TM) i7-8569U CPU @ 2.80GHz
    Memory: 65.03 MB / 16.00 GB
    Shell: 5.3 - /bin/zsh
  Binaries:
    Node: 12.18.0 - /usr/local/bin/node
    Yarn: 1.22.4 - /usr/local/bin/yarn
    npm: 6.14.7 - /usr/local/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Browsers:
    Chrome: 85.0.4183.102
    Firefox: 68.8.0
    Safari: 13.1.2
  npmPackages:
    @chakra-ui/core: ^1.0.0-rc.3 => 1.0.0-rc.3 
    @testing-library/jest-dom: ^4.2.4 => 4.2.4 
    @testing-library/react: ^9.3.2 => 9.5.0 
    @testing-library/user-event: ^7.1.2 => 7.2.1 
    @types/jest: ^24.0.0 => 24.9.1 
    @types/node: ^12.0.0 => 12.12.58 
    @types/react: ^16.9.0 => 16.9.49 
    @types/react-dom: ^16.9.0 => 16.9.8 
    aws-amplify: ^3.2.0 => 3.2.0 
    formik: ^2.1.5 => 2.1.5 
    react: ^16.13.1 => 16.13.1 
    react-dom: ^16.13.1 => 16.13.1 
    react-scripts: 3.4.3 => 3.4.3 
    typescript: ^4.0.2 => 4.0.2 
  npmGlobalPackages:
    @11ty/eleventy: 0.11.0
    @aws-amplify/cli: 4.26.1-flutter-preview.0
    @prisma/cli: 2.6.1
    diff-so-fancy: 1.3.0
    expo-cli: 3.21.5
    generator-code: 1.2.19
    netlify-cli: 2.53.0
    npm: 6.14.7
    vsce: 1.77.0
    yo: 3.1.1

GraphQL to-be-reproduced

Most helpful comment

i have discovered this is my fault - i have another function that is also called updateBlog and that was being shadowed unintentionally. sorry for the noise

All 3 comments

Can you please share your GraphQL Schema? This looks like an issue with the code generator (whose output you're importing). Please also share the generated updateBlog import.

i have discovered this is my fault - i have another function that is also called updateBlog and that was being shadowed unintentionally. sorry for the noise

All good :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rygo6 picture rygo6  路  3Comments

shinnapatthesix picture shinnapatthesix  路  3Comments

TheRealRed7 picture TheRealRed7  路  3Comments

benevolentprof picture benevolentprof  路  3Comments

karlmosenbacher picture karlmosenbacher  路  3Comments