Aws-mobile-appsync-sdk-js: Problem with mutations with appsync client

Created on 2 Jul 2018  Â·  18Comments  Â·  Source: awslabs/aws-mobile-appsync-sdk-js

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:

  .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"
  }
}

Most helpful comment

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

All 18 comments

If it's any help at all - I have this same issue as above. Additionally, immediately before the above error I receive this through my error link logger:

:
"Cannot read property 'data' of undefined"
stack
:
"TypeError: Cannot read property 'data' of undefined↵    at Mutation._this.onCompletedMutation (http://localhost:3000/static/js/bundle.js:116739:37)↵    at http://localhost:3000/static/js/bundle.js:116697:27"

I know that's not much more to go on, but figured I'd leave it all the same.

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

I have the same issue. Working my way backwards, I found that the latest version where this works is in version 1.0.22.

Diff between last working and first non working: https://github.com/awslabs/aws-mobile-appsync-sdk-js/compare/aws-appsync%401.0.22...aws-appsync%401.0.23

So it's probable either #143 or #146 is the culprit.

Edit: #143 seems implausible. The most probable cause is #146

158 seems to be the same issue.

Hi @micahjonas , @mwarger , @nilsga

I've looked at the issue, and I think I know what is happening. Using offline capabilities in the SDK only make sense if you provide an optimisticResponse to your client.mutate call. Can you try providing an optimisticReponse?

Also, there will be a PR soon with a fix to better handle these scenarios.

Let me know how it goes.

That might be an issue, too. But this used to work without supplying an optimisticResponse, so I don’t think that’s the cause of this particular issue.

I still received the error after supplying an optimistic response. I
thought that could be it too and tried it without luck.

On Thu, Jul 5, 2018, 5:20 PM Nils-Helge Garli Hegvik <
[email protected]> wrote:

That might be an issue, too. But this used to work without supplying an
optimisticResponse, so I don’t think that’s the cause of this particular
issue.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/170#issuecomment-402869447,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAp652_RtlX6751qEVIRo_GXPyVMd9uPks5uDpEfgaJpZM4U_XGd
.

I don't think this is fixed, I'm using the latest versions of aws-appsync and aws-appsync-react and getting the same problem; only rolling back to versions 1.0.22 and 1.0.13 will do the trick.

appSyncClient.mutate({
            mutation: UpdateTransactionMutation,
            name: 'UpdateTransactionMutation',
            variables,
            errorPolicy: 'all',
            fetchPolicy: 'no-cache',
        }).then(({ data: { updateTransaction } }) => {
            console.log(updateTransaction);
        }).catch((error) => {
            console.log(error, null);
        })

updateTransaction comes up as null but the server responds appropriately

I can also confirm this issue. Latest version of app sync is returning mutation response as null.

Reverting aws-appsync and aws-appsync-react to 1.0.22 and 1.0.13 as @alez007 mentioned is working.

@micahjonas Can you reopen this issue

One more thing,I managed to use the latest version if I set disableOffline
to true.

On Wed, Sep 12, 2018, 18:20 Kiran notifications@github.com wrote:

I can also confirm this issue. Latest version of app sync is returning
mutation response as null.

Reverting aws-appsync and aws-appsync-react to 1.0.22 and 1.0.13 as
@alez007 https://github.com/alez007 mentioned is working.

@micahjonas https://github.com/micahjonas Can you reopen this issue

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/awslabs/aws-mobile-appsync-sdk-js/issues/170#issuecomment-420729048,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAcC1ucZbvMp5t34uh9Ej2ICK8bZlHb5ks5uaUJogaJpZM4U_XGd
.

@alez007 With aws-appsync 1.3.4 and aws-appsync-react 1.14, setting disableOffline
to true didn't work for me.

Which versions are you using now ?

Hi guys I solved my issues some time ago with just using apollo and aws-amplify directly. I don't seem to have the priviliges to reopen this issue. Maybe somebody has to reopen e new one and maybe reference this issue.

@alez007 With aws-appsync 1.3.4 and aws-appsync-react 1.14, setting disableOffline
to true didn't work for me.

Which versions are you using now ?

My current versions are: 1.3.4 and 1.1.4.

Hi guys I solved my issues some time ago with just using apollo and aws-amplify directly. I don't seem to have the priviliges to reopen this issue. Maybe somebody has to reopen e new one and maybe reference this issue.

Yes, the thought crossed my mind, I'm not really content with the progress of this library tbh. Updates are slow and brief, pull requests are just sitting there, issue number just goes up, etc.

@micahjonas I've been contemplating a move from the appsync client to using apollo directly as well. Can you share any more details on how you accomplished this? In particular I'm wondering if any workarounds are required for passing cognito tokens to the appsync server.

We are preparing a new version that has many internal changes, it should address the issues you mentioned before, however the api remains the same.

You can try our latest beta version on @deepdish-next tag (1.3.5-link-effect.2)

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

Was this page helpful?
0 / 5 - 0 ratings