Meet us at Sitecore Symposium 2024 and Discover New Ways to Enhance Your Dynamics Experience. Book a Meeting

Let’s Talk

We would love to hear from you. Want to know more about
our services or have any questions? Say Hi!

How to create new GraphQL endpoint with custom schema in Sitecore JSS?

April 03, 2023
How to create new GraphQL endpoint with custom schema in Sitecore JSS?
Keyur Garala
Keyur Garala
Sitecore Certified Solutions Architect
how-to-create-new-graphql-endpoint-with-custom-schema-in-sitecore-jss

Through this blog, you will understand how to set up and use the Sitecore GraphQL API. You get the GraphQL API by installing the JSS server components package. In the Sitecore Headless Service 16.0 and later versions, the Edge Preview endpoint is kept enabled by default but you can also configure additional endpoints. Follow the below steps for that.

  1. Define one endpoint at least for using the Graph QL API.
  2. The below example defines a content API endpoint with the necessary authentication.
how-to-create-new-graphql-endpoint-with-custom-schema-in-sitecore-jss-1

After that, you initialize the hosting class as it is described below:

how-to-create-new-graphql-endpoint-with-custom-schema-in-sitecore-jss-2

After that is done, we have to create the schema class based on SchemaProviderbase. We also have to inherit the SchemaProvideBase class and create a new class as per the requirements.

how-to-create-new-graphql-endpoint-with-custom-schema-in-sitecore-jss-3 how-to-create-new-graphql-endpoint-with-custom-schema-in-sitecore-jss-4

In the above given method (Find blog) we write our own custom logic.

My class ISCQuery that is required is in the below model but you can create the model as per your requirements.

how-to-create-new-graphql-endpoint-with-custom-schema-in-sitecore-jss-5

After this, we are all set for using the new GraphQL endpoint with the custom schema as per the requirements.

To get access to the new GraphQL enpoint, please type (https://domain+your_new_endpoint_url+/ui)

In our case, it is (https://domain+/api/graph/isc/ui)

After this, enter the sc_apikey in the https header and you will be able to see the window given below

how-to-create-new-graphql-endpoint-with-custom-schema-in-sitecore-jss-6

On the left side of your editor, you can write queries also for example:

how-to-create-new-graphql-endpoint-with-custom-schema-in-sitecore-jss-7

This is how we can create a new GraphQL endpoint usisng the query in Sitecore JSS.


YOU MAY ALSO LIKE