Fragments
Reuse fields for the same object type
You can also reuse chunks of your queries with GraphQL fragments:
fragment ReuseableFragment on Course {
  id
  title
  flows {
    title
  }
}
{
  course(id: "00000000-5945-95c7-65fc-a9747b20031d") {
    ...ReuseableFragment
  }
  anotherCourse: course(id: "00000000-5945-95c6-65fc-a9747b200320") {
    ...ReuseableFragment
  }
}{
  course(id: "00000000-5945-95c7-65fc-a9747b20031d") {
    id
    title
    flows {
      title
    }
  }
  anotherCourse: course(id: "00000000-5945-95c6-65fc-a9747b200320") {
    id
    title
    flows {
      title
    }
  }
}{
  "data": {
    "course": {
      "id": "00000000-5945-95c6-65fc-a9747b200317",
      "title": "History 101",
      "flows": [
        {
          "title": "Welcome to History 101"
        },
        {
          "title": "Nascent Civilization"
        }
      ]
    },
    "anotherCourse": {
      "id": "00000000-5945-95c7-65fd-a9747b200320",
      "title": "M & A 101",
      "flows": [
        {
          "title": "Welcome to Mergers & Acquisitions 101"
        },
        {
          "title": "Flow 1 - SEC Regulatory Measures"
        },
        {
          "title": "Flow 2 - Intro"
        },
        {
          "title": "Flow 3 - Mergers"
        },
        {
          "title": "Flow 4 - Acquistions"
        },
        {
          "title": "Mergeable activities"
        }
      ]
    }
  }
}Another thing to point out: anotherCourse is a GraphQL alias. This is a way to make multiple queries to the same field (query.course)
Last updated
Was this helpful?