0

I'm encountering a CORS issue when making requests to the Preview GraphQL IDE. Despite setting the sc_apikey in the header, I'm still facing problems. The error message I receive is:

Access to fetch at 'https://xmc-*********-test.sitecorecloud.io/sitecore/api/graph/edge' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Additionally, I'm getting a 400 (Bad Request) error when making a POST request to https://xmc-***********-test.sitecorecloud.io/sitecore/api/graph/edge

Interestingly, I can access the IDE playground directly via URL and successfully make GraphQL queries within the playground. However, I'm unable to replicate this success on my localhost.

I've attempted to use https://xmcloudcm.localhost/sitecore/api/graph/edge and https://edge.sitecorecloud.io/api/graphql/ide, but neither of these has resolved the issue.

Currently I'm using NextJS+React with @apollo/client Any advice or guidance on this matter would be greatly appreciated.

2 Answers 2

0

You need to set correctly the URL and the ApiKey parameters to run against the local instance of XM Cloud.

the 3 important things we have to set up are:

In the image above, the 3 important things we have to set up are:

  1. The URL to launch the Playground IDE locally:

    https://xmcloudcm.localhost/sitecore/api/authoring/graphql/ide/

  2. The local endpoint to reach GraphQL API:

    https://xmcloudcm.localhost/sitecore/api/graph/edge

  3. The ApiKey: The ApiKey is the ID value of the Sitecore item of our local XM located in /sitecore/system/Settings/Services/API Keys/xmcloudpreview

enter image description here

It has to match the value of the variable of our .env file in the NextJs solution:

enter image description here

Hope it helps!

Credit: How to work with GraphQL in your local environment

0

While working with docker, make sure that you have enabled these two settings in your .env file.

SITECORE_GRAPHQL_ENABLED=true
SITECORE_GRAPHQL_EXPOSEPLAYGROUND=true

When you enable these settings, you will be able to access the graphQL playground.

Hope this 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.