Fragments

Documentation on using and nesting fragments in GraphQL queries to efficiently construct reusable sets of fields.

You can build fragments to construct sets of fields and then include them in queries where you need to. Nested fragments are supported.

Here is an example of a query constructed using a fragment called associateBasic, which in turn uses two other fragments, associateContact and associateAddress.

Query

query read($cid : Int!)
{
  useCompany(no: $cid)
  {
    associate
    {
      items
      {
        ...associateBasic
        customerNo
        supplierNo
      }
    }
  }
}
fragment associateBasic on Associate
{
  name
  userName
  ... associateContact
  ... associateAddress
}

fragment associateContact on Associate
{
  emailAddress
  phone
}

fragment associateAddress on Associate
{
  addressLine1
  postCode
  postalArea
  countryNo
}
Result

{
  "data": {
    "useCompany": {
      "associate": {
        "items": [
          {
            "name": "ABB Installasjon AS",
            "userName": "",
            "emailAddress": "",
            "phone": "12345678",
            "addressLine1": "Ole Deviks Vei 10",
            "postCode": "1375",
            "postalArea": "Billingstad",
            "countryNo": 0,
            "customerNo": 10000,
            "supplierNo": 0
          },
          {
            "name": "ABB Kraft AS",
            "userName": "",
            "emailAddress": "",
            "phone": "12345678",
            "addressLine1": "Jacob Borchs Gate 6",
            "postCode": "3002",
            "postalArea": "Drammen",
            "countryNo": 0,
            "customerNo": 10001,
            "supplierNo": 0
          }
        ]
      }
    }
  }
}
Last modified September 24, 2024