写入缓存与以Apollo链接状态突变返回实体之间有什么区别?

时间:2018-09-29 21:38:41

标签: graphql apollo apollo-client apollo-link-state apollo-link

为什么要这么做:

const stateLink = withClientState({
  cache,
  resolvers: {
    Mutation: {
      updateNetworkStatus: (_, { isConnected }, { cache }) => {
        const data = {
          networkStatus: {
            __typename: 'NetworkStatus',
            id: 1,
            isConnected
          },
        };
        cache.writeData({ data }); // <--
        return null; // <--
      },
    },
  }
});

对此:

const stateLink = withClientState({
  cache,
  resolvers: {
    Mutation: {
      updateNetworkStatus: (_, { isConnected }, { cache }) => {
        const data = {
          networkStatus: {
            __typename: 'NetworkStatus',
            id: 1,
            isConnected
          },
        };
        return data; // <--
      },
    },
  }
});

0 个答案:

没有答案