Skip to content

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

Open
@glasser

Description

@glasser

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.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions