GraphQL の例
以下は、GraphQL クエリの例です。
公開されたアイテムをクエリする
publishStatus_eq: "Published"
を使ってコンテンツを公開したときにクエリを実行します。
リクエスト本文
{
allM_Content(where: { publishStatus_eq: "Published" }) {
total
results {
content_Name
publishStatus
__typename
}
}
}
応答
{
"data": {
"allM_Content": {
"total": 2,
"results": [
{
"content_Name": "Healthful is the latest Flavorful Brand",
"publishStatus": "Published",
"__typename": "M_Content_Email"
},
{
"content_Name": "Life and Lemons",
"publishStatus": "Published",
"__typename": "M_Content_SocialMediaMessage"
}
]
}
}
}
特定の分類のコンテンツ アイテムをクエリする
特定の分類についてコンテンツ アイテムをクエリすると、ブログの総数とともに、すべてのブログのタイトルと引用が表示されます。
リクエスト本文
query getAllBlogs {
allM_Content_Blog {
total
results {
blog_Title
blog_Quote
}
}
}
応答
{
"data": {
"allM_Content_Blog": {
"total": 6,
"results": [
{
"blog_Title": "Who wants a mimosa!",
"blog_Quote": "<p>Sometimes I put a splash of orange juice in my champagne.</p>"
},
{
"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
}
]
}
}
}
特定のコンテンツ コレクション内のコンテンツ アイテムをクエリする
id_eq
を使用してコンテンツ アイテムをクエリします。
リクエスト本文
query getContentInContentCollection {
allM_ContentCollection(where: { id_eq: "Ai-JNhneM024pMItfBeYJQ" }) {
total
results {
id
contentCollectionName
contentCollectionToContent {
__typename
total
results {
content_Name
__typename
}
}
}
}
}
応答
{
"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"
}
]
}
}
]
}
}
}
en-US のローカリゼーションを持つすべての変数をクエリする
元のコンテンツ (m_Content_IsVariant_eq: true
) の変数であるすべてのコンテンツと、en-US(m_Localization_ids: "M.Localization.en-US"
) のローカリゼーションを持つコンテンツをクエリします。
リクエスト本文
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
}
}
}
}
応答
{
"data": {
"allM_Content": {
"total": 1,
"results": [
{
"id": "iAzTTLtsoEmuGKqBxPuAVg",
"content_Name": "Fruitful Summer 2021 (en-US)",
"m_Content_IsVariant": true,
"localizationToContent": {
"valueName": "en-US"
}
}
]
}
}
}
キャンペーン内のエンティティからすべての変数をクエリする
キャンペーン ID とブール値 m_Content_IsVariant_eq: true
を使用して、キャンペーン内のエンティティからすべての変数をクエリし、変数を表示します。
リクエスト本文
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
}
}
}
応答
{
"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
}
]
}
}
}
コンテンツ エンティティのすべての変数をクエリする
親コンテンツ ID と contentToContentVariant_Children
フィールドを使用してコンテンツ エンティティのすべての変数をクエリし、変数を表示します。
リクエスト本文
query allVariantsOfContent {
m_Content(id: "pBxKLsZaQU21-CTu9y0bWw") {
contentToContentVariant_Children {
results {
id
content_Name
__typename
localizationToContent {
valueName
}
}
}
}
}
応答
{
"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"
}
}
]
}
}
}
}
プレビューでドラフト コンテンツ アイテムをクエリする
m_Content_IsDraft_eq: true
を使用して、プレビューでドラフト コンテンツ アイテムをクエリします。
リクエスト本文
query draftContentPreview {
allM_Content(where: { m_Content_IsDraft_eq: true }) {
total
results {
id
content_Name
m_Content_IsDraft
}
}
}
応答
{
"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
}
]
}
}
}
複数のバージョンがあるコンテンツをクエリする
content_NumberOfCreatedVersions_gt: 1
を使用して、複数のバージョンがあるコンテンツをクエリします。
リクエスト本文
query moreThanOneVersionContent {
allM_Content(where: { content_NumberOfCreatedVersions_gt: 1 }) {
total
results {
id
content_Name
m_Content_IsDraft
publishStatus
content_NumberOfCreatedVersions
content_ApprovedForCreation
}
}
}
応答
{
"data": {
"allM_Content": {
"total": 1,
"results": [
{
"id": "BDolxU3bGkWMwFJk-s8Idg",
"content_Name": "Fruitful Summer (es-ES)",
"m_Content_IsDraft": null,
"publishStatus": "NotPublished",
"content_NumberOfCreatedVersions": 2,
"content_ApprovedForCreation": true
}
]
}
}
}
コンテンツの型に基づいて条件付きメタデータをクエリする
インターフェイスを使用してサブクエリを作成し、コンテンツの型に基づいて条件付きメタデータをクエリします。
リクエスト本文
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
}
}
}
}
応答
{
"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>"
}
]
}
}
}
Can we improve this article ? Provide feedback