Skip to content

feat(docs): add GitHub GraphQL playground page - #86

Merged
vito merged 2 commits into
mainfrom
docs-github-playground
Jun 4, 2026
Merged

vito merged 2 commits into
mainfrom
docs-github-playground

Conversation

@vito

@vito vito commented Jun 4, 2026

Copy link
Copy Markdown
Owner

What

Adds a GraphQL + Dang playground docs page (/github-playground) that builds
on the existing client-side WASM playground. Readers sign in with GitHub, then
run snippets that import GitHub against the live GitHub GraphQL API — types,
viewer, etc. all resolve from the real schema.

Follows up on docs feedback in Discord asking whether this was possible "in the
current scheme (statically deployed + Cloudflare Functions)." It is — confirmed
GitHub's GraphQL endpoint sends permissive CORS (access-control-allow-origin: *,
allowing Authorization/Content-Type), so introspection and queries run
straight from the browser with no proxy.

How it fits the static + CF Functions model

  • Client-side everything except the secret. Introspection and queries are
    ordinary cross-origin fetches from the WASM module to api.github.com.
  • Two tiny CF Pages Functions own the only thing a static site can't hold —
    the OAuth client secret:
    • GET /github/login → redirect to GitHub authorize (sets a SameSite=Lax,
      HttpOnly CSRF-state cookie carrying the return path).
    • GET /github/callback → verify state, exchange code for a token, bounce
      back to the page with the token in the URL fragment.
  • playground.js captures #gh_token=… into sessionStorage and strips it.
    The token lives only in the tab session and is never stored server-side.

Runtime changes

  • dangEval(source, token) now returns a Promise — the single-threaded wasm
    event loop can't block on the network from a synchronous js.Func. With a
    token it wires a GitHub ImportConfig into the eval context (schema
    introspected once, then cached for the page lifetime); without one, behavior
    is unchanged.
  • New \dang-github-playground booklit tag → a block marked data-dang-github,
    which playground.js enhances with a sign-in/out control.

Operator setup required before sign-in works

Mirrors the feedback webhook setup. Register a GitHub OAuth app with callback
URL <site>/github/callback and set encrypted secrets:

  • GITHUB_CLIENT_ID
  • GITHUB_CLIENT_SECRET
  • GITHUB_OAUTH_SCOPE (optional, defaults to read:user)

Verification

  • GOOS=js GOARCH=wasm go build ./cmd/dang-playground ✅
  • go build ./..., go vet, gofmt clean ✅
  • ./docs/build.sh renders github-playground.html with the right markup ✅
  • The full OAuth round-trip needs a deployed OAuth app + secrets, so it's not
    exercised here — worth eyeballing on the Cloudflare preview once secrets are set.

@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Jun 4, 2026 •

Copy link
Copy Markdown

Deploying dang with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4c08548
Status: ✅  Deploy successful!
Preview URL: https://02817efa.dang-3kk.pages.dev
Branch Preview URL: https://docs-github-playground.dang-3kk.pages.dev

View logs

@vito
vito force-pushed the docs-github-playground branch from 76b5e9b to 4022942 Compare June 4, 2026 19:36
vito added 2 commits June 4, 2026 21:00
Adds a "GraphQL + Dang playground" docs page that lets readers sign in
with GitHub and run snippets that `import GitHub` against the live API,
building on the existing client-side WASM playground. GitHub's GraphQL
endpoint permits CORS, so introspection and queries run straight from
the browser with no proxy; the only server step is the OAuth
code-for-token exchange, handled by two small Cloudflare Pages
Functions that own the client secret and hand the token back via the
URL fragment. The token lives only in the tab's sessionStorage.

dangEval now takes an optional token and returns a Promise, since the
single-threaded wasm event loop cannot block on the network from a
synchronous call. With a token it wires a GitHub ImportConfig into the
eval context (introspected once and cached) so `import GitHub`
resolves; without one it behaves exactly as before. playground.js
gains the auth control and token plumbing for blocks marked
data-dang-github, authored via the new \dang-github-playground tag.

Operators must register a GitHub OAuth app with callback
<site>/github/callback and set GITHUB_CLIENT_ID / GITHUB_CLIENT_SECRET
(optionally GITHUB_OAUTH_SCOPE), mirroring the feedback webhook setup.

Signed-off-by: Alex Suraci <[email protected]>
The "not configured" response was opaque, which made debugging the
Cloudflare setup hard. Report exactly which of GITHUB_CLIENT_ID /
GITHUB_CLIENT_SECRET is unset in the current environment so a
Production-vs-Preview scoping or naming mistake is immediately visible.

Signed-off-by: Alex Suraci <[email protected]>
@vito
vito force-pushed the docs-github-playground branch from 4022942 to 4c08548 Compare June 4, 2026 21:02
@vito
vito merged commit a8da998 into main Jun 4, 2026
6 checks passed
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