GraphQL examples

The following are examples of GraphQL queries that you can use in Sitecore Content Hub.

Query recipes title contains Fruitful

This query returns a list of recipes where the recipe title contains Fruitful.

RequestResponse

query RecipeFruitful {
 allM_Content(where: { recipe_Title_contains: "Fruitful" }) {
  total
  results {
   content_Name
   __typename
  }
 }
}

RequestResponse

{
 "data": {
  "allM_Content": {
   "total": 3,
   "results": [
    {
     "content_Name": "Fruitful refreshing ginger lemonade",
     "__typename": "M_Content_Recipe"
    },
    {
     "content_Name": "Sparkling Punch using Fruitful Orange",
     "__typename": "M_Content_Recipe"
    },
    {
     "content_Name": "Fruitful Mocktails",
     "__typename": "M_Content_Recipe"
    }
   ]
  }
 }
}

Query content items for certain taxonomies

This query returns data about a specific content taxonomy, specifically blog posts. The returned data consists of the title and the quote associated with the blog post.

RequestResponse

query getAllBlogs {
 allM_Content_Blog {
  results {
   blog_Title
   blog_Quote
 }
 }
}

RequestResponse

{
 "data": {
  "allM_Content_Blog": {
   "results": [
    {
     "blog_Title": "Who wants a mimosa?!",
     "blog_Quote": null
    },
    {
     "blog_Title": "Nutrition tips blog post",
     "blog_Quote": null
    },
    {
     "blog_Title": "Kracht komt van binnenuit",
     "blog_Quote": null
    },
    {
     "blog_Title": "Power comes from within",
     "blog_Quote": null
    },
    {
     "blog_Title": "Healthful nutrition helps you develop your diet",
     "blog_Quote": null
    },
    {
     "blog_Title": "Health Is Happiness",
     "blog_Quote": null
    }
   ]
  }
 }
}

Query content items in a specific collection

This query returns data about a content collection with a specific ID. This data includes an object containing the various content items in that collection.

RequestResponse

query getContentInContentCollection {
 allM_ContentCollection(where: { id_eq: "Ai-JNhneM024pMItfBeYJQ" }) {
  total
  results {
   id
   contentCollectionName

   contentCollectionToContent {
    __typename
    total
    results {
     content_Name
     __typename
    }
   }
  }
 }
}

RequestResponse

{
 "data": {
  "allM_ContentCollection": {
   "total": 1,
   "results": [
    {
     "id": "Ai-JNhneM024pMItfBeYJQ",
     "contentCollectionName": "Fruitful",
     "contentCollectionToContent": {
      "__typename": "M_ContentList",
      "total": 4,
      "results": [
       {
        "content_Name": "Healthy Mimosa blog",
        "__typename": "M_Content_Blog"
       },
       {
        "content_Name": "Healthful is the latest Flavorful Brand",
        "__typename": "M_Content_Email"
       },
       {
        "content_Name": "Sparkling Punch using Fruitful Orange",
        "__typename": "M_Content_Recipe"
       },
       {
        "content_Name": "Power comes from within",
        "__typename": "M_Content_Blog"
       }
      ]
     }
    }
   ]
  }
 }
}

Query all variants that have localization of en-US

This query returns all content item variants with the en-US localization parameter.

RequestResponse

query variantIsEnUS {
 allM_Content(
  where: {
   m_Content_IsVariant_eq: true
   localizationToContent: { m_Localization_ids: "M.Localization.en-US" }
  }
 ) {
  total
  results {
   id
   content_Name
   m_Content_IsVariant
   localizationToContent {
    valueName
   }
  }
 }
}

RequestResponse

{
 "data": {
  "allM_Content": {
   "total": 1,
   "results": [
    {
     "id": "iAzTTLtsoEmuGKqBxPuAVg",
     "content_Name": "Fruitful Summer 2021 (en-US)",
     "m_Content_IsVariant": true,
     "localizationToContent": {
      "valueName": "en-US"
     }
    }
   ]
  }
 }
}

Query all variants from entities in a campaign

This query looks at a campaign with a specific ID, and returns all variants of that campaign.

RequestResponse

query campaignVariant {
 allM_Content(
  where: {
   campaignToContent: { m_CMP_Campaign_ids: "M.CMP.Campaign.Summer2018" }
   m_Content_IsVariant_eq: true
  }
 ) {
  total
  results {
   id
   content_Name
   m_Content_IsVariant
  }
 }
}

RequestResponse

{
 "data": {
  "allM_Content": {
   "total": 2,
   "results": [
    {
     "id": "wT5RNeIcQ0SHTORNT1faug",
     "content_Name": "Fruitful Summer (it-IT)",
     "m_Content_IsVariant": true
    },
    {
     "id": "BDolxU3bGkWMwFJk-s8Idg",
     "content_Name": "Fruitful Summer (es-ES)",
     "m_Content_IsVariant": true
    }
   ]
  }
 }
}

Query all variants of a content entity

This query looks at an entity with a specific ID, and returns all variants of that entity.

RequestResponse

query allVariantsOfContent {
 m_Content(id: "pBxKLsZaQU21-CTu9y0bWw") {
  contentToContentVariant_Children {
   results {
    id
    content_Name
    __typename
    localizationToContent {
     valueName
    }
   }
  }
 }
}

RequestResponse

{
 "data": {
  "m_Content": {
   "contentToContentVariant_Children": {
    "results": [
     {
      "id": "bb_RjQxMS0O9ziQG7EWuog",
      "content_Name": "Fruitful Summer (de-DE)",
      "__typename": "M_Content_Email",
      "localizationToContent": {
       "valueName": "de-DE"
      }
     },
     {
      "id": "ah1bserorU-CIcDjFb5p-g",
      "content_Name": "Fruitful Summer 2021 (en-GB)",
      "__typename": "M_Content_Email",
      "localizationToContent": {
       "valueName": "en-GB"
      }
     },
     {
      "id": "iAzTTLtsoEmuGKqBxPuAVg",
      "content_Name": "Fruitful Summer 2021 (en-US)",
      "__typename": "M_Content_Email",
      "localizationToContent": {
       "valueName": "en-US"
      }
     }
    ]
   }
  }
 }
}

Query draft content items in preview

This query returns all content items that are in the Draft state.

RequestResponse

query draftContentPreview {
 allM_Content(where: { m_Content_IsDraft_eq: true }) {
  total
  results {
   id
   content_Name
   m_Content_IsDraft
  }
 }
}

RequestResponse

{
 "data": {
  "allM_Content": {
   "total": 2,
   "results": [
    {
     "id": "Content.WakeUp",
     "content_Name": "Everyone Wake Up",
     "m_Content_IsDraft": true
    },
    {
     "id": "Content.DevelopingADiet",
     "content_Name": "Developing a diet",
     "m_Content_IsDraft": true
    }
   ]
  }
 }
}

Query where there is more than one content version

This query returns all content items that have more than one version.

RequestResponse

query moreThanOneVersionContent {
 allM_Content(where: { content_NumberOfCreatedVersions_gt: 1 }) {
  total
  results {
   id
   content_Name
   m_Content_IsDraft
   content_NumberOfCreatedVersions
   content_ApprovedForCreation

  }
 }
}

RequestResponse

{
 "data": {
  "allM_Content": {
   "total": 1,
   "results": [
    {
     "id": "Content.FruitfulGinger",
     "content_Name": "Fruitful refreshing ginger lemonade",
     "m_Content_IsDraft": false,
     "content_NumberOfCreatedVersions": 3,
     "content_ApprovedForCreation": null
    }
   ]
  }
 }
}

Query conditional metadata based on the content type

This query returns content based on the content type (blog or recipe) and the status of the content (draft).

RequestResponse

query draftConteintInPreview {
 allM_Content(where: { m_Content_IsDraft_eq: true }) {
  total
  results {
   id
   content_Name
    ...on M_Content_Blog {
    blog_Title
    blog_Body
   }
   ...on M_Content_Recipe {
    recipe_Title
    recipe_Ingredients
   }
  }
 }
}

RequestResponse

{
 "data": {
  "allM_Content": {
   "total": 2,
   "results": [
    {
     "id": "t0uouuAwqkCYDo6Cfrub3w",
     "content_Name": "Summer Mimosa",
     "blog_Title": "Who wants a mimosa?!",
     "blog_Body": " p I do, always! Mimosas are supremely simple bubbly cocktails made with sparkling wine and orange juice. They’re light, fizzy and easy to sip. /p figure class=\"image\" img srcset=\"https://stylelabsdemo.com/api/public/content/17d2484d681844c29780547185d53ffd?v=2d1e5a46&t=w320 320w, https://stylelabsdemo.com/api/public/content/17d2484d681844c29780547185d53ffd?v=2d1e5a46&t=w480 480w\" width=\"664\" src=\"https://stylelabsdemo.com/api/public/content/17d2484d681844c29780547185d53ffd?v=2d1e5a46\" alt=\"Mimosa cocktails\" /figure p I love ordering mimosas at weekend brunch, and serving them to family and friends on holidays—Easter, Mother’s Day, July 4th, Christmas, you name it. Mimosas liven up wedding showers and baby showers. I bring mimosa supplies to football watch parties, and no one complains. I’ve shared a few variations on mimosas over the years. Today, I’m going to share everything you’ve ever wanted to know about mimosas, plus a basic mimosa recipe and variations. If you haven’t poured your first mimosa yet, you’ll be a mimosa expert by the end of this post! If you’re a seasoned mimosa drinker, I think you’ll find some new tips here, too. /p p   /p p strong Mimosa Ingredients: /strong /p p Classic mimosas require just two ingredients: dry sparkling wine, and orange juice. Some recipes will tell you to add some other alcohol or orange liqueur. Don’t listen to them! /p p strong Sparkling Wine /strong /p p The best Champagne for mimosas isn’t actually Champagne. For mimosas, opt for less-expensive Cava or Prosecco. Cava is from Spain and Prosecco is from Italy, but they’re both delicious dry sparkling wines that mix well with juice. Bonus? They’re affordable. A good bottle of Cava or Prosecco will run about $12 to $16. Avoid super cheap sparkling wine, unless you want a headache with your mimosas. Don’t waste your pricy bottle of Champagne on mimosas, since we’re diluting those delicate notes with orange juice. /p p strong Orange Juice /strong /p p Cold, fresh orange juice is best for mimosas. If you’re buying orange juice at the store, opt for high-quality such as the Fruitful Orange Juice! /p "
    },
    {
     "id": "-CVRo6Z7Y02yXEH_rS6y7w",
     "content_Name": "Fruitful refreshing ginger lemonade",
     "recipe_Title": "Fruitful refreshing ginger lemonade as an alternative to soda",
     "recipe_Ingredients": " p Ingredients /p p 3 cups white sugar br 4 quarts water br 14 slices fresh ginger root br 4 cups fresh lemon juice br 2 lemons, sliced /p "
    }
   ]
  }
 }
}

Query URLs and relative URLs for a specific asset

This query returns the public links and relative URLs for a specific asset based on its identifier.

RequestResponse

query AssetPublicLinks {
 m_Asset(id: "asset.toa-heftiba-271805") {
  fileName
  id
  urls
  assetToPublicLink {
   results {
    id
    status
    relativeUrl
    resource
    expirationDate
   }
  }
 }

RequestResponse

{
 "data": {
  "m_Asset": {
   "fileName": "toa-heftiba-271805.jpg",
   "id": "asset.toa-heftiba-271805",
   "urls": {
    "4f4e0ccfab8642009fe9ef321bdaa970": {
     "url": "https://sitecore-test-staging.cloud/api/public/content/4f4e0ccfab8642009fe9ef321bdaa970?v=df2e3a60",
     "expiredOn": null,
     "resource": "downloadOriginal",
     "metadata": {
      "filesize": 1.1,
      "filesizebytes": "1101428",
      "filename": "toa-heftiba-271805.jpg",
      "width": "3936",
      "height": "2624",
      "group": "Images",
      "extension": "jpg",
      "content_type": "image/jpeg",
      "resolution": "3936 2624",
      "colorspace": "RGB ",
      "megapixels": "10.328064"
     }
    },
    "3a497bc29c5741d985839e26cb198422": {
     "url": "https://sitecore-test-staging.cloud/api/public/content/3a497bc29c5741d985839e26cb198422?v=0f28452c",
     "expiredOn": null,
     "resource": "preview",
     "metadata": {
      "width": "1100",
      "height": "733",
      "content_type": "image/jpeg",
      "filesizebytes": "68885"
     }
    }
   },
   "assetToPublicLink": {
    "results": [
     {
      "id": "AKxo6TjtQkKHCjQwNvKlSA",
      "status": "Completed",
      "relativeUrl": "3a497bc29c5741d985839e26cb198422",
      "resource": "preview",
      "expirationDate": null
     },
     {
      "id": "nzxMRalDaUeDN0ZThInemg",
      "status": "Completed",
      "relativeUrl": "4f4e0ccfab8642009fe9ef321bdaa970",
      "resource": "downloadOriginal",
      "expirationDate": null
     }
    ]
   }
  }
 }
}

This query returns the ID and public URLs associated with each available asset.

RequestResponse

{
 allM_Asset {
  results {
   id
   urls
  }
 }
}

RequestResponse

{
 "data": {
  "allM_Asset": {
   "results": [
    {
     "id": "asset.oatmeal.jpg",
     "urls": {
      "oatmeal": {
       "url": "https://sitecore-test-staging.cloud/api/public/content/oatmeal?v=c498d245",
       "expiredOn": null,
       "resource": "downloadOriginal",
       "metadata": {
        "filesize": 0.18,
        "filesizebytes": "180019",
        "filename": "oatmeal.jpg",
        "width": "1500",
        "height": "575",
        "group": "Images",
        "extension": "jpg",
        "content_type": "image/jpeg",
        "resolution": "1500 575",
        "colorspace": "sRGB",
        "megapixels": "0.8625"
       }
      }
     }
    },
    {
     "id": "asset.fruitful-product-line",
     "urls": {}
    },
    {
     "id": "asset.fruitful-hero2",
     "urls": {}
    },
    {
     "id": "asset.sara-dubler-769470",
     "urls": {
      "summersalad": {
       "url": "https://sitecore-test-staging.cloud/api/public/content/summersalad?v=78f938b8",
       "expiredOn": null,
       "resource": "downloadOriginal",
       "metadata": {
        "filesize": 2.03,
        "filesizebytes": "2033543",
        "filename": "sara-dubler-769470.jpg",
        "width": "3456",
        "height": "2304",
        "group": "Images",
        "extension": "jpg",
        "content_type": "image/jpeg",
        "resolution": "3456 2304",
        "colorspace": "RGB ",
        "megapixels": "7.962624"
       }
      }
     }
    },
    {
     "id": "asset.logo-healthful.ai",
     "urls": {}
    },
    {
     "id": "asset.fruitful-presentation",
     "urls": {
      "cf17f452bab44781bd2648f3b08c4083": {
       "url": "https://sitecore-test-staging.cloud/api/public/content/cf17f452bab44781bd2648f3b08c4083?v=22521590",
       "expiredOn": null,
       "resource": "downloadOriginal",
       "metadata": {
        "filesize": 0.78,
        "filesizebytes": "776473",
        "filename": "fruitful-presentation-v1.png",
        "width": "1920",
        "height": "1080",
        "group": "Vectors",
        "extension": "png",
        "content_type": "image/png",
        "resolution": "1920 1080",
        "colorspace": "RGB ",
        "megapixels": "2.0736",
        "creator": "Adobe Photoshop CC 2018 (Macintosh)"
       }
      },
      "39d8dd7ae68b4197a501179c8496eae6": {
       "url": "https://sitecore-test-staging.cloud/api/public/content/39d8dd7ae68b4197a501179c8496eae6?v=dd800038",
       "expiredOn": null,
       "resource": "preview",
       "metadata": {
        "width": "1100",
        "height": "619",
        "content_type": "image/png",
        "filesizebytes": "285321"
       }
      }
     }
    }
   ]
  }
 }
}

Do you have some feedback for us?

If you have suggestions for improving this article,