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

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

Open
caccialdo opened this issue Nov 14, 2023 · 5 comments
Open

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

caccialdo opened this issue Nov 14, 2023 · 5 comments
Labels
help wanted Extra attention is needed new rule

Comments

@caccialdo
Copy link

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

@caccialdo caccialdo changed the title New rule request: union subtypes with conflicting key value type New rule request: union subtypes with conflicting field value type Nov 14, 2023
@dimaMachina dimaMachina added help wanted Extra attention is needed new rule labels Nov 14, 2023
@dimaMachina
Copy link
Owner

Accepted, this seems could be fixed by integrating federation validation rules into graphql-eslint #1824

If somebody want to give a try to integrate it, feel free, i’ll review it

@dimaMachina
Copy link
Owner

@caccialdo After some searching, seems your lint error in Apollo Studio goes not from federation rules but from graphql-js rules, use @graphql-eslint/overlapping-fields-can-be-merged rule and you can try it in playground https://the-guild.dev/graphql/eslint/play?or=overlapping-fields-can-be-merged

@caccialdo
Copy link
Author

Thanks @dimaMachina ! It does look like this is the linting rule used in the playground indeed (cf. original screenshot in the ticket description). I'll look into leveraging it in our clients.

I think the feature request is still valid though as enforcing it on the server-side at the schema level (vs. operation level) would be valuable for clients lacking linting capabilities.

@dimaMachina
Copy link
Owner

@caccialdo this rule is accepted, if you want you can work on it and send a PR

@caccialdo
Copy link
Author

Thanks! I'll give it a shot in the new year if nobody attempts it before me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed new rule
Projects
None yet
Development

No branches or pull requests

2 participants