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

Code generation disallows spreading an interface or union against a union #454

Open
glasser opened this issue Aug 2, 2023 · 0 comments
Open
Labels
bug Something isn't working enhancement New feature or request

Comments

@glasser
Copy link

glasser commented Aug 2, 2023

In GraphQL, you should be able to spread an interface or union against a union, as long as there's some type that satisfies both. For example:

interface Error {
  message: String
}

type ErrorA implements Error {
  message: String
}

type ErrorB implements Error {
  message: String
}

type Success {
  updated: Int
}

union Result = Success | ErrorA | ErrorB

type Mutation {
  doIt: Result
}
mutation M {
  doIt {
    ... on Error {
      message
    }
    ... on Success {
      updated
    }
  }
}

This mutation is a valid operation, but graphql-client will block it with error: Failed to generate GraphQLQuery impl: The spread Result... on Error is not valid.

This is unfortunate as it's a nice pattern for mutations to return a union that allows a bunch of different error types, but to let a client process all errors together if they want.

(I ran into this while debugging an issue with https://github.com/apollographql/rover but I'm not personally a strong Rust developer so I wasn't able to quickly turn this into a standalone test case — if you can show the proper part of the repo to do so, I'm happy to do so.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants