我正在Apollo,GraphQL和Nuxtjs项目中工作,在设置Apollo配置时收到以下警告:
link.js:38 Error: You are calling concat on a terminating link, which will have no effect
at new LinkError (linkUtils.js:41)
at concat (link.js:38)
at ApolloLink.webpackJsonp../node_modules/apollo-link/lib/link.js.ApolloLink.concat (link.js:65)
at link.js:13
at Array.reduce (<anonymous>)
at from (link.js:13)
at createApolloClient (index.js:58)
at webpackJsonp../.nuxt/apollo-module.js.__webpack_exports__.a (apollo-module.js:66)
at _callee2$ (index.js:140)
at tryCatch (runtime.js:62)
这是我的代码:
import { InMemoryCache } from 'apollo-cache-inmemory';
import { createHttpLink } from 'apollo-link-http';
import { ApolloLink } from 'apollo-link';
export default ({ store, env }) => {
const httpLink = new createHttpLink({ uri: env.GRAPH_BASE_URL });
// middleware
const middlewareLink = new ApolloLink((operation, forward) => {
const token = store.getters['user/GET_TOKEN'];
if (token) {
operation.setContext({
headers: { authorization: `Bearer ${token}` }
});
}
return forward(operation);
});
const link = middlewareLink.concat(httpLink);
return {
link,
cache: new InMemoryCache()
}
};
我在Google上搜索了任何类似的问题,发现了这个https://github.com/Akryum/vue-cli-plugin-apollo/issues/47 但这并没有帮助我。 我尝试更改:
const link = middlewareLink.concat(httpLink);
至:
const link = Apollo.from([middlewareLink, httpLink]);
但是它仍然给我同样的警告, 请帮忙
答案 0 :(得分:1)
我注意到在vue-apollo自述文件中,有一些有关apolloClient配置的文档,它说您可以关闭defaultHttpLink以使用终止链接。
return {
link,
cache: new InMemoryCache()
defaultHttpLink: false, // this should do the trick
}
答案 1 :(得分:1)
对我来说,解决方案是将Http Link
放在Apollo Link数组的末尾(在创建Apollo Client时使用)。
...
const param = {
link: ApolloLink.from([
onError(...) =>...,
authLink...,
new HttpLink({
uri: '/graphql',
credentials: 'same-origin'
})
]),
cache: ...,
connectToDevTools: ...
}
new ApolloClient(param);
我正在使用这些库:
apollo-client
apollo-cache-inmemory
apollo-link
apollo-link-http
apollo-link-context
apollo-link-error
答案 2 :(得分:0)
对于我来说,我解决了这个问题,更改了数组的顺序,例如:
之前:
const links = [...middlewares, localLink, authLink, httpLink, errorLink]
之后:
const links = [...middlewares, localLink, authLink, errorLink, httpLink]
答案 3 :(得分:0)
httplink应该在链接数组的结尾。