如何解决如何以@nuxt/apollo subscribeToMore 工作的方式设置我的nuxt
在我们的 nuxt 项目中使用 @nuxt/apollo 时。出于某种原因,我不断收到
期待已解析的 GraphQL 文档。也许您需要将查询字符串包装在“gql”标签中? http://docs.apollostack.com/apollo-client/core.html#gql
作为来自 Nuxt 的错误消息。 我使用以下语法:
apollo: {
items: {
$subscribeToMore: {
// below is the subscription query.
document: gql`
subscription($Group: String!){
agents(Group: $Group){
_id
name
}
}
`,variables () {
return {
Group: Object.keys(this.$auth.user.app_access)[0],}
},updateQuery: (previousResult,{ subscriptionData }) => {
console.log(subscriptionData);
return subscriptionData.data;
}
},}
},
我的阿波罗配置看起来像这样:
module.exports = function (ctx) {
const httpEndpoint = ctx.route.path.includes('/app/cmb') ? process.env.GRAPHQL_HTTP_ENDPOINT : process.env.GRAPHQL_HTTP_ENDPOINT_IAM
const wsEndpoint = ctx.route.path.includes('/app/cmb') ? process.env.GRAPHQL_WS_ENDPOINT : process.env.GRAPHQL_WS_ENDPOINT_IAM
return {
httpEndpoint,wsEndpoint,tokenName: 'auth._token.keycloak',inMemoryCacheOptions: {
addTypename: false,},fetchOptions: { mode: 'no-cors' },authenticationType: 'Bearer',getAuth: (tokenName) => {
if (process.client) {
return localStorage.getItem(tokenName)
} else {
// get token from cookie in server side request
return this.__VUE_SSR_CONTEXT__.req.headers.cookie.split('; ').reduce((acc,item) => {
const split = item.split('=')
if (split[0] === tokenName) {
acc = decodeURIComponent(split[1]) // decode cookie value
}
return acc
},'')
}
},credentials: 'include'
}
}
在 nuxt.config 我有以下内容:
apollo: {
clientConfigs: {
default: '~/apollo.config.js'
},tokenName: 'auth._token.keycloak'
},
package.json 中的 nuxt apollo:"@nuxtjs/apollo": "^4.0.1-rc.5",
有人可以告诉我如何以正确的方式设置多个订阅。只有一个订阅可以正常工作,但是当我想使用 subscribeToMore 添加多个订阅时,事情就会变得混乱。
解决方法
您是否使用
导入了gql
import gql from 'graphql-tag'
如 vue-apollo 文档中所示:https://apollo.vuejs.org/guide/apollo/queries.html#simple-query
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。