Exponential 6.0.15 has a GraphQL API in the kernel, at /api/graphql per siteaccess. It is off until you switch it on, and it needs the webonyx/graphql-php library, version 15. This guide takes a site from "switched off" to a front end reading its content.
1. Check that it can run
./console exp:graphql:status --siteaccess=site
The last line says PASS the GraphQL API can run (switched off here) when the library is installed and the schema builds from your content classes. A FAIL names what is missing.
2. See what switching on changes
./console exp:graphql:enable --siteaccess=site --origin=http://localhost:3000 --key-for=frontend
Without --apply nothing is written; the command prints the settings it would change. The user named by --key-for decides what the front end can read: give it a role that allows content/read on what the site shows, and nothing more. For a public site the anonymous user is enough; then leave --key-for out. --origin is only needed when a browser calls the API directly.
3. Switch it on
Run the same command with --apply. The API key is shown once and stored only as a hash, so copy it now. Every settings file is backed up first, the change is recorded in the audit log, and the INI cache is cleared.
4. Ask the first question
curl -s https://www.example.com/api/graphql \
-H "Authorization: Bearer $EXP_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"query": "{ currentUser { login signedInBy } }"}'
Setup > GraphQL in the administration shows the end point, the schema, the keys and a playground that runs queries with your own rights.
5. Generate a front end
./console exp:graphql:starter --list ./console exp:graphql:starter --kit=next --siteaccess=site --to=../shop-front --apply
Kits: html (a page without a build step), next, nuxt, astro and expo, with queries generated from the live schema.
6. Store the queries on the server
./console exp:graphql:persist ../shop-front/graphql/ --siteaccess=site --apply
A persisted query is called by name, cannot be changed by the caller, and is the only kind the response cache keeps. Publishing content expires the cache.
Before going live
- AllowedOrigins[] lists the production address, not localhost.
- The key's user reads only what the site shows. Never put a key with graphql:write into a browser or an app others install.
- PersistedQueriesOnly=anonymous once the front end sends only stored queries.
- The rate limits fit the expected traffic; Debug=disabled on the production siteaccess.
- A siteaccess where nothing writes has its mutations off: exp:graphql:disable --siteaccess=<name> --mutations --apply.