【发布时间】:2020-01-19 22:33:20
【问题描述】:
我有一个使用 apollo-client 用 reason-react 编写的应用程序。我在前端定义了一些片段,基本上可以重用一些字段定义。我正在为使用片段的组件设置自动化测试,但我不断收到此警告,说我需要使用 IntrospectionFragmentMatcher。
'You are using the simple (heuristic) fragment matcher, but your queries contain union or interface types. Apollo Client will not be able to accurately map fragments. To make this error go away, use the `IntrospectionFragmentMatcher` as described in the docs: https://www.apollographql.com/docs/react/advanced/fragments.html#fragment-matcher'
我尝试根据docs 设置片段匹配器。 codegen 结果不返回任何类型:
{
"__schema": {
"types": []
}
}
当我查询我的服务器并查看 apollo-client 推荐的手动方法时,我注意到它也不会返回任何类型。
另一个奇怪的事情是,当我不使用片段匹配器时,我得到了模拟的响应,但我只是得到了来自 apollo 的警告。如果我确实使用它,那么模拟的响应不会正确返回。
为什么我要在 graphql api 中查询我的前端代码中定义的片段?为什么我只会在运行测试和使用模拟数据时收到这些错误,而不是在运行我的实际应用程序时?
【问题讨论】:
标签: graphql apollo-client