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

Unused fragment error in the subqueries generated for a union fragment #1633

Closed
eole1712 opened this issue Aug 26, 2022 · 1 comment · Fixed by #1650
Closed

Unused fragment error in the subqueries generated for a union fragment #1633

eole1712 opened this issue Aug 26, 2022 · 1 comment · Fixed by #1650

Comments

@eole1712
Copy link
Contributor

Hello

Describe the bug

When we use a fragment in a query, in the subquery that the router builds the fragment is replaced by the selected keys and is removed from the query.

However, if the fragment refers to one of the options of a union, the router does not remove the fragment from the query after replacing it, which triggers a GRAPHQL_VALIDATION_FAILED error in the subgraph because of an unused fragment.

To Reproduce

  1. Setup a service with the followed schema
type Employee {
   job_name: String!
}

type Student {
   school_name: String!
}

union UserType = Student | Employee

type User {
  id: Int!
  type: UserType!
}

type Query {
  user: User
}
  1. Submit request
fragment employeeFragment on Employe {
   __typename
   job_name
}

fragment userFragment on User {
  __typename
  id
  type {
    ...employeeFragment
    __typename
  }
}

query test {
  user {
    __typename
    ...userFragment
  }
}

  1. See error

The generated subgraph request is supposed to be :

query test__servicea__0 {
  user {
    __typename
    id
    type {
      __typename
      ... on Employee {
        job_name
      }
    }
  }
}

But instead the query generated for the subgraph is :

query test__servicea__0 {
  user {
    __typename
    id
    type {
      __typename
      ... on Employee {
        job_name
      }
    }
  }
}

fragment employeeFragment on Employe {
   __typename
   job_name
}

This generated the error GRAPHQL_VALIDATION_FAILED on the subgraph with the message : Fragment "employeeFragment" is never used.

Desktop (please complete the following information):

  • OS: [e.g. iOS]
  • Version [e.g. 22]

Also sorry about the title of the issue, I had a hard time putting it into a sentence.

@abernix
Copy link
Member

abernix commented Aug 29, 2022

Thanks for reporting this! This is a duplicate of apollographql/federation#2092 and it'll be fixed in an upcoming release that brings in the updated query planner from that other repository. You can track #1546 for the issue that will eventually bring it in.

@abernix abernix closed this as completed Aug 29, 2022
@abernix abernix removed the triage label Aug 29, 2022
Geal added a commit that referenced this issue Aug 30, 2022
Fix #1546 
Fix #1584 
Fix #1633

Co-authored-by: Jesse Rosenberger <git@jro.cc>
Geal added a commit that referenced this issue Aug 31, 2022
Fix #1546 
Fix #1584 
Fix #1633

Co-authored-by: Jesse Rosenberger <git@jro.cc>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants