question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with mutations with appsync client

See original GitHub issue

Hi, I’m currently setting up a new project with AppSync and React and I’m running into problems with mutations. Fetching data works fine but when I try to do any mutation the response somehow crashes. The backend receives the mutation and changes the data, but in the appsync client something goes worng and I get the following errors:

offline-link.js:97 Uncaught TypeError: Cannot read property ‘queryManager’ of undefined at Object.next (offline-link.js:97) at notifySubscription (Observable.js:126) at onNotify (Observable.js:161) at SubscriptionObserver.next (Observable.js:215) at notifySubscription (Observable.js:126) at onNotify (Observable.js:161) at SubscriptionObserver.next (Observable.js:215) at notifySubscription (Observable.js:126) at onNotify (Observable.js:161) at SubscriptionObserver.next (Observable.js:215) at httpLink.js:91

The mutation is executed in the backend and the proper information is submitted back to the browser. But the AppSync Client for some reason can’t handle the response. If I setup an ApolloClient with ‘apollo-boost’ and connect it to the same endpoint everything works as expected. Is there something wrong with my query or does the AppSync client require a diffrent setup?

Some code:

const client = new AWSAppSyncClient({
  url: config.graphqlEndpoint,
  region: config.region,
  auth: {
    type: AUTH_TYPE.AMAZON_COGNITO_USER_POOLS,
    jwtToken: async () => (await Auth.currentSession()).idToken.jwtToken
  }
});

Mutation:

client
  .mutate({
    mutation: gql`
      mutation addManagementArea($name: String!) {
        addManagementArea(name: $name) {
          __typename
          id
          name
        }
      }
    `,
    variables: { name: "test 123" }
  })
  .then(data => console.log("success", data))
  .catch(error => console.error("error", error));

If I’m running the same query with just the ApolloClient and the same setup I get a response back:

const client = new ApolloClient({
  uri: config.graphqlEndpoint,
  request: async operation => {
    operation.setContext({
      headers: {
        authorization: (await Auth.currentSession()).idToken.jwtToken
      }
    });
  }
});

Package.json:

{
  "name": "resido-web-client",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "amazon-cognito-identity-js": "2.0.6",
    "apollo-boost": "^0.1.10",
    "aws-amplify": "^0.4.1",
    "aws-appsync": "^1.1.2",
    "aws-appsync-react": "^1.0.17",
    "graphql-tag": "^2.9.2",
    "moment": "^2.22.1",
    "react": "16.4.0",
    "react-apollo": "2.1.4",
    "react-dom": "16.4.0",
    "react-redux": "^5.0.7",
    "react-router-dom": "4.2.2",
    "react-scripts": "1.1.4",
    "react-waypoint": "^8.0.1",
    "redux": "^4.0.0",
    "redux-thunk": "^2.3.0",
    "uuid": "^3.2.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:18 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
bergiecommented, Sep 22, 2018

@elorzafe can verify that 1.3.4 returns a null, and @deepdish-next fixes this. What’s the planned release date for this?

3reactions
mwargercommented, Jul 3, 2018

@micahjonas This appears to be fixed in the “deepdish” version. I just tried it and didn’t face any issues.

yarn add aws-appsync@deepdish aws-appsync-react@deepdish - this is probably unstable, but good enough for my needs at the moment.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Appsync Update and Delete mutation not working
An update mutation sample bellow, extracted from the AppSync console - instead of using codegen from Amplify. Note that field version is ...
Read more >
Run Queries and Mutations - AWS AppSync
Quick start guide for AWS AppSync. ... Choose the Mutation node to see a mutation. ... When you're done, it's time to connect...
Read more >
Lessons learned: AWS AppSync Subscriptions
Tagged with aws, serverless, appsync, graphql. ... We solved that problem by creating dummy mutations with pass-through lambda resolvers ...
Read more >
Handling operation errors - Apollo GraphQL Docs
Apollo Client helps you handle these errors according to their type, enabling you to show appropriate information to the user when an error...
Read more >
API (GraphQL) - Create, update, delete data - JavaScript
If you pass in extra input fields not expected by the AppSync schema, this query will fail. You can see this in the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found