Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

236
Views
How to fetch graphQl fragment?

I need to set fragment to my gql. It is working code:

const findEntity = gql`
  query findEntity($pagination: Pagination, $sort: Sort) {
    organizationList(pagination: $pagination, sort: $sort) {
      data {
        _id
        name
      }
    }
  }
`;

This code doesn't work:

const TEST_FRAGMENT = gql`
  fragment organizationList on OrganizationsPage {
    data {
      _id
      name
    }
  }
`;

const findEntity = gql`
  query findEntity($pagination: Pagination, $sort: Sort) {
    organizationList(pagination: $pagination, sort: $sort) {
      ${TEST_FRAGMENT}
    }
  }
`;

errors: [{message: "Cannot query field "fragment" on type "OrganizationsPage".",…},…]

What I do wrong? I think I repeated documentation sample...

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Fragments use pseudo-spread syntax and you need to include them in the query. I also used caps for the fragment name for convention compliance.

const findEntity = gql`
  ${TEST_FRAGMENT}
  query findEntity($pagination: Pagination, $sort: Sort) {
    organizationList(pagination: $pagination, sort: $sort) {
      ...OrganizationListFields
    }
  }
`;
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!