【发布时间】:2020-04-28 14:33:17
【问题描述】:
我有一个无头 Craft CMS,它通过 Apollo 通过 GraphQL 端点将数据返回到我的 Nuxtjs 应用程序。我有一个可以返回三种不同块类型之一的字段:richText、image 和 pullQuote。
我的 GraphQL 端点如下所示:
query($section:[String], $slug:[String]) {
entries(section: $section, slug: $slug) {
id,
title,
uri,
... on blog_blog_Entry{
contentEngine{
__typename,
...on contentEngine_richText_BlockType{
__typename,
id,
richText
fontColor,
backgroundColor
}
...on contentEngine_image_BlockType{
__typename,
id,
backgroundColor,
imageWidth,
image {
id,
url
}
}
...on contentEngine_pullQuote_BlockType{
__typename,
id,
backgroundColor,
fontColor,
quote
}
}
}
}
}
It returns data just fine,但在我的 Nuxt 组件中尝试使用它时出现此错误:
您正在使用简单(启发式)片段匹配器,但您的查询包含联合或接口类型。 Apollo Client 将无法准确映射片段。要消除此错误,请使用文档中所述的
IntrospectionFragmentMatcher:https://www.apollographql.com/docs/react/advanced/fragments.html#fragment-matcher
令人气愤的是,这个文档导致了 404。我发现了一些 other GitHub tickets 引用了这个链接,所以我不确定我应该遵循什么步骤。
我想我需要做的就是教 Apollo 的内存缓存。由于我的回复没有那么复杂,我想我可以用Defining PossibleTypes manually 逃脱。
我尝试了以下方法,但我认为我不了解如何正确设置:
const cache = new InMemoryCache({
possibleTypes: {
contentEngine: [
"contentEngine_richText_BlockType",
"contentEngine_pullQuote_BlockType",
"contentEngine_image_BlockType"
],
},
});
解决这个问题的任何帮助都会是一个巨大的帮助。
警告:启发式片段匹配正在进行中!
【问题讨论】:
标签: graphql nuxt.js apollo vue-apollo