我正在处理nuxt / apollo包,但是没有有关addTypeName属性的信息。应该在哪里设置此属性?注意:所有有关@ nuxt / apollo的安装。 (作为模块等导入)
版本信息:
"@nuxtjs/apollo": "^4.0.0-rc8",
我在nuxt.config.js中的apollo配置:
apollo: {
includeNodeModules: false,
authenticationType: 'Basic',
defaultOptions: {
$query: {
loadingKey: 'loading',
fetchPolicy: 'cache-and-network'
}
},
clientConfigs: {
default: {
httpEndpoint: 'DEFAULT_GRAPHQL_ENDPOINT',
tokenName: 'apollo-token' // optional
},
financial: {
httpEndpoint: 'NEWS_GRAPHQL_ENDPOINT',
tokenName: 'apollo-token',
addTypename: false --> **Is not working**
}
}
}
我的Index.vue页面是:
apollo: {
data: {
query: gql`
{
newsJson(take: 1) {
key
*GENERATES __typeName when sending request to Graphql*
}
}
`,
client: 'financial'
}
}
我的graphql查询(通过网络上的graphiql::
{
newsJson(take:1){
key
approve
}
}
并且Response是:
{
"data": {
"newsJson": [
{
"key": 2071554,
"approve": false
}
]
}
}
当我发送请求__typeName时,我在graphql网站上崩溃了。如何防止向请求添加__ typeName属性?
最好的问候,
谢谢
InMemoryCache
带有可选的addTypename
参数,可以将其设置为false
以防止此行为。因此,您可以执行以下操作:
clientConfigs: {
default: {
...
inMemoryCacheOptions: {
addTypename: false,
},
},
}
但是,这是高度不建议。 __typename
字段与id
/ _id
字段一起用于生成缓存中单个节点的密钥。有关更多详细信息,请参见here。删除__typename
可能会在您的应用中导致错误和意外行为,因此不应执行。