[英]Graphql react-apollo IntrospectionFragmentMatcher issues
在向我们的graphql查询添加一些接口类型后,我们的react-apollo应用程序收到fragmentMatcher错误:
您正在使用简单的(启发式)片段匹配器,但是您的查询包含联合或接口类型。 Apollo客户端将无法准确映射片段。要消除此错误,请按照文档中的说明使用IntrospectionFragmentMatcher: http : //dev.apollodata.com/react/initialization.html#fragment-matcher
我已经按照指南进行操作,但错误并没有消失,即使我没有使用,它仍然表示我正在使用启发式片段匹配器? 有什么想法吗?
使用react-apollo@1.2.0
和apollo-cache-inmemory@1.0.0
,这是我的apollo配置:
...
import {
ApolloClient,
createNetworkInterface,
IntrospectionFragmentMatcher,
} from 'react-apollo'
import {InMemoryCache} from 'apollo-cache-inmemory'
import SchemaData from '../data/schema.json'
const filteredData = SchemaData.data.__schema.types.filter(
type => type.possibleTypes !== null,
)
const fragmentMatcher = new IntrospectionFragmentMatcher({
introspectionQueryResultData: {
__schema: {
types: filteredData,
},
},
})
const cache = new InMemoryCache({fragmentMatcher})
...
const client = new ApolloClient({
cache,
networkInterface,
dataIdFromObject: result => {
if (result.uuid && result.__typename) {
return result.__typename + result.uuid
}
return null
},
})
对于阿波罗客户端1.x,您不应使用包装fragmentMatcher的缓存。 在客户端构造函数中直接使用fragmentMatcher。
答案是包括您可能拥有的任何接口架构:
fragmentMatcher: new IntrospectionFragmentMatcher({
introspectionQueryResultData: {
__schema: {
types: [
{
kind: 'INTERFACE',
name: 'Document',
possibleTypes: [
{name: 'MyInterface1'},
{name: 'SomeInterface2'},
],
},
],
},
},
}),
尽管我建议尽可能使用apollo v2。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.