0

Why would one do this:

const clientState = {
  defaults: {
    networkStatus: {
      __typename: 'NetworkStatus',
      id: 1,
      isConnected: false,
    },
  },
  resolvers: {},
};

Over this:

const clientState = {
  resolvers: {
    Query: {
      networkStatus: () => ({
        __typename: 'NetworkStatus',
        id: 1,
        isConnected: false,
      }),
    },
  },
};

The advantages I can see of the latter approach are:

  • It's more akin to writing resolvers on the server
  • It supports async by simply returning a promise
  • It acts as a default because, from my current understanding, the resolver is only called on a cache miss.

I can't see any advantages to using the former defaults API, but I'm sure there's a reason otherwise it wouldn't exist?

Richard Scarrott
  • 6,638
  • 1
  • 35
  • 46
  • I always thought that `defaults` are just default store value, but in Query under resolver you can fine tune the response you need (instead of just returning current value from store). Wont this just always return default value, regardless of whats in the store ? – somerandomusername Oct 01 '18 at 09:17
  • @somerandomusername from my tests it only calls the Query resolvers on a cache miss. This means, should a mutation update the cache, the next query will read the updated value. – Richard Scarrott Oct 01 '18 at 09:43

0 Answers0