Kai*_*r91 6 apollo graphql apollo-server apollo-client vue-apollo
我正在尝试禁用Apollo 上的缓存,因此我正在关注文档apollo-client
,但我无法成功,我一直收到此警告 ApolloBoost was initialized with unsupported options: defaultOptions
有没有人有同样的警告?
import Vue from 'vue'
import ApolloClient from 'apollo-boost'
const defaultOptions = {
watchQuery: {
fetchPolicy: 'network-only',
errorPolicy: 'ignore'
},
query: {
fetchPolicy: 'network-only',
errorPolicy: 'all'
}
}
const client = new ApolloClient({
defaultOptions: defaultOptions,
)};
Run Code Online (Sandbox Code Playgroud)
看起来这是因为您正在使用Apollo Boost,它是 Apollo Client 的包装器,API 略有不同。
尝试更改您的导入:
import ApolloClient from "apollo-boost";
到:
import ApolloClient from "apollo-client";
或在 v3 中:
import { ApolloClient } from '@apollo/client';
“apollo-client”级别更低,更难使用。这可能就是该团队创建“apollo-boost”的原因。
但是查看源代码“apollo-boost”是了解如何使用低级“apollo-client”的好方法。例如:
import ApolloClient from 'apollo-client';
import { FetchResult } from 'apollo-link';
import { HttpLink } from 'apollo-link-http';
import { InMemoryCache } from 'apollo-cache-inmemory';
// in v3, the types moved:
// import { ApolloClient } from '@apollo/client';
const apolloClient = new ApolloClient({
link: new HttpLink({
uri: '/graphql',
credentials: 'same-origin',
}),
cache: new InMemoryCache(),
defaultOptions: {
query: {
errorPolicy: 'all',
},
},
});
Run Code Online (Sandbox Code Playgroud)
另请参阅有关从 Apollo Boost迁移到 Apollo Client的文档,如 Intellidroid 所说。