Featured Post
Sitecore Experience Edge GraphQL Queries
- Get link
- X
- Other Apps
In this article, we will explore about Sitecore scalable API layer called Sitecore Experience Edge which provides you a Sitecore-hosted GraphQL (GQL) API. With these Edge GraphQL (GQL) endpoint you can build your solution in any language and pull the required content with the help of GraphQL (GQL).
The major GraphQL APIs of Sitecore Experience Edge are:- Preview API
- Delivery API
GraphQL is a query language for these APIs that gives you a flexible way to query the data. It also provides the flexibility to define API endpoints with custom url's. These endpoints host the schema, which is a strongly typed graph definition where endpoints understand the GraphQL language.
I have explained in detail about Sitecore GraphQL and Sitecore Experience Edge and in my previous blog posts:This article will provide the details about Sitecore GraphQL Edge queries usage and how it will be useful in creating Sitecore projects especially Sitecore JSS projects. The topics covered under this Sitecore GraphQL Edge queries article are:
- Sitecore Edge GraphQL - Get an item by path and show field id and name
- Sitecore Edge GraphQL - Return the custom name of field
- Sitecore Edge GraphQL - Return the name and value from all fields
- Sitecore Edge GraphQL - Return a specific field with Alias
- Sitecore Edge GraphQL - Get Child Items using GraphQL
- Sitecore Edge GraphQL - Get a typed safe data using GraphQL
- Sitecore Edge GraphQL - Get specific Child Items using GraphQL and alias
- Sitecore Edge GraphQL - Get the values of Tree-list or Multi-list field type
- Sitecore Edge GraphQL - Get the values of Treelist or Multilist field type from child item of current context
- Sitecore Edge GraphQL - Get the template field details with values of current item
- Sitecore Edge GraphQL - Get the field values using Aliases
- Sitecore Edge GraphQL - Get repeated fields using Fragments
- Sitecore Edge GraphQL Search - using Search query keyword
- Sitecore Edge GraphQL Search - Apply filter not to return items from specific path
- Sitecore Edge GraphQL Search – Parameter details
- Sitecore Edge GraphQL Search - Hide items based on specific template
- Sitecore Edge GraphQL Search – Order By Field and Order by Direction
- Sitecore Edge GraphQL Search – AND / OR Condition (ItemSearchPredicateInput) Usage
- Sitecore Edge GraphQL Search – Pagination and first/after parameters
- Sitecore Edge GraphQL Search – Get all field name of the search result item
- Sitecore Edge GraphQL Search – Return a specific field with Alias
Sitecore GraphQL Architecture
To get more details about Sitecore Edge GraphQL Integrated Development Environment (IDE), you can check my previous article Quickstart guide - All about Sitecore Experience Edge.
- Sitecore Experience Manager (XM)
- Sitecore Edge Preview IDE:
You have to use the preview IDE URL as https://[WEBSITE HOST ADDRESS]/sitecore/api/graph/edge/ui and preview API URL as https://[WEBSITE HOST ADDRESS]/sitecore/api/graph/edge, and need to replace [WEBSITE HOST ADDRESS] with your Sitecore CM instance host address
To access the conentent:
You have to pass the API key and check the details at Sitecore Experience Manager (XM) Preview API Key
Once you have the API key then you have to pass the API key to the HTTP header of the API request
If you are accessing Edge GQL IDE in Sitecore Experience Platform (SXP) then may be sometimes you have to set the IDE Request Credentials setting and need to use the API Key present at /sitecore/system/Settings/Services/API Keys - Sitecore Edge Delivery IDE:
You have to use the delivery IDE URL as https://edge.sitecorecloud.io/api/graphql/ide and delivery API URL as https://edge.sitecorecloud.io/api/graphql/v1:
To access the conentent:
You have to pass the API key, if you are using Sitecore Demo Portal (this portal are NOT XM Cloud based. They are container environments hosted on AKS) then you can check steps at Sitecore Demo Portal Edge GraphQL API Key to get the API key and if you are using Sitecore SXP then need to use the API Key present at /sitecore/system/Settings/Services/API Keys but you can't use GQL IDE for Sitecore SXP Content Delivery instance because its disabled.
Once you have the API key then you have to pass the API key to the HTTP header of the API request.
- Sitecore Edge Preview IDE:
- Sitecore Experience Manager (XM) Cloud
- Sitecore Edge Preview IDE:
You have to use the preview IDE URL as https://[WEBSITE HOST ADDRESS]/sitecore/api/graph/edge/ide and preview API URL as https://[WEBSITE HOST ADDRESS]/sitecore/api/graph/edge, and need to replace [WEBSITE HOST ADDRESS] with your Sitecore XM Cloud CM instance host address
To access the conentent:
You have to pass the API key and check the details at Sitecore Experience Manager (XM) Cloud Preview API Key
Once you have the API key then you have to pass the API key to the HTTP header of the API request
- Sitecore Edge Delivery IDE:
You have to use the delivery IDE URL as https://edge.sitecorecloud.io/api/graphql/ide and delivery API URL as https://edge.sitecorecloud.io/api/graphql/v1:
To access the conentent:
You have to pass the API key, if you are using Sitecore XM Cloud Portal then you can check steps at Sitecore XM Cloud Edge GraphQL Delivery API Key to get the API key.
Once you have the API key then you have to pass the API key to the HTTP header of the API request.
- Sitecore Edge Preview IDE:
Sitecore XM Portal Content Tree:
The examples of Sitecore Edge GraphQL queries are:- Sitecore Edge GraphQL - Get an item by path and show field id and name
query GQLQuerySamples( $contextItem: String!) { #----Get an item by path and show field id and name:: Start ::------ GQLType1: item(path: $contextItem, language:"en"){ id, name } #----Get an item by path and show field id and name:: End ::------ } #--- Sitecore Edge Graphql Query Variables ------::Start::------ #--- To use below Sitecore Edge Graphql Query Variables you have to uncomment # and place in the QUERY VARIABLES section # {"contextItem" :"/sitecore/content/Website/Website1/Home"} #--- Sitecore Edge Graphql Query Variables ------::End::------
- Sitecore Edge GraphQL - Return the custom name of field
query GQLQuerySamples( $contextItem: String!) { #----Custom name for a field, test contain the id value:: Start ::------ GQLType2: item(path: $contextItem,, language:"en") { id name ItemId: id } #----Custom name for a field, test contain the id value:: End ::------ } # in the above query, mind the ",," it will work. #--- Sitecore Edge Graphql Query Variables ------::Start::------ #--- To use below Sitecore Edge Graphql Query Variables you have to uncomment # and place in the QUERY VARIABLES section # {"contextItem" :"/sitecore/content/Website/Website1/Home"} #--- Sitecore Edge Graphql Query Variables ------::End::------
- Sitecore Edge GraphQL - Return the name and value from all fields
query GQLQuerySamples( $contextItem: String!, $language: String!) { #----Return the name and value from all fields:: Start ::------ GQLType3: item(path: $contextItem,language:$language) { fields { name value } } #----Return the name and value from all fields:: End ::------ } #--- Sitecore Edge Graphql Query Variables ------::Start::------ #--- To use below Sitecore Edge Graphql Query Variables you have to uncomment # and place in the QUERY VARIABLES section # { # "contextItem" :"/sitecore/content/Website/Website1/Home", # "language" :"en" #} #--- Sitecore Edge Graphql Query Variables ------::End::------
With the help of this you can get the list of available fields. - Sitecore Edge GraphQL - Return a specific field with Alias
query GQLQuerySamples( $contextItem: String!, $language: String!) { #----Return a specific field, in this case field "Title" with Alias:: Start ::------ GQLType4: item(path: $contextItem,language:$language) { PageTitle:field(name : "Title") { MyPageTitle:value } } #----Return a specific field, in this case field "Title" with Alias:: End ::------ } #--- Sitecore Edge Graphql Query Variables ------::Start::------ #--- To use below Sitecore Edge Graphql Query Variables you have to uncomment # and place in the QUERY VARIABLES section # { # "contextItem" :"/sitecore/content/Website/Website1/Home", # "language" :"en" #} #--- Sitecore Edge Graphql Query Variables ------::End::------
- Sitecore Edge GraphQL - Get Child Items using GraphQL
query GQLQuerySamples( $contextItem: String!, $language: String!) { #----Get a children: You can access only common values :: Start ::------ #child specific values or get all field values as per Example# 3 GQLType5: item(path: $contextItem,language:$language) { id name children { results { id name fields { name value } } } } #----Get a children: You can access only common values :: End ::------ } #--- Sitecore Edge Graphql Query Variables ------::Start::------ #--- To use below Sitecore Edge Graphql Query Variables you have to uncomment # and place in the QUERY VARIABLES section # { # "contextItem" :"/sitecore/content/Website/Website1/Home", # "language" :"en" #} #--- Sitecore Edge Graphql Query Variables ------::End::------
In the above example, we are trying to get the child items of HOME node.
- Sitecore Edge GraphQL - Get a typed safe data using GraphQL
query GQLQuerySamples( $contextItem: String!, $language: String!) { #----Get a typed safe data on the basis of template :: Start ::------ GQLType6: item(path: $contextItem,language:$language) { children { results { ... on Speaker { id name sponsors {value} vendors {value} sessions {value} description {value} role {value} picture {value} } } } } #----Get a typed safe data on the basis of template :: End ::------ } #--- Sitecore Edge Graphql Query Variables ------::Start::------ #--- To use below Sitecore Edge Graphql Query Variables you have to uncomment # and place in the QUERY VARIABLES section # { # "contextItem" :"/sitecore/content/EdgeWebsite/home/speakers", # "language" :"en" #} #--- Sitecore Edge Graphql Query Variables ------::End::------
If you have multiple items based on different templates then it will return result based on typed data if present (no error message) otherwise not, and you can combine multiple templates in one query.
- Sitecore Edge GraphQL - Get specific Child Items using GraphQL and alias
query GQLQuerySamples( $contextItem: String!, $language: String!) { #----Get only specific children on the basis of Template :: Start ::------ GQLType7: item(path: $contextItem,language:$language) { #-- Get only Webpage children (includeTemplateIDs: ["6DB09CEF64A852A3A98038408109C4D7"]) { results { template{id name } name displayName ... on Webpage { pageTitle {value} } } } } #----Get only specific children on the basis of Template :: End ::------ } #--- Sitecore Edge Graphql Query Variables ------::Start::------ #--- To use below Sitecore Edge Graphql Query Variables you have to uncomment # and place in the QUERY VARIABLES section # { # "contextItem" :"/sitecore/content/EdgeWebsite/home", # "language" :"en" #} #--- Sitecore Edge Graphql Query Variables ------::End::------
- Sitecore Edge GraphQL - Get the values of Tree-list or Multi-list field type
query GQLQuerySamples( $contextItem: String!, $language: String!) { #----Get value of multi-list field from item :: Start ::------ GQLType8: item(path: $contextItem,language:$language) { ... on Speaker { id name sessions { SessionList:targetItems { ... on Session { SessionId: id SessionName: name SessionPageTitle: pageTitle {value} description { id value jsonValue definition {type} } } } } } } #----Get value of multi-list field from item :: End ::------ } #--- Sitecore Edge Graphql Query Variables ------::Start::------ #--- To use below Sitecore Edge Graphql Query Variables you have to uncomment # and place in the QUERY VARIABLES section # { # "contextItem" :"/sitecore/content/EdgeWebsite/home/speakers/Alex Mena", # "language" :"en" #} #--- Sitecore Edge Graphql Query Variables ------::End::------
- Sitecore Edge GraphQL - Get the values of Treelist or Multilist field type from child item of current context
query GQLQuerySamples( $contextItem: String!, $language: String!) { #----Get children of multi-list field from child item of current context :: Start ::------ GQLType9: item(path: $contextItem,language:$language) { ... on Speaker { id name sessions { SessionList:targetItems { ... on Session { SessionId: id SessionName: name SessionPageTitle: pageTitle {value} # using Parent item to get its child parent { id path # Get only some child items, if many different template item present children (includeTemplateIDs: ["{D8AA73E1-C275-4EEE-BB9D-333925E51952}"]) { results { id name path } } } } } } } } #----Get children of multi-list field from child item of current context :: End ::------ } #--- Sitecore Edge Graphql Query Variables ------::Start::------ #--- To use below Sitecore Edge Graphql Query Variables you have to uncomment # and place in the QUERY VARIABLES section # { # "contextItem" :"/sitecore/content/EdgeWebsite/home/speakers/Alex Mena", # "language" :"en" #} #--- Sitecore Edge Graphql Query Variables ------::End::------
- Sitecore Edge GraphQL - Get the template field details with values of current item
query GQLQuerySamples( $contextItem: String!, $language: String!) { #----Get the template field details with values of current item :: Start ::------ GQLType10: item(path: $contextItem,language:$language) { ... on Speaker { id name __typename templateName:template { id name } # Fields present on specific item ... on Item { fields { id name value } } } } #----Get the template field details with values of current item :: End ::------ } #--- Sitecore Edge Graphql Query Variables ------::Start::------ #--- To use below Sitecore Edge Graphql Query Variables you have to uncomment # and place in the QUERY VARIABLES section # { # "contextItem" :"/sitecore/content/EdgeWebsite/home/speakers/Alex Mena", # "language" :"en" #} #--- Sitecore Edge Graphql Query Variables ------::End::------
- Sitecore Edge GraphQL - Get the field values using Aliases
query GQLQuerySamples( $contextItem: String!, $language: String!) { #----Get the field values using Aliases :: Start ::------ GQLType11: item(path: $contextItem,language:$language) { ... on Speaker { id SpeakerName: name # You can add aliases to field attributes also role {Speaker_Role:value} } } #----Get the field values using Aliases :: End ::------ } #--- Sitecore Edge Graphql Query Variables ------::Start::------ #--- To use below Sitecore Edge Graphql Query Variables you have to uncomment # and place in the QUERY VARIABLES section # { # "contextItem" :"/sitecore/content/EdgeWebsite/home/speakers/Alex Mena", # "language" :"en" #} #--- Sitecore Edge Graphql Query Variables ------::End::------
- Sitecore Edge GraphQL - Get repeated fields using Fragments
query GQLQuerySamples( $contextItem: String!, $language: String!) { #---------Use this part to test Fragment Query Example-----------::Start::------------ GQLType12: item(path: $contextItem,language:$language) { ... on Speaker { id name sessions { ... Sessions } } } } fragment Sessions on MultilistField { SessionList:targetItems { name id ... on Session { SessionId: id SessionName: name SessionPageTitle: pageTitle {value} rooms { # Use of Fragment at child items ... Rooms } } } } fragment Rooms on MultilistField { RoomList:targetItems { name id ... on Room { RoomId: id RoomName: name RoomDescription: description {value} } } } #---------Use this part to test Fragment Query Example-----------::End::------------ #--- Sitecore Edge Graphql Query Variables ------::Start::------ #--- To use below Sitecore Edge Graphql Query Variables you have to uncomment # and place in the QUERY VARIABLES section # { # "contextItem" :"/sitecore/content/EdgeWebsite/home/speakers/Alex Mena", # "language" :"en" #} #--- Sitecore Edge Graphql Query Variables ------::End::------
- Sitecore Edge GraphQL Search - using Search query keyword
#1. Sitecore Edge GraphQL Search Query _path usage # you will get all items under the /sitecore/content/EdgeWebsite/home/speakers {1F4B781B-F2A5-5647-99DF-C0C369162C4D} # and _path accept only GUID (with or without braces). # It will return records from /page-components also query { pageOne: search( where: { AND: [ { name: "_path" value: "{1F4B781B-F2A5-5647-99DF-C0C369162C4D}" operator: CONTAINS } ] } # defaults to 10 first: 10 ) { total pageInfo { endCursor hasNext } results { url { path } } } }
- Sitecore Edge GraphQL Search - Apply filter not to return items from specific path
#2. Sitecore Edge GraphQL Search - Apply filter not to return items from specific path # To filter not to return child items from particular path we can use # NCONTAINS operator # If we want to exclude items under specific locations, e.g., need to hide items which are present under /sitecore/content/EdgeWebsite/home/speakers/Page Components: # GUID of /sitecore/content/EdgeWebsite/home/speakers/Page Components {81347F0C-A6F8-4A09-8D0A-0600485D5894} # It will not return records under the /Page Components query SearchQuery ( $pageSize: Int = 10 $language: String = "" $rootpath: String = "" ) { pageOne: search( where: { AND: [ { name: "_path" value:$rootpath operator: CONTAINS } { name: "_path" value: "{81347F0C-A6F8-4A09-8D0A-0600485D5894}" operator: NCONTAINS } { name: "_language" value: $language } ] } # defaults to 10 first: $pageSize ) { total pageInfo { endCursor hasNext } results { id path fields{name __typename } } } } #--- Sitecore Edge Graphql Query Variables ------::Start::------ #--- To use below Sitecore Edge Graphql Query Variables you have to uncomment # and place in the QUERY VARIABLES section # { # "pageSize": 30, # "language": "en", # "rootpath": "{1F4B781B-F2A5-5647-99DF-C0C369162C4D}" # } #--- Sitecore Edge Graphql Query Variables ------::End::------
In the above search query, i am using fields attribute to get the list of FIELDS from Search Result Item. With this you can find list of available fields.
- Sitecore Edge GraphQL Search – Parameter details
#3. Sitecore Edge GraphQL Search - Apply filter not to return items from specific path # To filter not to return child items from particular path we can use # NCONTAINS operator # If we want to exclude items under specific locations, e.g., need to hide items which are present under /sitecore/content/EdgeWebsite/home/speakers/Page Components: # GUID of /sitecore/content/EdgeWebsite/home/speakers/Page Components {81347F0C-A6F8-4A09-8D0A-0600485D5894} # It will not return records under the /Page Components query SearchQuery ( $pageSize: Int = 10 $language: String = "" $rootpath: String = "" ) { pageOne: search( where: { AND: [ { name: "_path" value:$rootpath operator: CONTAINS } { name: "_path" value: "{81347F0C-A6F8-4A09-8D0A-0600485D5894}" operator: NCONTAINS } { name: "_language" value: $language } ] } # defaults to 10 first: $pageSize ) { total pageInfo { endCursor hasNext } results { id path fields{name __typename } } } } #--- Sitecore Edge Graphql Query Variables ------::Start::------ #--- To use below Sitecore Edge Graphql Query Variables you have to uncomment # and place in the QUERY VARIABLES section # { # "pageSize": 10, # "language": "en", # "rootpath": "{1F4B781B-F2A5-5647-99DF-C0C369162C4D}" # } #--- Sitecore Edge Graphql Query Variables ------::End::------
In the above search query, we are having following parameters:
total: represent total number of records
first: this repsresent the page size of the search results and you can change as per your need
endCursor: Contains the encoded value of the cursor pointing to the last hit of a page
hasNext: this represents that next page present or not
Here total records are 21 and page size is 10 so total number of pages would be 3. If i will set the page size as 30 then hasNext should come as false, it means only ONE page.
- Sitecore Edge GraphQL Search - Hide items based on specific template
#4. Sitecore Edge GraphQL Search - Hide items based on specific template query SearchQuery ( $pageSize: Int = 10 $language: String = "" $rootpath: String = "" ) { pageOne: search( where: { AND: [ { name: "_path" value:$rootpath operator: CONTAINS } { name: "_path" value: "{81347F0C-A6F8-4A09-8D0A-0600485D5894}" operator: NCONTAINS } { # Item based on Folder template, e.g., Page Components name: "_templates" value: "{A87A00B1-E6DB-45AB-8B54-636FEC3B5523}" operator: NCONTAINS } { name: "_language" value: $language } ] } # defaults to 10 first: $pageSize ) { total pageInfo { endCursor hasNext } results { id path fields{name __typename } } } } #--- Sitecore Edge Graphql Query Variables ------::Start::------ #--- To use below Sitecore Edge Graphql Query Variables you have to uncomment # and place in the QUERY VARIABLES section # { # "pageSize": 30, # "language": "en", # "rootpath": "{1F4B781B-F2A5-5647-99DF-C0C369162C4D}" # } #--- Sitecore Edge Graphql Query Variables ------::End::------
- Sitecore Edge GraphQL Search – Order By Field and Order by Direction
#5. Sitecore Edge GraphQL Search – Order By Field and Order by Direction query SearchQuery ( $pageSize: Int = 10 $language: String = "" $rootpath: String = "" $orderByField: String! $orderDirection: OrderByDirection = ASC ) { pageOne: search( where: { AND: [ { name: "_path" value:$rootpath operator: CONTAINS } { name: "_path" value: "{81347F0C-A6F8-4A09-8D0A-0600485D5894}" operator: NCONTAINS } { # Item based on Folder template, e.g., Page Components name: "_templates" value: "{A87A00B1-E6DB-45AB-8B54-636FEC3B5523}" operator: NCONTAINS } { name: "_language" value: $language } ] } # defaults to 10 first: $pageSize orderBy: { name: $orderByField, direction: $orderDirection } ) { total pageInfo { endCursor hasNext } results { path ... on Speaker { jobTitle {value} } } } } #--- Sitecore Edge Graphql Query Variables ------::Start::------ # Root path is /sitecore/content/EdgeWebsite/home/speakers #--- To use below Sitecore Edge Graphql Query Variables you have to uncomment # and place in the QUERY VARIABLES section # { # "pageSize": 30, # "language": "en", # "rootpath": "{1F4B781B-F2A5-5647-99DF-C0C369162C4D}" # "orderByField": "JobTitle", # "orderDirection": "ASC" # } #--- Sitecore Edge Graphql Query Variables ------::End::------
- Sitecore Edge GraphQL Search – AND / OR Condition (ItemSearchPredicateInput) Usage
#6. Sitecore Edge GraphQL Search – AND / OR Condition (ItemSearchPredicateInput) Usage # You can add AND / OR clause to search query with different field names # if you are using the CONTAINS clause then it will search the keyword in field content and return the results, and keyword case (UPPER or LOWER case) wouldn't affect the search results query SearchQuery ( $pageSize: Int = 10 $language: String = "" $rootpath: String = "" $orderByField: String! $orderDirection: OrderByDirection = ASC $searchKeyword: String = "" $valueAfter: String = "" ) { pageOne: search( where: { AND: [ { name: "_path" value:$rootpath operator: CONTAINS } { name: "_path" value: "{81347F0C-A6F8-4A09-8D0A-0600485D5894}" operator: NCONTAINS } { # Item based on Folder template, e.g., Page Components name: "_templates" value: "{A87A00B1-E6DB-45AB-8B54-636FEC3B5523}" operator: NCONTAINS } { name: "_language" value: $language } { OR: [ { name: "JobTitle" value: $searchKeyword operator: CONTAINS } { name: "pageTitle" value: $searchKeyword operator: CONTAINS } { name: "Description" value: $searchKeyword operator: CONTAINS } ] } ] } # defaults to 10 first: $pageSize after:$valueAfter orderBy: { name: $orderByField, direction: $orderDirection } ) { total pageInfo { endCursor hasNext } results { path ... on Speaker { jobTitle {value} pageTitle{value} description{value} } } } } #--- Sitecore Edge Graphql Query Variables ------::Start::------ # Root path is /sitecore/content/EdgeWebsite/home/speakers #--- To use below Sitecore Edge Graphql Query Variables you have to uncomment # and place in the QUERY VARIABLES section # { # "searchKeyword": "alex", # "pageSize": 30, # "language": "en", # "rootpath": "{1F4B781B-F2A5-5647-99DF-C0C369162C4D}" # "orderByField": "JobTitle", # "orderDirection": "ASC", # "valueAfter": "" # } #--- Sitecore Edge Graphql Query Variables ------::End::------
- Sitecore Edge GraphQL Search – Pagination and first/after parameters
#7. Sitecore Edge GraphQL Search – Pagination and first/after parameters # For pagination we need to use the parameter 'after' and we need to pass the value returned in "'pageInfo/endCursor'". #At FE app we can use "'pageInfo/hasNext'" to validate that next page present or not. #When you are executing initial request then 'after' parameter value would be empty and if query returned more than one page then we have to use the exact value returned in 'pageInfo/endCursor'" in 'after' parameter query SearchQuery ( $pageSize: Int = 10 $language: String = "" $rootpath: String = "" $orderByField: String! $orderDirection: OrderByDirection = ASC $searchKeyword: String = "" $valueAfter: String = "" ) { pageOne: search( where: { AND: [ { name: "_path" value:$rootpath operator: CONTAINS } { name: "_path" value: "{81347F0C-A6F8-4A09-8D0A-0600485D5894}" operator: NCONTAINS } { # Item based on Folder template, e.g., Page Components name: "_templates" value: "{A87A00B1-E6DB-45AB-8B54-636FEC3B5523}" operator: NCONTAINS } { name: "_language" value: $language } { OR: [ { name: "JobTitle" value: $searchKeyword operator: CONTAINS } { name: "pageTitle" value: $searchKeyword operator: CONTAINS } { name: "Description" value: $searchKeyword operator: CONTAINS } ] } ] } # defaults to 10 first: $pageSize after:$valueAfter orderBy: { name: $orderByField, direction: $orderDirection } ) { total pageInfo { endCursor hasNext } results { path ... on Speaker { jobTitle {value} pageTitle{value} description{value} } } } } #--- Sitecore Edge Graphql Query Variables ------::Start::------ # Root path is /sitecore/content/EdgeWebsite/home/speakers #--- To use below Sitecore Edge Graphql Query Variables you have to uncomment # and place in the QUERY VARIABLES section # { # "searchKeyword": "alex", # "pageSize": 30, # "language": "en", # "rootpath": "{1F4B781B-F2A5-5647-99DF-C0C369162C4D}" # "orderByField": "JobTitle", # "orderDirection": "ASC", # "valueAfter": "" # } #--- Sitecore Edge Graphql Query Variables ------::End::------
For pagination we need to use the parameter 'after' and we need to pass the value returned in 'pageInfo/endCursor'.
At FE app we can use 'pageInfo/hasNext' to validate that next page present or not.
When you are executing initial request then 'after' parameter value would be empty and if query returned more than one page then we have to use the exact value returned in 'pageInfo/endCursor' in 'after' parameter.
In the above query, i am trying to access the Page TWO content by passing the value of 'pageInfo/endCursor' received from INITIAL search request to 'after'.
Now, if i will try to use the value of 'pageInfo/endCursor' received from above search results to 'after' parameter then i will get the EMPTY results: - Sitecore Edge GraphQL Search – Get all field name of the search result item
#8. Sitecore Edge GraphQL Search – Get all field name of the search result item query SearchQuery ( $pageSize: Int = 10 $language: String = "" $rootpath: String = "" $orderByField: String! $orderDirection: OrderByDirection = ASC $searchKeyword: String = "" $valueAfter: String = "" ) { pageOne: search( where: { AND: [ { name: "_path" value:$rootpath operator: CONTAINS } { name: "_path" value: "{81347F0C-A6F8-4A09-8D0A-0600485D5894}" operator: NCONTAINS } { # Item based on Folder template, e.g., Page Components name: "_templates" value: "{A87A00B1-E6DB-45AB-8B54-636FEC3B5523}" operator: NCONTAINS } { name: "_language" value: $language } { OR: [ { name: "JobTitle" value: $searchKeyword operator: CONTAINS } { name: "pageTitle" value: $searchKeyword operator: CONTAINS } { name: "Description" value: $searchKeyword operator: CONTAINS } ] } ] } # defaults to 10 first: $pageSize after:$valueAfter orderBy: { name: $orderByField, direction: $orderDirection } ) { total pageInfo { endCursor hasNext } results { template { id name } id name path ... SearchResultsItems } } } fragment SearchResultsItems on Item { fields { name value } } #--- Sitecore Edge Graphql Query Variables ------::Start::------ # Root path is /sitecore/content/EdgeWebsite/home/speakers #--- To use below Sitecore Edge Graphql Query Variables you have to uncomment # and place in the QUERY VARIABLES section # { # "searchKeyword": "alex", # "pageSize": 30, # "language": "en", # "rootpath": "{1F4B781B-F2A5-5647-99DF-C0C369162C4D}" # "orderByField": "JobTitle", # "orderDirection": "ASC", # "valueAfter": "" # } #--- Sitecore Edge Graphql Query Variables ------::End::------
When you start writing the Sitecore Edge GraphQL Search Queries, you would not be aware about the name of the fields which you have to use, because you wouldn't be having access to Search Engine provider.
In this case, the starting should be to get the list of all fields of all templates which you are going to use in your search queries.
- Sitecore Edge GraphQL Search – Return a specific field with Alias
#9. Sitecore Edge GraphQL Search – Return a specific field with Alias # You can provide user friendly name or alias to the field name as per your requirement. query SearchQuery ( $pageSize: Int = 10 $language: String = "" $rootpath: String = "" $orderByField: String! $orderDirection: OrderByDirection = ASC $searchKeyword: String = "" $valueAfter: String = "" ) { pageOne: search( where: { AND: [ { name: "_path" value:$rootpath operator: CONTAINS } { name: "_path" value: "{81347F0C-A6F8-4A09-8D0A-0600485D5894}" operator: NCONTAINS } { # Item based on Folder template, e.g., Page Components name: "_templates" value: "{A87A00B1-E6DB-45AB-8B54-636FEC3B5523}" operator: NCONTAINS } { name: "_language" value: $language } { OR: [ { name: "JobTitle" value: $searchKeyword operator: CONTAINS } { name: "pageTitle" value: $searchKeyword operator: CONTAINS } { name: "Description" value: $searchKeyword operator: CONTAINS } ] } ] } # defaults to 10 first: $pageSize after:$valueAfter orderBy: { name: $orderByField, direction: $orderDirection } ) { total pageInfo { endCursor hasNext } results { template { id name } id name path ... SearchResultsItems } } } fragment SearchResultsItems on Item { JobTitle: field(name : "JobTitle") { value } fields { name value } } #--- Sitecore Edge Graphql Query Variables ------::Start::------ # Root path is /sitecore/content/EdgeWebsite/home/speakers #--- To use below Sitecore Edge Graphql Query Variables you have to uncomment # and place in the QUERY VARIABLES section # { # "searchKeyword": "alex", # "pageSize": 30, # "language": "en", # "rootpath": "{1F4B781B-F2A5-5647-99DF-C0C369162C4D}" # "orderByField": "JobTitle", # "orderDirection": "ASC", # "valueAfter": "" # } #--- Sitecore Edge Graphql Query Variables ------::End::------
- Sitecore Experience Manager (XM) Edge Preview API Key
The API key for Sitecore CMS Present at /sitecore/system/Settings/Services/API Keys/ location, and if not present then you can create new API Key (using template /sitecore/templates/System/Services/API Key): - Sitecore Edge GraphQL Preview Request-Credentials
If you are accessing the Sitecore Edge GraphQL IDE on Sitecore XP (SXP) then sometimes you will received Authentication failed related errors then you have to update the Request Credentials setting from omit to same-origin in IDE: - Sitecore Edge GraphQL IDE HTTP Headers
If you are accessing the Sitecore Edge GraphQL IDE the you have to pass the API key to the HTTP header of API request, and you can directly set the API key in IDE: - Sitecore Experience Platform (SXP) Edge GraphQL API Key
The API key for SXP Present at /sitecore/system/Settings/Services/API Keys/ location, and if not present then you can create new API Key (using template /sitecore/templates/System/Services/API Key): You have to publish this API Key before using it. - Sitecore Demo Portal Edge GraphQL API Key
You can find API key for Sitecore Demo Portal at instance details section: - Sitecore XM Cloud Edge GraphQL Delivery API Key
To access the Sitecore XM Cloud Delivery API, you have to generate the API key for XM Cloud, and for this first you have to request a JWT for Experience Edge XM using OAuth:
Request an access token for the Experience Edge APIs by using a POST request
For example, request the JWT using the curl client:curl --request POST --url "https://auth.sitecorecloud.io/oauth/token" --header "content-type: application/x-www-form-urlencoded" --data grant_type=client_credentials --data client_id=<clientid> --data client_secret=<clientsecret> --data audience=https://api.sitecorecloud.io
In this you have the pass the end-point as https://auth.sitecorecloud.io/oauth/token instead of https://one-sc-production.eu.auth0.com/oauth/token, and audience url as https://api.sitecorecloud.io instead of https://delivery.sitecore.cloud/[tenant-id].
Currently, the url mentioned at Sitecore official documentation Request a JWT for Experience Edge XM using OAuth are incorrect, and team is working on to correct these urls.
For example, request the JWT using the POSTMAN client: You can generate client id and client secret for your Sitecore XM Cloud instance by following the steps present at Generate an Edge administration client for an XM Cloud environment.
After getting the JWT token you can follow the steps at Create the API key to generate the Sitecore XM Cloud Delivery API Key and you can check sample postman request details to generate the Sitecore XM Cloud Delivery API Key:
- Get link
- X
- Other Apps
Comments