Switch between REST and GraphQL in Next.js JSS apps
JSS Next.js applications can use either the Sitecore Layout Service REST API or the Sitecore GraphQL Edge schema to fetch layout and dictionary data.
You can change the data-fetching method after project creation by replacing the JSS services used by the application to interact with Sitecore APIs. Specifically, you need to change between REST and GraphQL services provided by the JSS Layout API and the JSS GraphQL API.
Switch from REST to GraphQL services
To switch the Next.js sample application from REST to GraphQL:
-
Move or delete
<src>/lib/dictionary-service-factory.ts
and<src>/lib/layout-service-factory.ts
. -
Download
dictionary-service-factory.ts
andlayout-service-factory.ts
to<src>/lib/
.
Switch from GraphQL to REST services
To switch the Next.js sample application from GraphQL to REST:
-
Move or delete
<src>/lib/dictionary-service-factory.ts
and<src>/lib/layout-service-factory.ts
. -
Download
dictionary-service-factory.rest.ts
andlayout-service-factory.rest.ts
to<src>/lib/
. -
Rename as
dictionary-service-factory.ts
andlayout-service-factory.ts
respectively.