1

I am using Sitecore 10.3 SXA Headless and using NextJS Page Router for my Front-end. Basically, I want to create an item by using graphQL mutation method. I have followed this stackexchange issue and also added this below shown configuration as mentioned in the answer,

<configuration>
  <sitecore>
    <pipelines>
      <owin.cookieAuthentication.validateIdentity>
        <processor type="Sitecore.Owin.Authentication.Pipelines.CookieAuthentication.ValidateIdentity.ValidateSiteNeutralPaths, Sitecore.Owin.Authentication">
          <siteNeutralPaths hint="list">
             <path hint="graphql">/sitecore/api/graph/items/</path>
          </siteNeutralPaths>
        </processor>
      </owin.cookieAuthentication.validateIdentity>
    </pipelines>
  </sitecore>
</configuration>

I have created templates and fields as required and added the GraphQL query as mentioned,

mutation CreateItem {
  createItem(
    name: "ExampleItem"
    template: "{1706CEB1-318A-4D71-A1B8-6FCCEA238762}"
    parent: "{27ACB186-4F20-44E8-BD94-8C1C73F97529}"
    language: "en"
    fields: [
      { name: "Title", value: "'Example Item'" }
      { name: "Text", value: "'This is an example item created with GraphQL'" }
    ]
  ) {
    path
  }
}

but still I am facing some issue in the GraphQL Edge Playground, which says...

{
  "errors": [
    {
      "message": "GraphQL.ExecutionError: Schema is not configured for mutations ---> GraphQL.ExecutionError: Schema is not configured for mutations\r\n   at GraphQL.Execution.ExecutionHelper.GetOperationRootType(Document document, ISchema schema, Operation operation)\r\n   at GraphQL.Execution.ExecutionStrategy.<ExecuteAsync>d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n   at GraphQL.DocumentExecuter.<ExecuteAsync>d__8.MoveNext()\r\n   --- End of inner exception stack trace ---",
      "extensions": {
        "code": "EXECUTION_ERROR"
      }
    }
  ]
}

Btw, I am a newbie in Sitecore and JSS, thanks 🙂

2
  • Can you share the query that you used to create item? Aug 9, 2023 at 14:43
  • Yes, I have shared the query in the question. @SumitBhatia
    – hrupapara
    Aug 9, 2023 at 15:07

2 Answers 2

1

To solve this error, you should do the following.

  • Check if you have enabled Sitecore.Services.GraphQL.Content.Master.config and deploy it to the Sitecore instance.

  • Now access with https://<your-sitecore-instance>/sitecore/api/graph/items/master

  • Finally check with your create item query and see if it should work.

Hope this helps.

2

The potential issue is with configuration and setup only. Few pointers that you can verify and try out to troubleshoot.

  1. Ensure layout service is working fine or not using this URL: https://your.sitecore.domain/sitecore/api/layout/render?item=/&sc_apikey={API-Key}

  2. Ensure authentication success while accessing the endpoint: https://your.sitecore.domain/sitecore/api/graph/items/master

  3. Try to access GraphQL GUI with – https://your.sitecore.domain/sitecore/api/graph/items/master/ui and try a simple query and see if it works fine or not.

    enter image description here

if you are able to get the result then your setup is working fine. The next step is to try mutation.

Create item mutation. Ensure field names are properly as defined in the template

mutation CreateItem {
  createItem(
    id:"22328777-1473-458e-915f-41ef13a44fe2"
    name: "Blog-1"
    template: "{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}"
    parent: "{0DE95AE4-41AB-4D01-9EB0-67441B7C2450}"
    language: "en"
    fields: [
      { name: "title", value: "'My Test Item'" }
      { name: "text", value: "'This is Test Item created with GraphQL CreateItem Mutaion'" }
    ]
  ) {
    path
  }
}

Refer to the below links for more details.

  1. Setup GraphQL for Sitecore 10.3 with NextJs, JSS, Sitecore Container
  2. How to use GraphQL Queries / Mutations / Subscriptions with Sitecore 10.3 Part 1
  3. How to use GraphQL Queries / Mutations with Sitecore 10.3 Part 2

Hope it helps!

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.