Skip to content

A union of object interfaces is formatted oddly with inline fragments #261

@dannycochran

Description

@dannycochran

Related issues:
#248

Given the following GraphQL schema:

type AssetInfo {
  id: String!
  data: AssetData
}

union AssetData = Video | Audio | Artwork

type Video {
  subType: String
}

type Audio {
  identifiers: [String]
}

type Artwork {
  tags: [String]
}

And this query against it:

{
  id
  data {
    ... on Artwork {
     tags
   }
   ... on Audio {
     identifiers
   }
   ... on Video {
     subType
   }
  }

gql2ts produces the following response for that query:

interface SelectionOnAssetInfo {
  id: string;
  data:
    | Partial<SpreadOnArtwork> &
        Partial<SpreadOnCopy> &
        Partial<SpreadOnVideo>
    | null;
}

I would expect the corresponding query to produce this interface

interface SelectionOnAssetInfo {
  id: string;
  data: SpreadOnArtwork | SpreadOnCopy | SpreadOnVideo | null;
}
  1. The data field should not be wrapped with Partial
  2. The interfaces should not be intersected with &, but unioned via |.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions