在查询中找到 @client 指令,但未指定 ApolloClient 解析器
Found @client directives in a query but no ApolloClient resolvers were specified
OS: Windows 10 专业版
阿波罗客户端:2.6.3
阿波罗提升:0.1.16
任何人都可以解释为什么我会收到以下错误消息吗?:
Found @client directives in a query but no ApolloClient resolvers were
specified. This means ApolloClient local resolver handling has been
disabled, and @client directives will be passed through to your link
chain.
当我按如下方式定义我的 ApolloClient 时:
return new ApolloClient({
uri: process.env.NODE_ENV === 'development' ? endpoint : prodEndpoint,
request: operation => {
operation.setContext({
fetchOptions: {
credentials: 'include',
},
headers: { cookie: headers && headers.cookie },
});
},
// local data
clientState: {
resolvers: {
Mutation: {
toggleCart(_, variables, { cache }) {
// Read the cartOpen value from the cache
const { cartOpen } = cache.readQuery({
query: LOCAL_STATE_QUERY,
});
// Write the cart State to the opposite
const data = {
data: { cartOpen: !cartOpen },
};
cache.writeData(data);
return data;
},
},
},
defaults: {
cartOpen: false,
},
},
});
来自docs:
If you're interested in integrating local state handling capabilities with Apollo Client < 2.5, please refer to our (now deprecated) apollo-link-state project. As of Apollo Client 2.5, local state handling is baked into the core, which means it is no longer necessary to use apollo-link-state
clientState
配置选项仅用于 apollo-link-state
。您需要将解析器直接添加到配置中,如文档中所示:
new ApolloClient({
uri: '/graphql',
resolvers: { ... },
})
另请注意,不再有 defaults
选项 -- 应通过直接在缓存实例上调用 writeData
来初始化缓存(请参阅 here)。
我建议阅读最新的文档并避免使用来自外部来源的任何示例(例如现有的存储库或教程),因为这些可能已过时。
注意:从 3.0 版开始,writeData
已被删除,取而代之的是 writeFragment
和 writeQuery
。
OS: Windows 10 专业版
阿波罗客户端:2.6.3
阿波罗提升:0.1.16
任何人都可以解释为什么我会收到以下错误消息吗?:
Found @client directives in a query but no ApolloClient resolvers were specified. This means ApolloClient local resolver handling has been disabled, and @client directives will be passed through to your link chain.
当我按如下方式定义我的 ApolloClient 时:
return new ApolloClient({
uri: process.env.NODE_ENV === 'development' ? endpoint : prodEndpoint,
request: operation => {
operation.setContext({
fetchOptions: {
credentials: 'include',
},
headers: { cookie: headers && headers.cookie },
});
},
// local data
clientState: {
resolvers: {
Mutation: {
toggleCart(_, variables, { cache }) {
// Read the cartOpen value from the cache
const { cartOpen } = cache.readQuery({
query: LOCAL_STATE_QUERY,
});
// Write the cart State to the opposite
const data = {
data: { cartOpen: !cartOpen },
};
cache.writeData(data);
return data;
},
},
},
defaults: {
cartOpen: false,
},
},
});
来自docs:
If you're interested in integrating local state handling capabilities with Apollo Client < 2.5, please refer to our (now deprecated) apollo-link-state project. As of Apollo Client 2.5, local state handling is baked into the core, which means it is no longer necessary to use apollo-link-state
clientState
配置选项仅用于 apollo-link-state
。您需要将解析器直接添加到配置中,如文档中所示:
new ApolloClient({
uri: '/graphql',
resolvers: { ... },
})
另请注意,不再有 defaults
选项 -- 应通过直接在缓存实例上调用 writeData
来初始化缓存(请参阅 here)。
我建议阅读最新的文档并避免使用来自外部来源的任何示例(例如现有的存储库或教程),因为这些可能已过时。
注意:从 3.0 版开始,writeData
已被删除,取而代之的是 writeFragment
和 writeQuery
。