Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apollo-link-state cache.writedata results in Missing field warning

When I call a mutation on my client I get the following warning:

writeToStore.js:111 Missing field updateLocale in {}

This is my stateLink:

const stateLink = withClientState({
  cache,
  resolvers: {
    Mutation: {
      updateLocale: (root, { locale }, context) => {
        context.cache.writeData({
          data: {
            language: {
              __typename: 'Language',
              locale,
            },
          },
        });
      },
    },
  },
  defaults: {
    language: {
      __typename: 'Language',
      locale: 'nl',
    },
  },
});

And this is my component:

export default graphql(gql`
  mutation updateLocale($locale: String) {
    updateLocale(locale: $locale) @client
  }
`, {
    props: ({ mutate }) => ({
      updateLocale: locale => mutate({
        variables: { locale },
      }),
    }),
  })(LanguagePicker);

What am I missing?

like image 591
Rob Indesteege Avatar asked Dec 28 '17 10:12

Rob Indesteege


People also ask

How do you read data from Apollo cache?

You can read and write data directly to the Apollo Client cache, without communicating with your GraphQL server. You can interact with data that you previously fetched from your server, and with data that's only available locally. Use standard GraphQL queries for managing both remote and local data.

How do I reset my Apollo cache?

Resetting the cache Sometimes, you might want to reset the cache entirely, such as when a user logs out. To accomplish this, call client. resetStore . This method is asynchronous, because it also refetches any of your active queries.

How do you update the Apollo client cache after a mutation?

If a mutation updates a single existing entity, Apollo Client can automatically update that entity's value in its cache when the mutation returns. To do so, the mutation must return the id of the modified entity, along with the values of the fields that were modified.

Can I delete Apollo cache?

Apollo Client 3 enables you to selectively remove cached data that is no longer useful. The default garbage collection strategy of the gc method is suitable for most applications, but the evict method provides more fine-grained control for applications that require it.


1 Answers

At the moment, apollo-link-state requires you to return any result. It can be null too. This might be changed in the future.

like image 75
Robin Wieruch Avatar answered Oct 04 '22 13:10

Robin Wieruch