Add @graphiql/cdn package#4312
Open
trevor-scheer wants to merge 1 commit into
Open
Conversation
🦋 Changeset detectedLatest commit: 58fc180 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
1627bc2 to
d955761
Compare
A self-contained, pre-bundled ESM distribution of GraphiQL for browser CDN consumption. One `.js` file, one `.css` file, with `react`, `react-dom`, and `graphql` as the only externals (peer deps). Monaco editor and workers are inlined into the bundle, so loading the file from any static CDN onto any origin gives a working GraphiQL with no build step on the consumer side. Replaces the previous esm.sh `?standalone` approach for CDN consumers. See graphql#4303 for the underlying esm.sh regression that motivated owning the bundle.
d955761 to
58fc180
Compare
Contributor
Author
|
@dimaMachina FYI this was a pretty Claude-heavy investigation + PR but I'm pretty happy with the direction and I've reviewed it and iterated quite a bit already. Would love to get your take on the approach. This is solving a real problem with our example usage of esm.sh as it is today. |
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
@graphiql/cdnis a new package that ships GraphiQL as a self-contained, pre-bundled file for browser CDN consumption. One ESM file, one CSS file,react/react-dom/graphqlas the only externals (peer deps). Drop it into a<script type="module">on any page and you have a working GraphiQL.Motivation
The current CDN story (
examples/graphiql-cdn/index.html) relies on esm.sh's?standalonemode to assemble the bundle on demand from our npm-published packages. In late April, an esm.sh change to how it handles small re-export modules started fragmentingmonaco-editorinto two runtime instances. The result isCannot set tokens provider for unknown language jsonand dead syntax highlighting + autocomplete for every CDN consumer (#4303).esm.sh caches each version's build immutably, so the regression is sticky for
@graphiql/react@0.37.4+, and the fix has to come from either esm.sh or from us moving off?standalone. Iterating on package.json shape to coax esm.sh's builder into a working output didn't pan out, and even if it had, the next esm.sh internal change could break us the same way.Owning the bundle means:
esm.sh/pr/.../?rawserves the bundle untransformed. No publish-to-test cycle.What's in the package
dist/graphiql.js— single self-contained ESM bundle, ~11 MB raw, ~2 MB gzipped. Inlinesgraphiql,@graphiql/react, the explorer and history plugins,@graphiql/toolkit, and the monaco workers (as blob URLs, so there are no separate worker fetches and no cross-origin worker constraints).dist/style.css— bundled stylesheet (graphiql + explorer styles).react,react-dom,graphql.Usage
Per-asset SRI hashes are exact-content hashes — compute them once after pinning a version:
curl -sL <url> | openssl dgst -sha384 -binary | openssl base64 -A.Test plan
How to test this out
Save the snippet below as
cdn-pr-4312.htmland open it in a browser (no server needed — every URL is absolute). It pins to commit58fc180of this PR with real SRI hashes. Type in the operation editor to verify syntax highlighting and autocompletion against thecountries.trevorblades.comendpoint.import { GraphiQL } from '@graphiql/cdn'still resolves and the component mounts. The package ships normal ESM; bundlers treat it like any other dep.Follow-ups (not in this PR)
examples/graphiql-cdn/index.htmlto consume@graphiql/cdn.dist/index.umd.jsand deletepackages/graphiql/src/cdn.ts+ its UMD vite config.