Extract credentials in the transport layer, pass them via context, and enforce access with permissions or field extensions.
FastQL’s core has no built-in authentication machinery — authentication is a
transport concern, and the core is deliberately framework-agnostic. The recommended
pattern has three layers:
Extract credentials in the transport layer (middleware, dependency injection).
Pass the authenticated identity into resolvers via the Context object.
Step 1 — Extract credentials in the transport layer
Authentication belongs in the framework integration, not in the GraphQL schema.
Extract the token or session in HTTP middleware or a framework dependency, then
make the resolved identity available when the context is constructed.FastAPI example:
from fastapi import Depends, Requestfrom fastapi.security import HTTPBearer, HTTPAuthorizationCredentialssecurity = HTTPBearer(auto_error=False)def get_current_user( credentials: HTTPAuthorizationCredentials | None = Depends(security),) -> User | None: if credentials is None: return None return verify_jwt(credentials.credentials) # your token verification
ASGI middleware example (framework-agnostic):
class AuthMiddleware: def __init__(self, app): self.app = app async def __call__(self, scope, receive, send): if scope["type"] in ("http", "websocket"): token = extract_bearer(scope["headers"]) scope["user"] = await verify_token(token) if token else None await self.app(scope, receive, send)
Step 2 — Surface the identity through Context
Override get_context (or its framework-specific equivalent) to inject the
resolved identity into the FastQL context:
The ASGI, Starlette, Flask, and Django adapters each have equivalent context
injection hooks — see the integrations section for your
framework.
Step 3 — Enforce access with permissions
Use BasePermission to define reusable access rules and apply them to fields:
from fastql import Field, Permission, Query, Typeclass IsAuthenticated(Permission): message = "You must be logged in." def has_permission(self, source, info) -> bool: return info.context.user is not Noneclass IsAdmin(Permission): message = "Admin access required." def has_permission(self, source, info) -> bool: user = info.context.user return user is not None and user.is_admin@Queryclass QueryRoot: @Field(permissions=[IsAuthenticated]) def me(self, info) -> User: return info.context.user @Field(permissions=[IsAuthenticated, IsAdmin]) def admin_stats(self, info) -> AdminStats: return fetch_admin_stats()
When a permission check fails, FastQL returns a field error with the permission’s
message and null for the field value (subject to the field’s nullability).
Field extensions for cross-cutting auth rules
For rules that apply to many fields, a field extension is cleaner than repeating
permissions=[...] everywhere:
from fastql import FieldExtension, Schema, SchemaExtensionclass RequireAuthExtension(FieldExtension): async def resolve(self, next_, source, info, **kwargs): if info.context.user is None: raise PermissionError("Authentication required.") return await next_(source, info, **kwargs)
Do not perform authentication inside field resolvers. Resolvers are called per-field
and may run in parallel — putting auth logic there makes it easy to miss a field,
hard to test, and expensive to audit.
Don’t verify tokens inside @Field resolvers.
Don’t put credentials in GraphQL arguments — they appear in logs and
introspection.
Do use the transport layer for extraction and Permission / field extensions
for enforcement.
{"docsConfig":{"theme":"mint","$schema":"https://mintlify.com/docs.json","name":"FastQL","description":"A Python-native GraphQL framework with a unified schema API and built-in execution engine.","colors":{"primary":"#15803D","light":"#22C55E","dark":"#15803D"},"logo":{"light":"https://mintcdn.com/fastql/q_W__onbisDxPw41/images/logo-light.svg?fit=max\u0026auto=format\u0026n=q_W__onbisDxPw41\u0026q=85\u0026s=29f6b69ceac421a73d83cc4671ae34bb","dark":"https://mintcdn.com/fastql/q_W__onbisDxPw41/images/logo-dark.svg?fit=max\u0026auto=format\u0026n=q_W__onbisDxPw41\u0026q=85\u0026s=4c5d155ef87d7aa103b8921511a47def"},"favicon":"https://mintcdn.com/fastql/q_W__onbisDxPw41/images/favicon.svg?fit=max\u0026auto=format\u0026n=q_W__onbisDxPw41\u0026q=85\u0026s=21d7670630e0aa79477dec486c61bee8","appearance":{"default":"system"},"navbar":{"links":[{"href":"https://github.com/MyGenX/FastQL","label":"GitHub"}],"primary":{"type":"github","href":"https://github.com/MyGenX/FastQL"}},"footer":{"socials":{"github":"https://github.com/MyGenX/FastQL"}},"seo":{"metatags":{"canonical":"https://fastql.vachagan.dev"}},"styling":{"latex":false},"navigation":{"pages":[]}},"deployment":{"deploymentMetadataValue":{"subdomain":"fastql","hasAudioNarration":false,"actualSubdomain":"fastql","customDomains":["fastql.vachagan.dev"],"gitSource":{"type":"github","owner":"mygenx","repo":"fastql","deployBranch":"main","contentDirectory":"docs","isPrivate":false,"mountPath":"","label":""},"entitlements":{"AI_CHAT":{"status":"DISABLED"}},"buildId":"6ae9599090e885ae1a9016c0:success","clientVersion":"0.0.4271","searchFilterCounts":[{"language":"default","tag":"Build schemas","count":7},{"language":"default","tag":"Start","count":7},{"language":"default","tag":"Integrations","count":7},{"language":"default","tag":"Resolve data","count":6},{"language":"default","tag":"Reference","count":5},{"language":"default","tag":"Architecture","count":4},{"language":"default","tag":"Contribute","count":3},{"language":"default","tag":"Data \u0026 performance","count":3},{"language":"default","tag":"Federation","count":3},{"language":"default","tag":"Operations","count":3}]},"assistantConfig":{"enableAskAiButton":false,"enableStarterQuestions":false,"enableContextualStarterQuestions":false,"enableAskAiSearchBar":true},"basePath":"","hasChatPermissions":false,"hasWebMcpPermissions":false,"toggles":[{"name":"kill-isr","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-rbac-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-mintlify-slack","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"agent-integrations-settings","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"rbac-expansion","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-pr-grouping","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"custom-prefix","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"analytics-v7","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"user-flows-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"no-publish-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-onboarding","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving-live","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"stripTemperatureMiddleware","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"support-platform-pylon-zendesk","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"snapshot-serving","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"instant-rollback","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications-server","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"granular-notifications","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automations-fable","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fixed-ai-action-pricing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"site-roles","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"automation-resolve-merge-conflict","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"scoped-publishing","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"mintql","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"page-level-analytics","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-version-history-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"billing-page-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"full-page-search","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workspace-projects","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"assistant-v5","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"fork-pr-previews","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"revalidation-jwt","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-sso-scim","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"hobby-abuse-scan","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"dashboard-inbox","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-signup","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-dual-write","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"workos-enabled","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"approve-review-flow","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"editor-metadata","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"sso-setup-deadline-banner","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"turbopuffer-serve","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"live-agents","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"starter-pricing","enabled":true,"variant":{"name":"control","enabled":true,"payload":{"type":"string","value":"control"},"feature_enabled":true},"impressionData":false},{"name":"llms-txt-v2","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false},{"name":"wildcard-email-auth","enabled":true,"variant":{"name":"disabled","enabled":false,"feature_enabled":true},"impressionData":false}],"googleFontsInlined":false},"customCss":[{"filePath":"style.css","content":":root{--fastql-ink: #17211b;--fastql-muted: #5c6861;--fastql-line: #dce4df;--fastql-green: #15803d;--fastql-green-dark: #11652f;--fastql-green-soft: #e9f5ed;--fastql-surface: #f7faf8;--fastql-panel: #ffffff;--fastql-code: #101713;--fastql-code-line: #2c3b32;--fastql-code-muted: #9db0a3;--fastql-gutter: clamp(1.25rem, 3vw, 2rem)}.fastql-page,.fastql-page *{box-sizing:border-box}.fastql-page{width:100%;overflow:clip;color:var(--fastql-ink);background:var(--fastql-panel)}.fastql-shell{width:100%;max-width:1244px;margin-inline:auto;padding-inline:var(--fastql-gutter)}.fastql-eyebrow{color:var(--fastql-green-dark);font-size:0.76rem;font-weight:750;letter-spacing:0.11em;text-transform:uppercase}.fastql-hero{position:relative;display:grid;min-height:min(760px, calc(100vh - 4rem));align-items:center;padding-block:clamp(4.5rem, 8vw, 7rem);border-bottom:1px solid var(--fastql-line);background-color:var(--fastql-panel);background-image:linear-gradient(rgb(220 228 223 / 58%) 1px, transparent 1px),\n linear-gradient(90deg, rgb(220 228 223 / 58%) 1px, transparent 1px),\n radial-gradient(circle at 78% 42%, rgb(34 197 94 / 10%), transparent 32rem);background-position:-1px -1px, -1px -1px, center;background-size:48px 48px, 48px 48px, auto}.fastql-hero::before{position:absolute;inset:0;background:linear-gradient(90deg, var(--fastql-panel) 0%, transparent 48%);content:\"\";pointer-events:none}.fastql-hero__layout{position:relative;display:grid;grid-template-columns:minmax(0, 1.05fr) minmax(420px, 0.95fr);gap:clamp(3rem, 7vw, 6rem);align-items:center}.fastql-hero__copy{min-width:0}.fastql-hero h1{max-width:740px;margin:0.9rem 0 1.25rem;color:var(--fastql-ink);font-size:clamp(3.25rem, 5.7vw, 5.6rem);font-weight:720;line-height:0.98;letter-spacing:-0.055em;text-wrap:balance}.fastql-hero__lede{max-width:650px;margin:0;color:var(--fastql-muted);font-size:clamp(1.05rem, 1.5vw, 1.22rem);line-height:1.7}.fastql-actions{display:flex;flex-wrap:wrap;gap:0.75rem;margin-top:2rem}.fastql-action{display:inline-flex;min-height:46px;align-items:center;justify-content:center;padding:0.72rem 1.05rem;border:1px solid var(--fastql-line);border-radius:8px;color:var(--fastql-ink);background:rgb(255 255 255 / 78%);font-size:0.94rem;font-weight:680;line-height:1.2;text-decoration:none;box-shadow:0 1px 2px rgb(23 33 27 / 4%);transition:border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease}.fastql-action:hover{border-color:var(--fastql-green);box-shadow:0 8px 22px rgb(23 33 27 / 9%);transform:translateY(-1px)}.fastql-action--primary{border-color:var(--fastql-green);color:#ffffff;background:var(--fastql-green)}.fastql-action--primary:hover{border-color:var(--fastql-green-dark);background:var(--fastql-green-dark)}.fastql-action:focus-visible,.fastql-feature-card a:focus-visible,.fastql-text-link:focus-visible,.fastql-route-cards a:focus-visible{outline:3px solid rgb(34 197 94 / 42%);outline-offset:3px}.fastql-code-card{min-width:0;overflow:hidden;border:1px solid var(--fastql-code-line);border-radius:14px;color:#dce8df;background:var(--fastql-code);box-shadow:0 28px 70px rgb(23 33 27 / 20%)}.fastql-code-card__bar{display:flex;min-height:44px;align-items:center;gap:0.42rem;padding-inline:1rem;border-bottom:1px solid var(--fastql-code-line);color:var(--fastql-code-muted);background:#151f19}.fastql-code-card__dot{width:8px;height:8px;border-radius:50%;background:#526359}.fastql-code-card__dot:first-child{background:#f59e0b}.fastql-code-card__dot:nth-child(2){background:#4ade80}.fastql-code-card__file{margin-left:auto;font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;font-size:0.76rem}.fastql-code-card__code{max-width:100%;margin:0;overflow-x:auto;padding:1.45rem;color:#dce8df;background:transparent;font-size:clamp(0.78rem, 1.1vw, 0.9rem);line-height:1.65;tab-size:4}.fastql-code-card__code code,.fastql-code-card__result code{display:block;color:inherit;background:transparent;font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;font-size:inherit;text-align:left;white-space:pre}.fastql-code-card__result{display:grid;gap:0.4rem;padding:1rem 1.45rem 1.15rem;border-top:1px solid var(--fastql-code-line);color:#bbf7d0;background:#0c120e;font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;font-size:0.78rem}.fastql-code-card__result span{color:var(--fastql-code-muted);font-size:0.68rem;letter-spacing:0.08em;text-transform:uppercase}.fastql-value-strip{border-bottom:1px solid var(--fastql-line);background:var(--fastql-surface)}.fastql-value-strip__grid{display:grid;grid-template-columns:repeat(3, minmax(0, 1fr))}.fastql-value-strip__grid>div{display:flex;min-width:0;align-items:baseline;gap:0.65rem;padding:1.35rem clamp(1rem, 2vw, 1.75rem);border-left:1px solid var(--fastql-line)}.fastql-value-strip__grid>div:last-child{border-right:1px solid var(--fastql-line)}.fastql-value-strip__metric{color:var(--fastql-green-dark);font-size:1.15rem;font-weight:750}.fastql-value-strip__grid>div>span:not(.fastql-value-strip__metric){color:var(--fastql-muted);font-size:0.88rem}.fastql-section{padding-block:clamp(4.5rem, 8vw, 7rem);border-bottom:1px solid var(--fastql-line);background:var(--fastql-panel)}.fastql-section--tinted{background:var(--fastql-surface)}.fastql-section--last{border-bottom:0}.fastql-section__heading{max-width:760px;margin-bottom:clamp(2rem, 4vw, 3rem)}.fastql-section__heading--compact{max-width:680px}.fastql-section__heading h2,.fastql-inspect h2{margin:0.65rem 0 0;color:var(--fastql-ink);font-size:clamp(2rem, 4vw, 3.35rem);font-weight:700;line-height:1.08;letter-spacing:-0.038em;text-wrap:balance}.fastql-section__heading p,.fastql-inspect__copy>p{max-width:680px;margin:1rem 0 0;color:var(--fastql-muted);font-size:1.03rem;line-height:1.7}.fastql-feature-grid{display:grid;grid-template-columns:repeat(3, minmax(0, 1fr));gap:1rem}.fastql-feature-card{position:relative;display:flex;min-width:0;min-height:300px;flex-direction:column;padding:clamp(1.35rem, 2.5vw, 1.85rem);border:1px solid var(--fastql-line);border-radius:10px;background:var(--fastql-panel);box-shadow:0 1px 2px rgb(23 33 27 / 3%);transition:border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease}.fastql-feature-card:hover{border-color:rgb(21 128 61 / 42%);box-shadow:0 16px 36px rgb(23 33 27 / 8%);transform:translateY(-2px)}.fastql-feature-card__index{color:var(--fastql-green-dark);font-family:ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;font-size:0.74rem;font-weight:700}.fastql-feature-card h3{margin:2.2rem 0 0.7rem;color:var(--fastql-ink);font-size:1.18rem;letter-spacing:-0.015em}.fastql-feature-card p{margin:0;color:var(--fastql-muted);line-height:1.65}.fastql-feature-card a{align-self:flex-start;margin-top:auto;padding-top:1.5rem;color:var(--fastql-green-dark);font-size:0.9rem;font-weight:680;text-decoration:none}.fastql-workflow{position:relative;display:grid;grid-template-columns:repeat(4, minmax(0, 1fr));gap:1rem}.fastql-workflow::before{position:absolute;top:24px;right:10%;left:10%;height:1px;background:var(--fastql-line);content:\"\"}.fastql-workflow__step{position:relative;min-width:0;padding-top:4rem}.fastql-workflow__step>span{position:absolute;top:0;left:0;z-index:1;display:grid;width:48px;height:48px;place-items:center;border:1px solid var(--fastql-green);border-radius:50%;color:var(--fastql-green-dark);background:var(--fastql-panel);font-size:0.78rem;font-weight:750}.fastql-workflow__title{display:block;color:var(--fastql-ink);font-size:1rem;font-weight:700}.fastql-workflow__step p{max-width:190px;margin:0.4rem 0 0;color:var(--fastql-muted);font-size:0.88rem;line-height:1.5}.fastql-inspect{display:grid;grid-template-columns:minmax(0, 0.75fr) minmax(0, 1.25fr);gap:clamp(2.5rem, 6vw, 5rem);align-items:center}.fastql-inspect__copy{min-width:0}.fastql-command{display:flex;max-width:100%;align-items:center;gap:0.65rem;margin-top:1.6rem;overflow-x:auto;padding:0.82rem 0.95rem;border:1px solid var(--fastql-code-line);border-radius:8px;color:#dce8df;background:var(--fastql-code);white-space:nowrap}.fastql-command span{color:#4ade80;font-weight:750}.fastql-command code{color:inherit;background:transparent;font-size:0.77rem}.fastql-text-link{display:inline-block;margin-top:1.25rem;color:var(--fastql-green-dark);font-size:0.92rem;font-weight:680;text-decoration:none}.fastql-preview{min-width:0;overflow:hidden;border:1px solid var(--fastql-line);border-radius:12px;background:var(--fastql-panel);box-shadow:0 22px 54px rgb(23 33 27 / 12%)}.fastql-preview img{display:block;width:100%;height:auto}.fastql-route-cards{display:grid;grid-template-columns:repeat(3, minmax(0, 1fr));gap:1rem}.fastql-route-cards a{display:flex;min-width:0;min-height:220px;flex-direction:column;padding:clamp(1.35rem, 2.5vw, 1.8rem);border:1px solid var(--fastql-line);border-radius:10px;color:var(--fastql-ink);background:var(--fastql-panel);text-decoration:none;transition:border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease}.fastql-route-cards a:hover{border-color:var(--fastql-green);box-shadow:0 14px 34px rgb(23 33 27 / 8%);transform:translateY(-2px)}.fastql-route-cards span{color:var(--fastql-green-dark);font-size:0.75rem;font-weight:750;letter-spacing:0.08em;text-transform:uppercase}.fastql-route-cards__title{max-width:290px;margin-top:1.25rem;font-size:1.12rem;font-weight:700;line-height:1.45}.fastql-route-cards .fastql-route-cards__cta{margin-top:auto;color:var(--fastql-muted);font-size:0.88rem;font-weight:400;font-style:normal;letter-spacing:0;text-transform:none}html.dark{--fastql-ink: #f4f7f5;--fastql-muted: #b6c2ba;--fastql-line: #334239;--fastql-green-dark: #4ade80;--fastql-green-soft: #173222;--fastql-surface: #111914;--fastql-panel: #0d130f}html.dark .fastql-hero{background-image:linear-gradient(rgb(51 66 57 / 45%) 1px, transparent 1px),\n linear-gradient(90deg, rgb(51 66 57 / 45%) 1px, transparent 1px),\n radial-gradient(circle at 78% 42%, rgb(34 197 94 / 9%), transparent 32rem)}html.dark .fastql-action{background:rgb(13 19 15 / 82%)}html.dark .fastql-action--primary{background:var(--fastql-green)}html.dark .fastql-code-card,html.dark .fastql-preview{box-shadow:0 28px 70px rgb(0 0 0 / 34%)}@media (max-width: 960px){.fastql-hero{min-height:auto}.fastql-hero::before{background:linear-gradient(180deg, var(--fastql-panel) 0%, transparent 60%)}.fastql-hero__layout,.fastql-inspect{grid-template-columns:1fr}.fastql-hero__layout{gap:3rem}.fastql-hero__copy{max-width:760px}.fastql-code-card{width:min(100%, 720px)}.fastql-feature-grid,.fastql-route-cards{grid-template-columns:repeat(2, minmax(0, 1fr))}.fastql-feature-card:last-child,.fastql-route-cards a:last-child{grid-column:1 / -1}.fastql-feature-card:last-child{min-height:250px}.fastql-inspect__copy{max-width:680px}}@media (max-width: 700px){.fastql-hero{padding-block:3.75rem 4rem}.fastql-hero h1{font-size:clamp(2.75rem, 14vw, 4rem)}.fastql-value-strip__grid,.fastql-feature-grid,.fastql-workflow,.fastql-route-cards{grid-template-columns:1fr}.fastql-value-strip__grid>div,.fastql-value-strip__grid>div:last-child{border-right:1px solid var(--fastql-line);border-bottom:1px solid var(--fastql-line)}.fastql-value-strip__grid>div:last-child{border-bottom:0}.fastql-feature-card:last-child,.fastql-route-cards a:last-child{grid-column:auto}.fastql-workflow{gap:0}.fastql-workflow::before{top:24px;bottom:24px;left:24px;width:1px;height:auto}.fastql-workflow__step{min-height:110px;padding:0 0 2rem 4.25rem}.fastql-workflow__step p{max-width:none}.fastql-feature-card,.fastql-feature-card:last-child{min-height:260px}.fastql-route-cards a{min-height:190px}}@media (max-width: 480px){.fastql-actions{align-items:stretch;flex-direction:column}.fastql-action{width:100%}.fastql-code-card__code{padding:1.1rem;font-size:0.73rem}.fastql-code-card__result{padding-inline:1.1rem;overflow-x:auto}}@media (prefers-reduced-motion: reduce){.fastql-action,.fastql-feature-card,.fastql-route-cards a{transition:none}.fastql-action:hover,.fastql-feature-card:hover,.fastql-route-cards a:hover{transform:none}}"}]}
{"page":{"pagePath":"resolve/authentication","slug":"/resolve/authentication","pageMetadata":{"title":"Authentication","description":"Extract credentials in the transport layer, pass them via context, and enforce access with permissions or field extensions.","href":"/resolve/authentication"},"description":{"compiledSource":"\"use strict\";\nconst {jsx: _jsx} = arguments[0];\nconst {useMDXComponents: _provideComponents} = arguments[0];\nfunction _createMdxContent(props) {\n const _components = {\n p: \"p\",\n ..._provideComponents(),\n ...props.components\n };\n return _jsx(_components.p, {\n children: \"Extract credentials in the transport layer, pass them via context, and enforce access with permissions or field extensions.\"\n });\n}\nfunction MDXContent(props = {}) {\n const {wrapper: MDXLayout} = {\n ..._provideComponents(),\n ...props.components\n };\n return MDXLayout ? _jsx(MDXLayout, {\n ...props,\n children: _jsx(_createMdxContent, {\n ...props\n })\n }) : _createMdxContent(props);\n}\nreturn {\n default: MDXContent\n};\n","frontmatter":{},"scope":{}},"pageType":"default","mdx":{"mdxSource":{"compiledSource":"\"use strict\";const{Fragment:_Fragment,jsx:_jsx,jsxs:_jsxs}=arguments[0];const{useMDXComponents:_provideComponents}=arguments[0];function _createMdxContent(props){const _components={a:`a`,code:`code`,li:`li`,ol:`ol`,p:`p`,pre:`pre`,span:`span`,strong:`strong`,ul:`ul`,..._provideComponents(),...props.components},{CodeBlock,Heading,Warning}=_components;if(!CodeBlock)_missingMdxReference(`CodeBlock`,true);if(!Heading)_missingMdxReference(`Heading`,true);if(!Warning)_missingMdxReference(`Warning`,true);return _jsxs(_Fragment,{children:[_jsx(_components.p,{children:`FastQL’s core has no built-in authentication machinery — authentication is a\ntransport concern, and the core is deliberately framework-agnostic. The recommended\npattern has three layers:`}),`\n`,_jsxs(_components.ol,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Extract`}),` credentials in the transport layer (middleware, dependency injection).`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Pass`}),` the authenticated identity into resolvers via the `,_jsx(_components.code,{children:`Context`}),` object.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Enforce`}),` access rules with `,_jsx(_components.a,{href:`/resolve/extensions-and-permissions`,children:`permissions or field extensions`}),`.`]}),`\n`]}),`\n`,_jsx(Heading,{level:`2`,id:`step-1-—-extract-credentials-in-the-transport-layer`,children:`Step 1 — Extract credentials in the transport layer`}),`\n`,_jsx(_components.p,{children:`Authentication belongs in the framework integration, not in the GraphQL schema.\nExtract the token or session in HTTP middleware or a framework dependency, then\nmake the resolved identity available when the context is constructed.`}),`\n`,_jsx(_components.p,{children:_jsx(_components.strong,{children:`FastAPI example:`})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`12`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`12`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` fastapi `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Depends, Request`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` fastapi.security `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` HTTPBearer, HTTPAuthorizationCredentials`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`security `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` HTTPBearer(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`auto_error`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`False`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` get_current_user`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` credentials`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: HTTPAuthorizationCredentials `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`|`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Depends(security),`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) -> User `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`|`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` credentials `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`is`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` verify_jwt(credentials.credentials) `}),_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# your token verification`})]}),`\n`]})})}),`\n`,_jsx(_components.p,{children:_jsx(_components.strong,{children:`ASGI middleware example (framework-agnostic):`})}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`9`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`9`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`class`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:` AuthMiddleware`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` def`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` __init__`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`app`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.app `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` app`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` async`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` def`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` __call__`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`scope`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`receive`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`send`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` scope[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"type\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`] `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`in`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` (`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"http\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"websocket\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` token `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` extract_bearer(scope[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"headers\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`])`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` scope[`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"user\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`] `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` verify_token(token) `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` token `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`else`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.app(scope, receive, send)`})]}),`\n`]})})}),`\n`,_jsxs(Heading,{level:`2`,id:`step-2-—-surface-the-identity-through-context`,children:[`Step 2 — Surface the identity through `,_jsx(_components.code,{children:`Context`})]}),`\n`,_jsxs(_components.p,{children:[`Override `,_jsx(_components.code,{children:`get_context`}),` (or its framework-specific equivalent) to inject the\nresolved identity into the FastQL context:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`20`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`20`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` fastql `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Context`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` fastapi `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Request`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`class`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:` AppContext`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`Context`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` def`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#DCDCAA`},children:` __init__`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`user`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: User `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`|`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) -> `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:`None`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`.user `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` user`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#6E7781`,\"--shiki-dark\":`#6A9955`},children:`# FastAPI integration`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` fastql.fastapi `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` GraphQLRouter`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`router `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` GraphQLRouter(schema)`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`@router.context_getter`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`async`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` get_context`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` request`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: Request,`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:` user`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`: User `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`|`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:` =`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Depends(get_current_user),`})]}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) -> AppContext:`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` AppContext(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`user`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`user)`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`The ASGI, Starlette, Flask, and Django adapters each have equivalent context\ninjection hooks — see the `,_jsx(_components.a,{href:`/integrations/overview`,children:`integrations section`}),` for your\nframework.`]}),`\n`,_jsx(Heading,{level:`2`,id:`step-3-—-enforce-access-with-permissions`,children:`Step 3 — Enforce access with permissions`}),`\n`,_jsxs(_components.p,{children:[`Use `,_jsx(_components.code,{children:`BasePermission`}),` to define reusable access rules and apply them to fields:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`27`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`27`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` fastql `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` Field, Permission, Query, Type`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`class`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:` IsAuthenticated`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`Permission`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` message `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"You must be logged in.\"`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` has_permission`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`source`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`info`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) -> `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`bool`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` info.context.user `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`is`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` not`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`class`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:` IsAdmin`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`Permission`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` message `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:` \"Admin access required.\"`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` has_permission`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`source`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`info`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) -> `}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`bool`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` user `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` info.context.user`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` user `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`is`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` not`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` and`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` user.is_admin`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`,children:_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:`@Query`})}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`class`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:` QueryRoot`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` @Field`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`permissions`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[IsAuthenticated])`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` me`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`info`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) -> User:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` info.context.user`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` @Field`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#9CDCFE`},children:`permissions`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`=`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`[IsAuthenticated, IsAdmin])`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` admin_stats`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`info`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`) -> AdminStats:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` fetch_admin_stats()`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`When a permission check fails, FastQL returns a field error with the permission’s\n`,_jsx(_components.code,{children:`message`}),` and `,_jsx(_components.code,{children:`null`}),` for the field value (subject to the field’s nullability).`]}),`\n`,_jsx(Heading,{level:`2`,id:`field-extensions-for-cross-cutting-auth-rules`,children:`Field extensions for cross-cutting auth rules`}),`\n`,_jsxs(_components.p,{children:[`For rules that apply to many fields, a field extension is cleaner than repeating\n`,_jsx(_components.code,{children:`permissions=[...]`}),` everywhere:`]}),`\n`,_jsx(CodeBlock,{filename:``,numberOfLines:`8`,language:`python`,children:_jsx(_components.pre,{className:`shiki shiki-themes github-light-default dark-plus`,style:{backgroundColor:`#ffffff`,\"--shiki-dark-bg\":`#0B0C0E`,color:`#1f2328`,\"--shiki-dark\":`#D4D4D4`},language:`python`,children:_jsxs(_components.code,{language:`python`,numberOfLines:`8`,children:[_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`from`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` fastql `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:`import`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` FieldExtension, Schema, SchemaExtension`})]}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsx(_components.span,{className:`line`}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`class`}),_jsx(_components.span,{style:{color:`#953800`,\"--shiki-dark\":`#4EC9B0`},children:` RequireAuthExtension`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:`FieldExtension`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` async`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:` def`}),_jsx(_components.span,{style:{color:`#8250DF`,\"--shiki-dark\":`#DCDCAA`},children:` resolve`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`self`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`next_`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`source`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`info`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`, `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`**`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#9CDCFE`},children:`kwargs`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`):`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` if`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` info.context.user `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#569CD6`},children:`is`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#569CD6`},children:` None`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`:`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` raise`}),_jsx(_components.span,{style:{color:`#0550AE`,\"--shiki-dark\":`#4EC9B0`},children:` PermissionError`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`(`}),_jsx(_components.span,{style:{color:`#0A3069`,\"--shiki-dark\":`#CE9178`},children:`\"Authentication required.\"`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`)`})]}),`\n`,_jsxs(_components.span,{className:`line`,children:[_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` return`}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#C586C0`},children:` await`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:` next_(source, info, `}),_jsx(_components.span,{style:{color:`#CF222E`,\"--shiki-dark\":`#D4D4D4`},children:`**`}),_jsx(_components.span,{style:{color:`#1F2328`,\"--shiki-dark\":`#D4D4D4`},children:`kwargs)`})]}),`\n`]})})}),`\n`,_jsxs(_components.p,{children:[`See `,_jsx(_components.a,{href:`/resolve/extensions-and-permissions`,children:`Extensions and permissions`}),` for the full\nfield extension API.`]}),`\n`,_jsx(Heading,{level:`2`,id:`what-not-to-do`,children:`What not to do`}),`\n`,_jsx(Warning,{children:_jsx(_components.p,{children:`Do not perform authentication inside field resolvers. Resolvers are called per-field\nand may run in parallel — putting auth logic there makes it easy to miss a field,\nhard to test, and expensive to audit.`})}),`\n`,_jsxs(_components.ul,{children:[`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Don’t`}),` verify tokens inside `,_jsx(_components.code,{children:`@Field`}),` resolvers.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Don’t`}),` put credentials in GraphQL arguments — they appear in logs and\nintrospection.`]}),`\n`,_jsxs(_components.li,{children:[_jsx(_components.strong,{children:`Do`}),` use the transport layer for extraction and `,_jsx(_components.code,{children:`Permission`}),` / field extensions\nfor enforcement.`]}),`\n`]})]})}function MDXContent(props={}){const{wrapper:MDXLayout}={..._provideComponents(),...props.components};return MDXLayout?_jsx(MDXLayout,{...props,children:_jsx(_createMdxContent,{...props})}):_createMdxContent(props)}return{default:MDXContent};function _missingMdxReference(id,component){throw new Error(`Expected `+(component?`component`:`object`)+\" `\"+id+\"` to be defined: you likely forgot to import, pass, or provide it.\")}","frontmatter":{},"scope":{"config":{},"pageMetadata":{"title":"Authentication","description":"Extract credentials in the transport layer, pass them via context, and enforce access with permissions or field extensions.","href":"/resolve/authentication"}}},"mdxSourceWithNoJs":null},"mdxExtracts":{"tableOfContents":[{"title":"Step 1 — Extract credentials in the transport layer","slug":"step-1-—-extract-credentials-in-the-transport-layer","depth":2,"children":[]},{"title":"Step 2 — Surface the identity through Context","slug":"step-2-—-surface-the-identity-through-context","depth":2,"children":[]},{"title":"Step 3 — Enforce access with permissions","slug":"step-3-—-enforce-access-with-permissions","depth":2,"children":[]},{"title":"Field extensions for cross-cutting auth rules","slug":"field-extensions-for-cross-cutting-auth-rules","depth":2,"children":[]},{"title":"What not to do","slug":"what-not-to-do","depth":2,"children":[]}],"codeExamples":{}},"jsLinks":[],"subdomain":"fastql","siteName":"FastQL","title":"Authentication - FastQL","navMaps":{"firstHrefInVersion":{},"firstHrefInLanguage":{}},"lastModified":"2026-06-12T10:26:07.652Z","originalFileLocation":"resolve/authentication.mdx"},"headHtml":"\u003cscript data-mint-head>(function(){var d=document.documentElement,p=null;if(!p){try{p=localStorage.getItem(\"isDarkMode\")}catch(e){}if(p==='true')p='dark';else if(p==='false')p='light';if(p!=='light'\u0026\u0026p!=='dark'\u0026\u0026p!=='system')p=\"system\"}var r=p==='system'?(matchMedia(\"(prefers-color-scheme: dark)\").matches?'dark':'light'):p;d.classList.remove(r==='dark'?'light':'dark');d.classList.add(r);d.setAttribute(\"data-theme-preference\",p)})();\u003c/script>\u003cmeta data-mint-head name=\"description\" content=\"Extract credentials in the transport layer, pass them via context, and enforce access with permissions or field extensions.\">\u003cmeta data-mint-head name=\"application-name\" content=\"FastQL\">\u003cmeta data-mint-head name=\"generator\" content=\"Mintlify\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/fastql/GplX8e6u9KJmBbEZ/_generated/favicon/android-chrome-192x192.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"apple-touch-icon\" type=\"image/png\" sizes=\"180x180\" href=\"/mintlify-assets/_mintlify/favicons/fastql/GplX8e6u9KJmBbEZ/_generated/favicon/apple-touch-icon.png\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/fastql/GplX8e6u9KJmBbEZ/_generated/favicon/favicon-16x16.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/fastql/GplX8e6u9KJmBbEZ/_generated/favicon/favicon-32x32.png\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/fastql/GplX8e6u9KJmBbEZ/_generated/favicon/favicon.ico\" media=\"(prefers-color-scheme: light)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"192x192\" href=\"/mintlify-assets/_mintlify/favicons/fastql/GplX8e6u9KJmBbEZ/_generated/favicon-dark/android-chrome-192x192.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"16x16\" href=\"/mintlify-assets/_mintlify/favicons/fastql/GplX8e6u9KJmBbEZ/_generated/favicon-dark/favicon-16x16.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"icon\" type=\"image/png\" sizes=\"32x32\" href=\"/mintlify-assets/_mintlify/favicons/fastql/GplX8e6u9KJmBbEZ/_generated/favicon-dark/favicon-32x32.png\" media=\"(prefers-color-scheme: dark)\">\u003clink data-mint-head rel=\"shortcut icon\" type=\"image/x-icon\" href=\"/mintlify-assets/_mintlify/favicons/fastql/GplX8e6u9KJmBbEZ/_generated/favicon-dark/favicon.ico\" media=\"(prefers-color-scheme: dark)\">\u003cmeta data-mint-head property=\"og:title\" content=\"Authentication - FastQL\">\u003cmeta data-mint-head property=\"og:description\" content=\"Extract credentials in the transport layer, pass them via context, and enforce access with permissions or field extensions.\">\u003cmeta data-mint-head property=\"og:site_name\" content=\"FastQL\">\u003cmeta data-mint-head property=\"og:url\" content=\"https://fastql.vachagan.dev/resolve/authentication\">\u003cmeta data-mint-head property=\"og:type\" content=\"website\">\u003cmeta data-mint-head property=\"og:image\" content=\"https://fastql.mintlify.site/_mintlify/api/og/v2?division=Resolve+data\u0026amp;title=Authentication\u0026amp;description=Extract+credentials+in+the+transport+layer%2C+pass+them+via+context%2C+and+enforce+access+with+permissions+or+field+extensions.\u0026amp;theme=e47e458230b507940d40bc1c\u0026amp;signature=0cf59398056c064c1a2e8b9d57ac0e085bc3235e6d86230ff7709274f37e58f4\">\u003cmeta data-mint-head property=\"og:image:width\" content=\"1200\">\u003cmeta data-mint-head property=\"og:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"twitter:card\" content=\"summary_large_image\">\u003cmeta data-mint-head name=\"twitter:title\" content=\"Authentication - FastQL\">\u003cmeta data-mint-head name=\"twitter:description\" content=\"Extract credentials in the transport layer, pass them via context, and enforce access with permissions or field extensions.\">\u003cmeta data-mint-head name=\"twitter:image\" content=\"https://fastql.mintlify.site/_mintlify/api/og/v2?division=Resolve+data\u0026amp;title=Authentication\u0026amp;description=Extract+credentials+in+the+transport+layer%2C+pass+them+via+context%2C+and+enforce+access+with+permissions+or+field+extensions.\u0026amp;theme=e47e458230b507940d40bc1c\u0026amp;signature=0cf59398056c064c1a2e8b9d57ac0e085bc3235e6d86230ff7709274f37e58f4\">\u003cmeta data-mint-head name=\"twitter:image:width\" content=\"1200\">\u003cmeta data-mint-head name=\"twitter:image:height\" content=\"630\">\u003cmeta data-mint-head name=\"msapplication-config\" content=\"/mintlify-assets/_mintlify/favicons/fastql/GplX8e6u9KJmBbEZ/_generated/favicon/browserconfig.xml\">\u003cmeta data-mint-head name=\"apple-mobile-web-app-title\" content=\"FastQL\">\u003cmeta data-mint-head name=\"msapplication-TileColor\" content=\"#15803D\">\u003clink data-mint-head rel=\"canonical\" href=\"https://fastql.vachagan.dev/resolve/authentication\">\u003clink data-mint-head rel=\"alternate\" type=\"application/xml\" href=\"/sitemap.xml\">\u003clink data-mint-head rel=\"alternate\" type=\"text/markdown\" href=\"/resolve/authentication.md\">\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@graph\":[{\"@type\":\"Organization\",\"@id\":\"https://fastql.vachagan.dev/#organization\",\"name\":\"FastQL\",\"url\":\"https://fastql.vachagan.dev\",\"logo\":{\"@type\":\"ImageObject\",\"url\":\"https://mintcdn.com/fastql/q_W__onbisDxPw41/images/logo-light.svg?fit=max\u0026auto=format\u0026n=q_W__onbisDxPw41\u0026q=85\u0026s=29f6b69ceac421a73d83cc4671ae34bb\"}},{\"@type\":\"WebSite\",\"@id\":\"https://fastql.vachagan.dev#website\",\"name\":\"FastQL\",\"url\":\"https://fastql.vachagan.dev\",\"publisher\":{\"@id\":\"https://fastql.vachagan.dev/#organization\"}},{\"@type\":\"WebPage\",\"@id\":\"https://fastql.vachagan.dev/resolve/authentication#webpage\",\"url\":\"https://fastql.vachagan.dev/resolve/authentication\",\"name\":\"Authentication\",\"description\":\"Extract credentials in the transport layer, pass them via context, and enforce access with permissions or field extensions.\",\"dateModified\":\"2026-06-12T10:26:07.652Z\",\"isPartOf\":{\"@id\":\"https://fastql.vachagan.dev#website\"},\"breadcrumb\":{\"@id\":\"https://fastql.vachagan.dev/resolve/authentication#breadcrumb\"}},{\"@type\":\"BreadcrumbList\",\"@id\":\"https://fastql.vachagan.dev/resolve/authentication#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Resolve data\",\"item\":\"https://fastql.vachagan.dev/resolve/resolvers\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Authentication\",\"item\":\"https://fastql.vachagan.dev/resolve/authentication\"}]},{\"@type\":[\"Article\",\"TechArticle\"],\"@id\":\"https://fastql.vachagan.dev/resolve/authentication#article\",\"headline\":\"Authentication\",\"name\":\"Authentication\",\"description\":\"Extract credentials in the transport layer, pass them via context, and enforce access with permissions or field extensions.\",\"url\":\"https://fastql.vachagan.dev/resolve/authentication\",\"mainEntityOfPage\":{\"@id\":\"https://fastql.vachagan.dev/resolve/authentication#webpage\"},\"dateModified\":\"2026-06-12T10:26:07.652Z\",\"publisher\":{\"@id\":\"https://fastql.vachagan.dev/#organization\"},\"isPartOf\":{\"@id\":\"https://fastql.vachagan.dev#website\"}}]}\u003c/script>\u003cscript data-mint-head type=\"application/ld+json\">{\"@context\":\"https://schema.org\",\"@type\":\"WebSite\",\"name\":\"FastQL\",\"publisher\":{\"@type\":\"Organization\",\"name\":\"FastQL\"},\"provider\":{\"@type\":\"Organization\",\"name\":\"Mintlify\",\"url\":\"https://mintlify.com\"}}\u003c/script>","agentPointerHref":"/resolve/authentication.md","siteName":"FastQL","nav":{"global":null,"groups":[{"group":"Start","pages":[{"title":"FastQL documentation","mode":"custom","href":"/index"},{"title":"Introduction","href":"/start/introduction"},{"title":"Installation","href":"/start/installation"},{"title":"Quickstart","href":"/start/quickstart"},{"title":"First schema","href":"/start/first-schema"},{"title":"Project status","href":"/start/project-status"},{"title":"FAQ","href":"/start/faq"}]},{"group":"Build schemas","pages":[{"title":"Types and fields","href":"/build/types-and-fields"},{"title":"Inputs and abstract types","href":"/build/inputs-and-abstract-types"},{"title":"Operations and schema","href":"/build/operations-and-schema"},{"title":"Naming and configuration","href":"/build/naming-and-configuration"},{"title":"Generic types","href":"/build/generic-types"},{"title":"Custom directives \u0026 field visibility","href":"/build/directives-and-visibility"},{"title":"Lazy types and forward references","href":"/build/lazy-types"}]},{"group":"Resolve data","pages":[{"title":"Resolvers","href":"/resolve/resolvers"},{"title":"Context and Info","href":"/resolve/context-and-info"},{"title":"Dependencies","href":"/resolve/dependencies"},{"title":"Extensions and permissions","href":"/resolve/extensions-and-permissions"},{"title":"Errors and nullability","description":"Understand GraphQL errors, paths, and non-null propagation.","href":"/resolve/errors-and-nullability"},{"title":"Authentication","href":"/resolve/authentication"}]},{"group":"Data \u0026 performance","pages":[{"title":"DataLoader","description":"Batch and cache per-request loads to eliminate N+1 queries.","href":"/data/dataloader"},{"title":"Schema extensions","href":"/data/schema-extensions"},{"title":"Relay pagination","href":"/data/relay-pagination"}]},{"group":"Protocol features","pages":[{"title":"Subscriptions","href":"/protocol/subscriptions"},{"title":"Incremental delivery","href":"/protocol/incremental-delivery"},{"title":"File uploads \u0026 batching","href":"/protocol/uploads-and-batching"}]},{"group":"Federation","pages":[{"title":"Apollo Federation v2 — Overview","href":"/federation/overview"},{"title":"Federation entities","href":"/federation/entities"},{"title":"Custom federation directives","href":"/federation/custom-directives"}]},{"group":"Integrations","pages":[{"title":"Web framework integrations","href":"/integrations/overview"},{"title":"ASGI, Starlette, and FastAPI","href":"/integrations/asgi-and-api-frameworks"},{"title":"Flask and Django","href":"/integrations/flask-and-django"},{"title":"AIOHTTP, Sanic, Litestar, Quart \u0026 Channels","href":"/integrations/additional-frameworks"},{"title":"HTTP context","href":"/integrations/context"},{"title":"GraphQL-over-HTTP contract","href":"/integrations/http-contract"},{"title":"Pydantic integration","href":"/integrations/pydantic"}]},{"group":"Operations","pages":[{"title":"Deployment","href":"/operations/deployment"},{"title":"Testing \u0026 schema export","href":"/operations/testing-and-export"},{"title":"Tracing \u0026 observability","href":"/operations/observability"}]},{"group":"Tooling","pages":[{"title":"Development server","href":"/tooling/dev-server"},{"title":"CLI","href":"/tooling/cli"},{"title":"SDL and introspection","href":"/tooling/schema-output"}]},{"group":"Reference","pages":[{"title":"API overview","href":"/reference/overview"},{"title":"Decorators and metadata","href":"/reference/decorators"},{"title":"Schema and execution","href":"/reference/schema-and-execution"},{"title":"Context API","href":"/reference/context"},{"title":"Scalars and wrappers","href":"/reference/scalars-and-wrappers"}]},{"group":"Architecture","pages":[{"title":"Architecture overview","href":"/architecture/overview"},{"title":"Language pipeline","href":"/architecture/language-pipeline"},{"title":"Type system and schema compilation","href":"/architecture/type-system"},{"title":"Validation and execution","href":"/architecture/validation-and-execution"}]},{"group":"Specifications","pages":[{"title":"Product principles and scope","href":"/specifications/product-principles"},{"title":"Capability catalog","href":"/specifications/capability-catalog"}]},{"group":"Contribute","pages":[{"title":"Development setup","href":"/contribute/development"},{"title":"Documentation workflow","href":"/contribute/documentation"},{"title":"Contributing","href":"/contribute/contributing"}]}]},"basePath":"","title":"Authentication - FastQL","deploymentId":"dpl_Em2U4NQQ2N2DE3HPbPUJVZLnAtvc","buildId":"dpl_Em2U4NQQ2N2DE3HPbPUJVZLnAtvc","dynamics":[],"chunks":[]}