将标题添加到所有Apollo查询
正如标题所暗示的那样,我正在尝试为阿波罗(Apollo)提出的所有查询和突变添加标头。我知道我可以做
context: {
headers: {
'Accept-Language': $this.i18n.current;
}
}
,但这只是一个查询或突变。我正在使用vue和我的当前nuxt.config.js
如下所示,
apollo: {
clientConfigs: {
default: '~/plugins/apollo-config.js'
},
defaultOptions: {
$query: {
fetchPolicy: 'network-only',
context: { // does not work
headers: {
"Accept-Language": $this.i18n.current, // not sure if this works as it is in config
}
}
}
},
errorHandler: '~/plugins/apollo-error-handler.js'
},
我很确定在这种情况下我使用上下文,但不确定我还应该如何做。任何帮助将不胜感激。
As the title suggest, I am trying to add a header to all queries and mutations made by apollo. I know I can do
context: {
headers: {
'Accept-Language': $this.i18n.current;
}
}
but that is only for one query or mutation. I am using nuxt with vue and my current nuxt.config.js
is as follows
apollo: {
clientConfigs: {
default: '~/plugins/apollo-config.js'
},
defaultOptions: {
$query: {
fetchPolicy: 'network-only',
context: { // does not work
headers: {
"Accept-Language": $this.i18n.current, // not sure if this works as it is in config
}
}
}
},
errorHandler: '~/plugins/apollo-error-handler.js'
},
I'm pretty sure I'm using context wrong in this case but not sure how else I should do it. Any help would be very much appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我根本不是关于GraphQl的专业人员,但是去年,我取得了很好的工作(与JWT标头),这是我当时回到的
nuxt.config.js
>这是我的
nuxt-apollo-config.js
fileimport {setContext}从'apollo-link-context'
对我来说很好。我不确定这是最好的,因为现在可能有一些烘烤的东西,但是去年这对我有用。I'm not at all a professional regarding GraphQL but last year, I've achieved something that works well (with a JWT header), here is what I had back at the time
nuxt.config.js
and here is my
nuxt-apollo-config.js
fileimport { setContext } from 'apollo-link-context'
worked well for me. I'm not sure that it's the best because there is maybe something baked-in right now but this one worked for me last year.