Skip to content

feat: session manager for any library, device signals, refresh tokens - #7

Merged
BackStacked merged 1 commit into
mainfrom
claude/graphql-backend-fa2c1c
Oct 14, 2026
Merged

BackStacked merged 1 commit into
mainfrom
claude/graphql-backend-fa2c1c

Conversation

@BackStacked

Copy link
Copy Markdown
Contributor

What and why

Before: the GraphQL client kept one bearer token and left refresh and session state to the app.

After: client.session, a framework-agnostic session manager with no dependencies.

  • It keeps the access and refresh tokens, in memory, localStorage, or any storage you supply.
  • It refreshes before expiry, once for everyone: parallel callers share one refresh, and tabs share it through Web Locks. On UNAUTHENTICATED it refreshes and retries once.
  • It notifies React (useMgplSession), Vue, Svelte and Solid through subscribe / getSnapshot / store.
  • session.fetch plugs into Apollo, urql, graphql-request and RTK Query.
  • mgplQuery / mgplMutation / mgplKey / mgplFetcher / clearOnSignOut cover TanStack Query and SWR without importing either.

Login and refresh send device signals (deviceId, clientSessionId, fingerprint, info) so the API can bind refresh tokens to the device. Everything collected is listed in docs/session.md, and there is no canvas, audio or font probing. The signal code is in src/graphql/device.ts, which imports nothing, so it can move to security-kit unchanged.

New operations: refreshSession, job, startDocumentJob (documents.startJob / job / waitForJob). LoginResult now carries accessToken and refreshToken. Version 1.2.0.

How: the end-to-end checks run in mgpl-diagnostics/api's test suite against the real server. They cover login with device signals, 5 parallel calls with an expiring token causing 1 refresh, refresh and retry on UNAUTHENTICATED, session.fetch, and logout. All 96 checks pass locally.

Type

  • Feature
  • Fix
  • Docs
  • Chore

Screenshots

n/a (SDK)

Checklist

  • npm run typecheck && npm run build
  • Docs: docs/session.md (new, Mermaid), graphql.md, README, AGENTS.md, llms
  • Zero runtime dependencies kept

🤖 Generated with Claude Code

https://claude.ai/code/session_01BA5Vx77ihDsLiZpyg5duJV


Generated by Claude Code

…y / SWR helpers

Access + refresh tokens with single-flight refresh (Web Locks across tabs), one retry on
UNAUTHENTICATED, memory or web storage, subscribe/getSnapshot/store and a fetch wrapper for any
UI or GraphQL library. Device signals (deviceId, clientSessionId, fingerprint, info) go with login
and refresh. New operations: refreshSession, job, startDocumentJob. 1.2.0.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BA5Vx77ihDsLiZpyg5duJV
@BackStacked
BackStacked merged commit 8961047 into main Oct 14, 2026
1 check passed
@BackStacked
BackStacked deleted the claude/graphql-backend-fa2c1c branch October 14, 2026 22:06
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.

2 participants