Skip to content

fix(graphiql): migrate to v5 via esm.sh CDN#8209

Merged
soyuka merged 2 commits into
api-platform:4.3from
soyuka:feat/graphiql-v5-esm
May 29, 2026
Merged

fix(graphiql): migrate to v5 via esm.sh CDN#8209
soyuka merged 2 commits into
api-platform:4.3from
soyuka:feat/graphiql-v5-esm

Conversation

@soyuka
Copy link
Copy Markdown
Member

@soyuka soyuka commented May 29, 2026

Summary

  • GraphiQL 5 and React 19 both removed UMD bundles; the old <script src=…/graphiql.min.js> pattern no longer works
  • Move to browser-native ESM via <script type="importmap"> pointing at esm.sh, mirroring the upstream graphiql-cdn example
  • Drop bundled react/, graphiql/, es6-promise/, fetch/ public assets (no longer needed)
  • update-js.sh now only ships @fontsource/open-sans, swagger-ui and redoc (the ones that still distribute usable single-file bundles)

Pins match upstream's graphiql-cdn example exactly:

  • graphiql@5.2.2, @graphiql/react@0.37.3, @graphiql/toolkit@0.11.3
  • react@19.2.5, react-dom@19.2.5, graphql@16.13.2

Newer combos (graphiql 5.2.3 + @graphiql/react 0.37.5 + react 19.2.6) trigger a Cannot set tokens provider for unknown language json module-load-order regression on esm.sh; staying on the pins the upstream example actually ships with.

Trade-off

The GraphiQL page now needs network access to esm.sh at runtime. There is no local bundler (no esbuild/rollup) in the repo. This matches what the GraphiQL team officially recommends for v5 in their README and the graphiql-cdn example. If a fully self-hosted bundle is needed later, that's a separate change requiring a bundler.

URL state

?query=…&variables=…&operationName=… is honored on first render, and editing the active tab writes the latest values back to the URL via onTabChange (v5 dropped the per-editor onEdit* props, so the sync goes through the tab-state callback instead).

Test plan

  • update-js.sh runs clean (no missing files)
  • Symfony dev server (symfony server:start --dir tests/Fixtures/app/) → https://127.0.0.1:8000/graphql/graphiql renders without console errors after a localStorage clear
  • Monaco editor renders with full "# Welcome to GraphiQL" default query and syntax highlighting
  • Doc Explorer / History / Refetch schema / Settings / Shortcuts buttons present
  • /graphql introspection POST returns the schema
  • Initial ?query=…&variables=… honored on load, edits sync back to URL bar
  • Laravel side: blade template changes mirrored from twig, not exercised on a live Laravel app in this PR — needs a reviewer with Laravel setup to confirm

soyuka added 2 commits May 29, 2026 11:50
GraphiQL 5 + React 19 dropped UMD bundles. Move to browser-native
ESM via importmap pointing at esm.sh, mirroring the upstream
`graphiql-cdn` example.

- update-js.sh: stop bundling graphiql/react/polyfills, only ship
  fonts + swagger-ui + redoc
- Graphiql twig + blade: importmap + type=module loader
- init-graphiql.js (Symfony + Laravel): ESM rewrite with
  createGraphiQLFetcher, createRoot, setup-workers/esm.sh
- remove tracked public/{es6-promise,fetch,graphiql,react}/

Live URL sync on edit is regressed; init from URL still works.
Follow-up restores it via store subscription.
Restore the pre-v5 behavior where editing the query, variables or
operation name updates the URL bar. v5 dropped `onEditQuery` /
`onEditVariables` props but exposes `onTabChange(tabState)`, which
fires on any active-tab content edit and carries the latest query,
variables, headers and operationName.

Reads from URL on first render already worked; only the live write-
back was missing.
@soyuka soyuka changed the title feat(graphiql): migrate to v5 via esm.sh CDN fix(graphiql): migrate to v5 via esm.sh CDN May 29, 2026
@soyuka soyuka merged commit ef40bcd into api-platform:4.3 May 29, 2026
107 of 120 checks passed
@soyuka soyuka deleted the feat/graphiql-v5-esm branch May 29, 2026 14:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant