Skip to content

New rule request: union subtypes with conflicting field value type #2008

Open
@caccialdo

Description

@caccialdo

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

When 2 subtypes of the same union type share a field but with a different value type, it's possible to run into query-time errors like below if the client doesn't alias the field with conflicting value types:

image

Minimal reproducible setup where a Book is either a Novel or a Poem but their id field is Drn and Int respectively.

Sample schema

type Drn {
  country: String
  id: String
}

type Poem {
  id: Int
  title: String
  author: String
}

type Novel {
  id: Drn
  title: String
  author: String
}

union Book = Poem | Novel

type Query {
  books: [Book]
}

Describe the solution you'd like

Creating such scenario in a schema isn't forbidden per se but it would be nice to have the option of enforcing a linting rule preventing it in the first place. The rule would suggest renaming the field(s) in the conflicting subtype(s).

Describe alternatives you've considered

apollographql/eslint-plugin-graphql but the tool is also missing a rule for this scenario.

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions