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

Query on polymorphic types #2444

Open
antonio-petricca opened this issue Nov 30, 2022 · 1 comment
Open

Query on polymorphic types #2444

antonio-petricca opened this issue Nov 30, 2022 · 1 comment

Comments

@antonio-petricca
Copy link

Hi, I have a situation like this:

type Query {
  GetData: AbstractDataResponse
}

type AbstractDataResponse {
  field1: String!
  field2: String!
}

type DataResponseTypeA implements AbstractDataResponse {
  field3a: String!
}

type DataResponseTypeB implements AbstractDataResponse {
  field3:b String!
}

I run a query by:

{ 
  GetData {
    field3a
  }
}

The resolver, in such situation, returns an instance of DataResponseTypeA.

I get the error:

Validation error (FieldUndefined@[GetData/field3a]) : Field 'field3a' in type 'AbstractDataResponse' is undefined

How could I fix it?

Thank you so much!
Antonio

@jclyons52
Copy link
Contributor

There are a number of issues with your graphql, AbstractDataResponse should be an interface, the types implementing it will need to have all the fields listed in the interface on them and there is a b after the : in DataResponseTypeB

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