Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] GraphQL server returns interface type for __typename when UseFieldResolvers is enabled #630

Open
magicoder10 opened this issue Jan 21, 2024 · 1 comment

Comments

@magicoder10
Copy link

Input

Schema

interface Animal {
    name: String!
}

type Dog implements Animal {
    name: String!
    breed: String!
}

type Cat implements Animal {
    name: String!
    livesLeft: Int!
}

type Query {
    animals: [Animal!]!
}

Query

query {
  animals {
    name
    __typename
  }
}

Output

Without UseFieldResolvers

schema := graphql.MustParseSchema(schemaString, &query{})
	http.Handle("/graphql", &relay.Handler{Schema: schema})
	log.Fatal(http.ListenAndServe(":8080", nil))
{
  "data": {
    "animals": [
      {
        "name": "Buddy",
        "__typename": "Dog"
      },
      {
        "name": "Whiskers",
        "__typename": "Cat"
      }
    ]
  }
}

With UseFieldResolvers

schema := graphql.MustParseSchema(schemaString, &query{}, graphql.UseFieldResolvers())
	http.Handle("/graphql", &relay.Handler{Schema: schema})
	log.Fatal(http.ListenAndServe(":8080", nil))
{
  "data": {
    "animals": [
      {
        "name": "Buddy",
        "__typename": "Animal"
      },
      {
        "name": "Whiskers",
        "__typename": "Animal"
      }
    ]
  }
}

This bug leads to

{
  "errors": [
    {
      "message": "panic occurred: {{\"Dog\" {'\\x05' '\\f'}}} does not implement \"Animal\""
    }
  ]
}
@magicoder10 magicoder10 changed the title [Bug] GraphQL will returns interface type for __typename when UseFieldResolvers is enabled [Bug] GraphQL returns interface type for __typename when UseFieldResolvers is enabled Jan 21, 2024
@magicoder10 magicoder10 changed the title [Bug] GraphQL returns interface type for __typename when UseFieldResolvers is enabled [Bug] GraphQL server returns interface type for __typename when UseFieldResolvers is enabled Jan 21, 2024
@pavelnikolov
Copy link
Member

@magicoder10 thank you for reporting this. Can I, please, have the code for the resolver as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants