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

Conflicting types when field may be non-nullable #5178

Open
ARWhattam opened this issue Feb 24, 2023 · 0 comments
Open

Conflicting types when field may be non-nullable #5178

ARWhattam opened this issue Feb 24, 2023 · 0 comments

Comments

@ARWhattam
Copy link

ARWhattam commented Feb 24, 2023

We have a DGS with a GraphQL schema that has two possible type of User - AnonUser and RegisteredUser. Both can have a firstName or a lastName but this is non-nullable for RegisteredUser. When sending a request to the DGS to retrieve the current user (this uses the authentication header) it returns either a AnonUser or RegisteredUser. However we get a conflicting types error when using GraphQL Mesh.

If our schema looks like this:

type Query {
  _sdl: String!
  _appVersion: String!
  me: User
}

interface User {
  id: ID!
  firstName: String
  lastName: String
}

type AnonUser implements User {
  id: ID!
  firstName: String
  lastName: String
}

type RegisteredUser implements User {
  id: ID!
  firstName: String!
  lastName: String!
}

When we send it the following request directly we get the user back:

query myUser {
  me {
    id
    firstName
    lastName
    __typename
  }
}

This is also what is sent down via our customer GraphQL Gateway we have created using GraphQL Tools. However, if we send the request through GraphQL Mesh we get the following error messages:
Fields \"firstName\" conflict because they return conflicting types \"String\" and \"String!\". Use different aliases on the fields to fetch both if this was intentional.
Fields \"lastName\" conflict because they return conflicting types \"String\" and \"String!\". Use different aliases on the fields to fetch both if this was intentional.

After some investigating we found that GraphQL Mesh was sending the following to our DGS:

query myUser {
  me {
    __typename
    ... on AnonUser {
      id
      firstName
      lastName
    }
    ... on RegisteredUser {
      id
      firstName
      lastName
    }
  }
}

Why does GraphQL Mesh change the query like this? I don't think inline fragments need to be used for this query. Then again, I don't know why GraphQL errors as I thought String and String! were compatible types. Could you assist with this? Is this an edge case that needs fixing in GraphQL Mesh?

Also, if you know of a workaround using transforms we can use in the meantime that would be fantastic. Have a nice weekend :)

This was referenced Apr 30, 2024
This was referenced May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant