我正在从事阿波罗、GraphQL和Nuxtjs项目,在设置阿波罗配置时,我收到了以下警告:
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()
}
};我在谷歌上搜索了任何类似的问题,我找到了这个https://github.com/Akryum/vue-cli-plugin-apollo/issues/47,但它并没有帮助我。我试着改变:
const link = middlewareLink.concat(httpLink);至:
const link = Apollo.from([middlewareLink, httpLink]);但它还是给了我同样的警告,任何帮助
发布于 2019-11-06 18:52:41
我的解决方案是将Http Link放在阿波罗链接数组的末尾(在创建阿波罗客户端时使用)。
...
const param = {
link: ApolloLink.from([
onError(...) =>...,
authLink...,
new HttpLink({
uri: '/graphql',
credentials: 'same-origin'
})
]),
cache: ...,
connectToDevTools: ...
}
new ApolloClient(param);我正在使用这些库:
apollo-clientapollo-cache-inmemoryapollo-linkapollo-link-httpapollo-link-contextapollo-link-error发布于 2019-03-14 18:33:48
在我的例子中,我解决了这个问题,更改了数组中的顺序,例如:
在此之前:
const links = [...middlewares, localLink, authLink, httpLink, errorLink]之后:
const links = [...middlewares, localLink, authLink, errorLink, httpLink]发布于 2018-10-29 04:34:55
我注意到,在vue-阿波罗自述中,有一些文档是供apolloClient吐露的,它说您可以关闭defaultHttpLink来使用终止链接。
return {
link,
cache: new InMemoryCache()
defaultHttpLink: false, // this should do the trick
}https://stackoverflow.com/questions/51840201
复制相似问题