获取" selectionSet为空"使用apollo-link-state保存@client数据时出错

时间:2018-04-26 08:23:44

标签: apollo

我不确定这个错误究竟意味着什么。我试图在我的本地州调用变异时得到它

  

消息:"网络错误:selectionSet为空" networkError:   TypeError:selectionSet为null

这是我的apollo-link-state代码:

const stateLink = withClientState({
            cache,
            resolvers: {
                Mutation: {
                    setNavigationsState: (_:any, { path }:any, { cache }:any):any => {
                        cache.writeData(
                            {
                                navigationState: {
                                    __typename: 'NavigationState',
                                    path
                                }
                        });
                        return null;
                    },
                },
            },
            defaults: {
                navigationState: {
                    __typename: 'NavigationState',
                    path: "default",
                }
            },
        });

我对mutate的呼吁:

Apollo.client.mutate<FetchResult<ApolloQueryResult<any>>>({
            mutation:
            gql`
                mutation Test{
                    setNavigationsState(path:"newpath") @client{
                        path
                    }

                }
            `
        })

Graphql架构:

type RootMutation {
  setNavigationsState(path: String): NavigationState
}
type RootQuery {
  navigationState:NavigationState
}
type NavigationState {
  path:String!
}

我尝试查询时工作正常:

let _test = Apollo.client.query<RootQuery>({
            query:
            gql`
                query TEST{
                        navigationState @client{
                            path
                        }

                }
            `
        })

1 个答案:

答案 0 :(得分:1)

这可能是因为navigationState不在缓存的根目录,而是在&#39;数据中:

cache.writeData({
  data: {
     navigationState: {
       __typename: 'NavigationState',
       path
     }
  }
});