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.

[2.0.2] apollo-client returns empty data during mutation | bug

See original GitHub issue

I am not sure if it is related to apollo-client or react-apollo but I have this issue. During mutation I will get data without cached fields.

Here is steps how to reproduce it

  1. I have one component with graphql query which is loading user by his username. It is working great. data.user contains all information.
@graphql(gql`
  query getQuestionContainerData($username: String!) {
    user(username: $username) {
      id
      isViewer
      cover
    }
  }
`, {
  options: ({ match: { params: { username } } }) => ({
    variables: {
      username,
    },
  }),
})
  1. Second component is changing users photo (it has one mutation)
@graphql(gql`
  mutation ($signed: String!) {
    user: submitUserCoverS3DirectUpload(signed: $signed) {
      id
      canEdit
      cover
    }
  }
`, {
    name: 'submitUserCoverS3DirectUpload',
  })
  1. First component will receive empty data.user (user is undefined) when second component starts mutation.
  2. After success mutation first component will receive correct data.user with all data.

My question is why I receive empty data.user ? Apollo client already have this data and I do not any clean cache.

My current deps:

    "apollo-cache-inmemory": "^1.1.0",
    "apollo-client": "^2.0.2",
    "apollo-link": "^1.0.0",
    "apollo-link-http": "^1.1.0",
    "apollo-link-batch-http": "^1.0.0",
    "apollo-link-retry": "^1.0.0",
    "apollo-link-dedup": "^1.0.0",
    "react-apollo": "^2.0.0",

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:10
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

13reactions
vincentdesmarescommented, Mar 2, 2018

I got the same issue and struggled a lot to find the source of it.

I traced it back to this part of the code which swallowed an error:

try {
  var data = this.dataStore.getCache().read({
    query: query,
    variables: variables,
    previousResult: lastResult ? lastResult.data : undefined,
    optimistic: true
  })
  return maybeDeepFreeze({ data: data, partial: false })
} catch (e) {
  return maybeDeepFreeze({ data: {}, partial: true })
}

The result of my mutation was missing a field that was present in the original request.

query test {
   house {
      id
      length
      width
   }
}
mutation test {
   updateHouse(id: 1) {
      id
      length
   }
}

Width being missing, an error was thrown, catch by the previous code, and the object house ended undefined.

I’m not sure of what I have done wrong.

I’m using the 2.1.0, so the code related to this PR is at least not covering all the cases.

@jbaxleyiii Can you reopen this issue?

6reactions
nicholas-lcommented, Nov 28, 2017

Is this published? Because I am getting a similar error, below is before and after a mutation that happens in a deeply nested child component from the query component. Loading is false and no error on data.

First is check if object is null (node) Second line is props.data Third line is props.data.error.

nodeviewer.jsx:74 data.node is null: false
nodeviewer.jsx:75 {variables: {…}, refetch: ƒ, fetchMore: ƒ, updateQuery: ƒ, startPolling: ƒ, …}error: (...)fetchMore: ƒ ()loading: falsenetworkStatus: 7node: { id: "R1RlY2hfQWRkcmVzczo1MzYxNDgwNw==", …} refetch: ƒ ()startPolling: ƒ ()stopPolling: ƒ ()subscribeToMore: ƒ ()updateQuery: ƒ ()variables: {objectId: "R1RlY2hfQWRkcmVzczo1MzYxNDgwNw=="}get error: ƒ 
nodeviewer.jsx:76 undefined

Mutation happened

nodeviewer.jsx:74 data.node is null: true
nodeviewer.jsx:75 {variables: {…}, refetch: ƒ, fetchMore: ƒ, updateQuery: ƒ, startPolling: ƒ, …}error: (...)fetchMore: ƒ ()loading: falsenetworkStatus: 7refetch: ƒ ()startPolling: ƒ ()stopPolling: ƒ ()subscribeToMore: ƒ ()updateQuery: ƒ ()variables: {objectId: "R1RlY2hfQWRkcmVzczo1MzYxNDgwNw=="}get error: ƒ ()__proto__: Object
nodeviewer.jsx:76 undefined
Read more comments on GitHub >

github_iconTop Results From Across the Web

Mutations in Apollo Client - Apollo GraphQL Docs
You can use this to enable users to dismiss mutation result data or errors in the UI. Calling reset does not remove any...
Read more >
Full Stack Error Handling with GraphQL and Apollo
If networkError is present in your response, it means your entire query was rejected, and therefore no data was returned.
Read more >
Handling operation errors - Apollo GraphQL Docs
Apollo Client can encounter a variety of errors when executing operations on your ... If resolver errors occur, your server can still return...
Read more >
Apollo Cache is completely empty as are my queries and ...
I am using Apollo dev tools, and my queries are empty, on pages that are rendering queries, and my mutations are empty when...
Read more >
React-Apollo Mutation Returns Empty Response - ADocLib
Previously cached query should reflect changes in intersecting [2.0.2] apolloclient returns empty data during mutation | bug #2496.
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