简体   繁体   中英

Inconsistent results between Graphql playground and Apollo Client

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,
}

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 
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM