close

Filter

loading table of contents...

Headless Server Developer Manual / Version 2307

Table Of Contents

4.10.2 Article Query with Fragments and Parameters

The following example is a more complex article query. It uses GraphQL query fragments to factor out repeating parts, and a query parameter $id which can easily be passed in the variables field of the HTTP request:

query ArticleQuery($id: String!) {
  content {
    article(id: $id) {
      ...Reference
      teaserTitle
      teaserText
      pictures {
        ...ContentInfo
        alt
        uriTemplate
      }
      navigationPath {
        ...Reference
      }
    }
  }
}

fragment ContentInfo on Content_ {
  name
  creationDate
}

fragment Reference on CMLinkable {
  ...ContentInfo
  title
  segment
  link {
    id
    type
  }
}

Query parameters are called variables in Graphql. In GraphiQL, you pass query variables in the QUERY VARIABLES input field below the query input field, as a JSON object, for example,

{
  "id": "6494"
}
  

Note that, in this query, the picture fields has been replaced with the pictures field. This way, the result will hold a list of all (valid) CMPicture links within the pictures property instead of just the first one. Moreover, the response contains the navigation path of the article up to the root.

Search Results

Table Of Contents
warning

Your Internet Explorer is no longer supported.

Please use Mozilla Firefox, Google Chrome, or Microsoft Edge.