GraphQL Playground和Apollo客户端之间的结果不一致
我遇到了一个问题,即Apollo客户端和GQL操场返回具有完全相同查询的不同数据。该模式看起来像这样:
interface A {
age: Int!
}
interface B implements A {
age: Int!
name: String!
}
type SomeType implements A & B { ... }
type Query {
hello: A
}
服务器返回具体类型loyepe
,它同时实现了接口a
和b
。
查询:(
{
hello {
age
... on B {
name
}
}
}
我能想到的唯一区别是,当使用Apollo客户端时,查询将用graphl-tag
进行解析)。 在GQL操场上,查询返回预期结果。类似:
{
"__typename": "someType",
"age": 10,
"name": "someName"
}
但是,使用Apollo客户端运行此查询时,我会得到:
{
"__typename": "someType",
"age": 10,
}
I've run into an issue where Apollo client and the GQL playground return different data with the exact same query. The schema looks something like this:
interface A {
age: Int!
}
interface B implements A {
age: Int!
name: String!
}
type SomeType implements A & B { ... }
type Query {
hello: A
}
The server returns a concrete type SomeType
, which implements both interface A
and B
.
The query:
{
hello {
age
... on B {
name
}
}
}
(The only difference I can think of is that when using Apollo client, the query is parsed with the graphl-tag
).
In the GQL playground, the query returns the expect result. Something like:
{
"__typename": "someType",
"age": 10,
"name": "someName"
}
However, when running this query with Apollo client, I get:
{
"__typename": "someType",
"age": 10,
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查询似乎定义为返回类型
a
,因此仅获得
a
中定义的字段似乎正确。也许您应该将模式更改为类似的内容:
It seems the query is defined to return type
A
So getting only the fields defined in
A
seems correct.Perhaps you should change the schema to something like: