graphql-code-generator icon indicating copy to clipboard operation
graphql-code-generator copied to clipboard

Support @oneOf in operations plugin

Open n1ru4l opened this issue 4 years ago • 4 comments

Is your feature request related to a problem? Please describe.

Since @oneOf is already usable via https://www.npmjs.com/package/@envelop/extended-validation it would be great if graphql-codegen could also generate the correct types for (input) object types

Describe the solution you'd like

type Fish {
  id: ID!
}

type Tiger {
  id: ID!
}

type Dog {
  id: ID!
}

type Animal @oneOf {
  fish: Fish
  tiger: Tiger
  dog: Dog
}

type Query {
  animal: Animal!
}
query AnimalQuery {
  animal {
    fish {
      __typename
    }
    tiger {
      __typename
    }
    dog {
      __typename
    }
  }
}
type AnimalQuery = {
  animal:
    | ({ fish: { __typename: "Fish" } })
    | ({ tiger: { __typename: "Tiger" } })
    | ({ dog: { __typename: "Dog" } });
};

n1ru4l avatar May 03 '21 06:05 n1ru4l