1. GraphQL

GraphQLの例

日本語翻訳に関する免責事項

このページの翻訳はAIによって自動的に行われました。可能な限り正確な翻訳を心掛けていますが、原文と異なる表現や解釈が含まれる場合があります。正確で公式な情報については、必ず英語の原文をご参照ください。

以下は、Sitecore Content Hubで使用できるGraphQLクエリの例です。

クエリレシピのタイトルにFruitfulが含まれている

このクエリは、レシピのタイトルにFruitfulが含まれているレシピのリストを返します。

query RecipeFruitful {
 allM_Content(where: { recipe_Title_contains: "Fruitful" }) {
  total
  results {
   content_Name
   __typename
  }
 }
}
{
 "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 getAllBlogs {
 allM_Content_Blog {
  results {
   blog_Title
   blog_Quote
 }
 }
}
{
 "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
    }
   ]
  }
 }
}

特定のコレクション内のコンテンツ項目のクエリ

このクエリは、特定のIDを持つコンテンツコレクションに関するデータを返します。このデータには、そのコレクション内のさまざまなコンテンツ項目を含むオブジェクトが含まれます。

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のローカリゼーションを持つすべてのバリアントをクエリします

このクエリは、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を持つキャンペーンを検索し、そのキャンペーンのすべてのバリエーションを返します。

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を持つエンティティを検索し、そのエンティティのすべてのバリアントを返します。

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"
      }
     }
    ]
   }
  }
 }
}

プレビューでの下書きコンテンツ項目のクエリ

このクエリは、Draft状態にあるすべてのコンテンツ項目を返します。

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
    }
   ]
  }
 }
}

複数のコンテンツバージョンがある場合のクエリ

このクエリは、複数のバージョンを持つすべてのコンテンツ項目を返します。

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

  }
 }
}
{
 "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 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 "
    }
   ]
  }
 }
}

特定のアセットのURLと相対URLのクエリ

このクエリは、特定のアセットの公開リンクと相対URLをその識別子に基づいて返します。

query AssetPublicLinks {
 m_Asset(id: "asset.toa-heftiba-271805") {
  fileName
  id
  urls
  assetToPublicLink {
   results {
    id
    status
    relativeUrl
    resource
    expirationDate
   }
  }
 }
{
 "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
     }
    ]
   }
  }
 }
}

すべてのアセットをクエリし、関連する公開リンクを表示する

このクエリは、使用可能な各アセットに関連付けられたIDと公開URLを返します。

{
 allM_Asset {
  results {
   id
   urls
  }
 }
}
{
 "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"
       }
      }
     }
    }
   ]
  }
 }
}
この記事を改善するための提案がある場合は、 お知らせください!