1

I am trying to work with Graph QL Endpoint "/sitecore/api/graph/items/master" in my next js app. But I am receiving error as "Cannot query field "layout" on type "Query" on one of the default queries executed by Next Js app when it starts

query {
      layout(site:"your-site", routePath:"/page", language:"en"){
        item {
          rendered
        }
      }
    }

I noticed that schema provider for api/items/master endpoint is

<schema hint="list:AddSchemaProvider">
                            <!-- defaults are defined in Sitecore.Services.GraphQL.Content.config -->
                            <content ref="/sitecore/api/GraphQL/defaults/content/schemaProviders/systemContent" param1="master" />
                        </schema>

But when I point to Edge Content I am not receiving the error and I am able to get the JSON Output -- <content ref="/sitecore/api/GraphQL/defaults/content/schemaProviders/edgeContent" param1="master" />

enter image description here

I am able to narrow down to the issue to systemContent but any help on this at the earliest would be highly appreciated.

2
  • Can you share your site configuration? It’s possible that the hostname you are querying doesn’t match up with the database that the schema provider is configured against. Commented Jun 2 at 16:11
  • Also, what version of Sitecore and Headless services are you using? Commented Jun 2 at 16:12

1 Answer 1

2

When you create a custom graphql endpoint you can refer schema provider to one of the following.

  1. Edge Content -> This is used for fetching item and layout related data. Example of query operations supported in this provider can be found below:

https://doc.sitecore.com/xp/en/developers/101/developer-tools/query-examples.html#get-items-filtered-by-multiple-paths

  1. System Content: This is mainly used to perform authoring operation such as creating/deleting an item. Example of query operations supported in this provider can be found below:

https://doc.sitecore.com/xp/en/developers/103/sitecore-experience-manager/query-examples-for-authoring-operations.html#search-items-under-a-specific-path

Moreover, you can find the schema of the query operations supported in the provider by clicking on the docs section, it will enlist all the query supported. In the below example, all queries supported for 'System Content' provider are enlisted on the right hand side section.

enter image description here

In your case since you are trying to running layout query, it will be supported in Edge Content schema.

When you are trying to search content with the field values on Edge content, you can run the GraphQL query as below:

query{
  search(
    where: {
      AND: [
        { name: "Title", value: "Test" , operator: EQ}
      ]
    }
    first: 10
  ) {
    total
    pageInfo {
       endCursor
       hasNext
    }
    results {
      id
      name
    }
  }

This will return all the items containing 'Test' in the title field as below:

enter image description here

Hope this helps!!!

2
  • Thanks for your answer. But when we use edge schema we cannot use filter parameters in our search . I am pasting the link at last of the comment of my previous question in stack. Any suggestions on how to overcome that limitation if we use edge schema ?? sitecore.stackexchange.com/questions/37093/…
    – Sylesh JL
    Commented Jun 2 at 19:15
  • @SyleshJL I have updated the answer above containing GraphQL query required to search over field values over Edge schema. Hope this helps!
    – ckhanna
    Commented Jun 2 at 19:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.