GraphQL Playground和Apollo客户端之间的结果不一致

发布于 2025-01-28 17:56:55 字数 702 浏览 1 评论 0原文

我遇到了一个问题,即Apollo客户端和GQL操场返回具有完全相同查询的不同数据。该模式看起来像这样:

interface A {
  age: Int!
}

interface B implements A {
  age: Int!
  name: String!
}

type SomeType implements A & B { ... }

type Query {
  hello: A 
}

服务器返回具体类型loyepe,它同时实现了接口ab

查询:(

{
  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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黑色毁心梦 2025-02-04 17:56:55

查询似乎定义为返回类型a

type Query {
  hello: A 
}

因此仅获得a中定义的字段似乎正确。
也许您应该将模式更改为类似的内容:

type Query {
  hello: SomeType 
}

It seems the query is defined to return type A

type Query {
  hello: A 
}

So getting only the fields defined in A seems correct.
Perhaps you should change the schema to something like:

type Query {
  hello: SomeType 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文