GraphQL query examples

The following are examples of GraphQL queries that can be used in the GraphQL IDE. The GraphQL IDE includes documentation and gives you access to the schema.

Important

You must authenticate with an API key for all requests to the GraphQL APIs.

Note

The full range of search and filter parameters is supported in the Delivery API only. The Preview API supports filtering on the content type, content item, and media item number field with the following operators _eq, _neg, _gt, _It, and _between. For content types, filtering is also supported on the datetime field.

This query returns the Content Hub ONE schema.

Request body

{
  __schema {
    types {
      name
    }
  }
}

This query returns all content items that use the event content type.

Request body

{
  allEvent { 
    total
    results {
      eventName
    }
  }
}

Response body

{
  "data": {
    "allEvent": {
      "total": 3,
      "results": [
        {
          "eventName": "iRadio concert series"
        },
        {
          "eventName": "Christmas Ball"
        },
        {
          "eventName": "Fall Concert"
        }
      ]
    }
  }
}

This query returns an event with a specific ID.

Request body

{
  event3(id: "jWFh1IiZkUet8NaIAY7bVg") { 
      eventName
    }
  }

Response body

{
  "data": {
    "event3": {
      "eventName": "iRadio concert series"
    }
  }
}

This query returns content with the Podcast content type that contains a specific string (life) in the title. For a complete list of operators, click the DOCS tab in the GraphQL IDE.

Note

The Preview API does not support the where clause.

Request body

{
  allPodcast(where: { podcastName_contains: "life"}) {
    results {
      episodeName
    }
  }
}

Response body

{
  "data": {
    "allPodcast": {
      "results": [
        {
          "episodeName": "In the beginning"
        }
      ]
    }
  }
}

This query returns related articles of type Artist for a specific content item of type sampleArticle.

Request body

{
sampleArticle(id: "JW9APZtr3kK7WZvM4xv1wA"){
  relatedArticles{
    results {
        ... on Artist {
          id
          artistName
        }
           }
      }
    }
}

Response body

{
  "data": {
    "sampleArticle": {
      "relatedArticles": {
        "results": [
          {
            "id": "artistStellaDonnelly",
            "artistName": "Stella Donnelly"
          },
          {
            "id": "artistJeremySoule",
            "artistName": "Jeremy Soule"
          }
        ]
      }
    }
  }
}

This query returns a list of sample articles with the related articles and related media for each.

Request body

{
  allSampleArticle {
    results {
      title
      relatedArticles {
        results {
          ... on Artist {
            id
            name
          }
        }
      }
      relatedMedia {
        results {
          id
          name
        }
      }
    }
  }
}

Response body

{
  "data": {
    "allSampleArticle": {
      "results": [
        {
          "title": "Headless CMS : Exactly what marketers need today (V2)",
          "relatedArticles": {
            "results": [
              {}
            ]
          },
          "relatedMedia": {
            "results": [
              {
                "id": "z2LD0nIRiE6GfkxDNkU5Bw",
                "name": "wireless-workflow.jpg"
              }
            ]
          }
        },
        {
          "title": "We heart charity campaign",
          "relatedArticles": {
            "results": [
              {
                "id": "artistStellaDonnelly",
                "name": "Stella Donnelly"
              },
              {
                "id": "artistJeremySoule",
                "name": "Jeremy Soule"
              },
              {}
            ]
          },
          "relatedMedia": {
            "results": [
              {
                "id": "8y7yq3LhYESvoqzHC1cTYw",
                "name": "pink-couch.jpg"
              },
              {
                "id": "l_o6ED_e0EGh8cyp5kppOA",
                "name": "paper hearts"
              }
            ]
          }
        }
      ]
    }
  }
}

This query returns a media item with the ID KTsF62Q4gg60q6WCsWJw8.

Request body

{
  media(id: "KTsF62Q4gg60q6WCsWJw8") {
    title
    url
   }
}

Response body

{
  media {
    title: "TheLittleBlackDress"
    url: "https://..../dress.jpg"
   }
}

This query example returns a media item with the ID KTsF62Q4gg60q6WCsWJw8 and resizes it to a specific width (500 pixels) and height (300 pixels) using media transformation parameters.

Request body

{
  media(id: "KTsF62Q4gg60q6WCsWJw8") {
    title
    url(transform: {
      width: 500,
      height: 300,
    })
   }
}

Response body

{
  media {
    title: "TheLittleBlackDress"
    url: "https://..../dress.jpg?width=500&height=300"
   }
}