是否可以使用apollo-link-state将javascript函数添加到本地状态?

时间:2018-03-08 10:55:41

标签: javascript apollo apollo-client

基本上我想做这样的事情(将函数myCallback添加到待办事项的callBack字段):

./解析器/待办事项:

const myCallback = () => {
  console.log('callback run');
};

const todos = {
  defaults: {
    todos: [
      {
        id: '2',
        text: 'Hi',
        completed: false,
        callBack: myCallback, // <-- Add the callback here
        __typename: 'todo',
      },
    ],
  },
};

export default todos;

但我收到错误:错误:将结果写入存储以查询未定义/ nCannot读取属性'substring'未定义

我的应用初始化如下:

import React from 'react';
import { render } from 'react-dom';
import { ApolloClient } from 'apollo-client';
import { withClientState } from 'apollo-link-state';
import { InMemoryCache } from 'apollo-cache-inmemory';
import { ApolloProvider } from 'react-apollo';

import todos from './resolvers/todos';

const cache = new InMemoryCache();

const client = new ApolloClient({
  cache,
  link: withClientState({ ...todos, cache }),
});

render(
  <ApolloProvider client={client}>
    <div />
  </ApolloProvider>,
  document.getElementById('root')
);

这可能与apollo-link-state有关,还是我做错了?

0 个答案:

没有答案