Skip to content

Interface inline fragment on union types results in panic. #241

Closed
hsdp/graphql-go
#2
@marksauter

Description

@marksauter

Error

Given:

interface Node {
  id: ID!
}

type A implements Node {
  id: ID!
  a: String!
}

type B implements Node {
  id: ID!
  b: String!
}

type C implements Node {
  id: ID!
  c: String!
}

union ABC = A | B | C

query {
  search(input: InputType!): ABC
}

If I make the following query to this mock api:

{
  search(input: { ... }) {
    ... on A {
      a
    }
    ... on B {
      b
    }
    ... on C {
      c
    }
    ... on Node {
      id
    }
  }
}

I get a panic error that Node does not implement ABC, originating from the following line of code:

panic(fmt.Errorf("%q does not implement %q", frag.On, e.Name)) // TODO proper error handling

Expected

I expect the Node inline fragment to resolve just fine, because A) relay makes queries of this nature via its api, and B) each type in the union implements the Node interface.

Probable source of the error

Looking through the code I can see - correct me if I'm wrong - that the type assertion is only checking for possible types for the union. It is not checking if A) the inline fragment is an interface type, or if B) the union objects implement said interface.

Update

I've decided to just make all my union types into interface types for the time being.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions