@softistx/alxia-graphql 0.0.0-stage → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +445 -2
  3. package/dist/bounded-stream.d.ts +37 -0
  4. package/dist/bounded-stream.d.ts.map +1 -0
  5. package/dist/endpoint.d.ts +17 -0
  6. package/dist/endpoint.d.ts.map +1 -0
  7. package/dist/executor.d.ts +49 -0
  8. package/dist/executor.d.ts.map +1 -0
  9. package/dist/explorer.d.ts +24 -0
  10. package/dist/explorer.d.ts.map +1 -0
  11. package/dist/graphql.d.ts +63 -0
  12. package/dist/graphql.d.ts.map +1 -0
  13. package/dist/handler.d.ts +11 -0
  14. package/dist/handler.d.ts.map +1 -0
  15. package/dist/index.d.ts +8 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +621 -0
  18. package/dist/index.js.map +21 -0
  19. package/dist/once-per-request.d.ts +28 -0
  20. package/dist/once-per-request.d.ts.map +1 -0
  21. package/dist/operation.d.ts +3 -0
  22. package/dist/operation.d.ts.map +1 -0
  23. package/dist/options.d.ts +38 -0
  24. package/dist/options.d.ts.map +1 -0
  25. package/dist/removed.d.ts +14 -0
  26. package/dist/removed.d.ts.map +1 -0
  27. package/dist/sandbox.d.ts +15 -0
  28. package/dist/sandbox.d.ts.map +1 -0
  29. package/dist/testing/client.d.ts +95 -0
  30. package/dist/testing/client.d.ts.map +1 -0
  31. package/dist/testing/index.d.ts +2 -0
  32. package/dist/testing/index.d.ts.map +1 -0
  33. package/dist/testing/index.js +73 -0
  34. package/dist/testing/index.js.map +10 -0
  35. package/dist/ws.d.ts +30 -0
  36. package/dist/ws.d.ts.map +1 -0
  37. package/docs/README.md +31 -0
  38. package/docs/guide/context.md +351 -0
  39. package/docs/guide/endpoint.md +293 -0
  40. package/docs/guide/executor.md +75 -0
  41. package/docs/guide/ide.md +160 -0
  42. package/docs/guide/plugins.md +316 -0
  43. package/docs/guide/production.md +374 -0
  44. package/docs/guide/testing.md +171 -0
  45. package/docs/guide/websockets.md +329 -0
  46. package/docs/migrating-to-graxia.md +408 -0
  47. package/docs/roadmap.md +122 -0
  48. package/docs/troubleshooting.md +963 -0
  49. package/package.json +69 -5
@@ -0,0 +1,21 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts", "../src/bounded-stream.ts", "../src/executor.ts", "../src/explorer.ts", "../src/operation.ts", "../src/removed.ts", "../src/options.ts", "../src/graphql.ts", "../src/endpoint.ts", "../src/handler.ts", "../src/ws.ts", "../src/once-per-request.ts"],
4
+ "sourcesContent": [
5
+ "// graxia owns these now; re-exported under alxia's names.\nexport {\n\ttype CostlessStore,\n\ttype FieldDecision,\n\ttype FieldLimit,\n\ttype FieldRateLimitOptions,\n\ttype FieldRule,\n\tfieldRateLimit,\n\ttype GraxiaErrorCode,\n\tlimitFromStore,\n} from '@softistx/graxia';\nexport { type BoundedStreamOptions, boundedStream } from './bounded-stream';\nexport {\n\ttype ExecutorCall,\n\ttype ExecutorError,\n\ttype ExecutorRequest,\n\ttype ExecutorResult,\n\ttype GraphQLExecutor,\n\ttype GraphQLExecutorOptions,\n\tgraphqlExecutor,\n} from './executor';\nexport {\n\ttype GraphQLContext,\n\ttype GraphQLContextInit,\n\ttype GraphQLOptions,\n\ttype GraphQLWsContext,\n\tgraphql,\n\ttype ServerContext,\n} from './graphql';\nexport {\n\tclearRequestCache,\n\tfreshPerMutation,\n\toncePerRequest,\n} from './once-per-request';\nexport type { SandboxOptions } from './sandbox';\nexport type { GraphQLWsOptions } from './ws';\n",
6
+ "/** What bounds a stream, and what keeps it authorized. All durations in ms. */\nexport interface BoundedStreamOptions {\n\t/** The stream ends, cleanly, after this long without an event. */\n\tidleMs: number;\n\t/** The stream ends, cleanly, this long after it began, however chatty. */\n\ttotalMs: number;\n\t/** `check` runs at least this often, also while no event comes. */\n\tcheckEveryMs: number;\n\t/**\n\t * Before an event is yielded, `check` runs when the last check is at least\n\t * this old. Default `0`: every event is checked. Raise it when events come\n\t * in bursts and one check per event would cost more than the delay of a\n\t * revocation it saves.\n\t */\n\tcheckDebounceMs?: number;\n\t/** Throws to refuse (a session that ended, a role that was lost). */\n\tcheck: () => Promise<void> | void;\n\t/** Turns what `check` (or the source) threw into the error the stream throws. Default: rethrown as is. */\n\tmapError?: (error: unknown) => unknown;\n\t/** Aborted when the client leaves: the stream ends and releases the source. */\n\tsignal?: AbortSignal;\n}\n\ntype Woke<T> =\n\t| { kind: 'read'; result: IteratorResult<T> }\n\t| { kind: 'failed'; error: unknown }\n\t| { kind: 'timer' }\n\t| { kind: 'interrupted' };\n\nconst DONE = { done: true, value: undefined } as const;\n\n/**\n * `source` bounded by an idle and a total lifetime and re-checked while it\n * lives, to return as a subscription's `subscribe` result.\n *\n * It ends, without an error, when the source ends, on the idle bound, on the\n * total bound and on `signal`'s abort. It throws `mapError(error)` (the\n * error itself by default) when `check` fails, or when the source does. The\n * source's `return()` is called at once on the consumer's `return()` (a\n * client that disconnected) and on any end, even while a read is pending: the\n * iterator is written by hand because a generator's `return()` waits behind a\n * pending `next()`. Read it one `next()` at a time, as `for await` does. No\n * timer outlives a step.\n */\nexport function boundedStream<T>(\n\tsource: AsyncIterable<T> | AsyncIterator<T>,\n\toptions: BoundedStreamOptions,\n): AsyncIterableIterator<T> {\n\tconst { idleMs, totalMs, checkEveryMs, check, signal } = options;\n\tconst debounceMs = options.checkDebounceMs ?? 0;\n\tconst mapError = options.mapError ?? ((error: unknown) => error);\n\tconst iterator: AsyncIterator<T> =\n\t\tSymbol.asyncIterator in source\n\t\t\t? (source as AsyncIterable<T>)[Symbol.asyncIterator]()\n\t\t\t: (source as AsyncIterator<T>);\n\n\tconst startedAt = Date.now();\n\tlet lastEventAt = startedAt;\n\tlet lastCheckAt = startedAt;\n\tlet finished = false;\n\tlet interrupt: (() => void) | undefined;\n\tlet pending: Promise<IteratorResult<T>> | undefined;\n\tlet released: Promise<void> | undefined;\n\n\tconst release = (): Promise<void> => {\n\t\tfinished = true;\n\t\tinterrupt?.();\n\t\treleased ??= (async () => {\n\t\t\ttry {\n\t\t\t\tawait iterator.return?.(undefined);\n\t\t\t} catch {}\n\t\t})();\n\t\treturn released;\n\t};\n\n\tconst onAbort = () => void release();\n\tif (signal?.aborted) void release();\n\telse signal?.addEventListener('abort', onAbort, { once: true });\n\tconst detach = () => signal?.removeEventListener('abort', onAbort);\n\n\tconst checked = async () => {\n\t\tawait check();\n\t\tlastCheckAt = Date.now();\n\t};\n\n\t// Waits for the source, the nearest bound or the abort, whichever is first.\n\tconst wait = (read: Promise<IteratorResult<T>>, ms: number) =>\n\t\tnew Promise<Woke<T>>((resolve) => {\n\t\t\tconst settle = (woke: Woke<T>) => {\n\t\t\t\tclearTimeout(timer);\n\t\t\t\tinterrupt = undefined;\n\t\t\t\tresolve(woke);\n\t\t\t};\n\t\t\tconst timer = setTimeout(() => settle({ kind: 'timer' }), ms);\n\t\t\tinterrupt = () => settle({ kind: 'interrupted' });\n\t\t\tread.then(\n\t\t\t\t(result) => settle({ kind: 'read', result }),\n\t\t\t\t(error: unknown) => settle({ kind: 'failed', error }),\n\t\t\t);\n\t\t});\n\n\tconst step = async (): Promise<IteratorResult<T>> => {\n\t\tfor (;;) {\n\t\t\tif (finished) return DONE;\n\t\t\tconst t = Date.now();\n\t\t\tconst left = [totalMs - (t - startedAt), idleMs - (t - lastEventAt)];\n\t\t\tif (Math.min(...left) <= 0) {\n\t\t\t\tawait release();\n\t\t\t\treturn DONE;\n\t\t\t}\n\t\t\tconst dueIn = checkEveryMs - (t - lastCheckAt);\n\t\t\tif (dueIn <= 0) {\n\t\t\t\tawait checked();\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!pending) {\n\t\t\t\tpending = iterator.next();\n\t\t\t\tpending.catch(() => {});\n\t\t\t}\n\t\t\tconst woke = await wait(pending, Math.max(1, Math.min(dueIn, ...left)));\n\t\t\tif (woke.kind === 'interrupted') {\n\t\t\t\tawait release();\n\t\t\t\treturn DONE;\n\t\t\t}\n\t\t\tif (woke.kind === 'timer') continue;\n\t\t\tpending = undefined;\n\t\t\tif (woke.kind === 'failed') throw woke.error;\n\t\t\tif (woke.result.done) {\n\t\t\t\tawait release();\n\t\t\t\treturn DONE;\n\t\t\t}\n\t\t\tlastEventAt = Date.now();\n\t\t\tif (lastEventAt - lastCheckAt >= debounceMs) await checked();\n\t\t\tif (finished) return DONE;\n\t\t\treturn { done: false, value: woke.result.value };\n\t\t}\n\t};\n\n\tconst stream: AsyncIterableIterator<T> = {\n\t\t[Symbol.asyncIterator]: () => stream,\n\t\tnext: async () => {\n\t\t\ttry {\n\t\t\t\tconst result = await step();\n\t\t\t\tif (result.done) detach();\n\t\t\t\treturn result;\n\t\t\t} catch (error) {\n\t\t\t\tawait release();\n\t\t\t\tdetach();\n\t\t\t\tthrow mapError(error);\n\t\t\t}\n\t\t},\n\t\treturn: async () => {\n\t\t\tawait release();\n\t\t\tdetach();\n\t\t\treturn DONE;\n\t\t},\n\t};\n\treturn stream;\n}\n",
7
+ "import type { Empty } from '@softistx/alxia';\nimport { createGraxia, type GraxiaOptions } from '@softistx/graxia';\nimport type { GraphQLSchema } from 'graphql';\nimport { graxiaOptions, type LegacyOptions } from './options';\n\n/** What an in-process call asks for: a GraphQL-over-HTTP request's parameters. */\nexport interface ExecutorRequest {\n\treadonly query: string;\n\treadonly operationName?: string | undefined;\n\treadonly variables?: Readonly<Record<string, unknown>> | undefined;\n}\n\n/** A plain, JSON-shaped error, as the route answers it. */\nexport interface ExecutorError {\n\treadonly message: string;\n\treadonly path?: readonly (string | number)[];\n\treadonly locations?: readonly { line: number; column: number }[];\n\treadonly extensions?: Readonly<Record<string, unknown>>;\n}\n\n/** The answer: `data` and `errors`, as the endpoint's JSON body. */\nexport interface ExecutorResult {\n\treadonly data?: unknown;\n\treadonly errors?: readonly ExecutorError[];\n}\n\n/** Per call: the signal that stops the operation, as a client leaving does. */\nexport interface ExecutorCall {\n\t/**\n\t * An aborted signal, before the call or while it runs, resolves to\n\t * `{ errors: [{ extensions: { code: 'OPERATION_ABORTED' } }] }`: it never rejects.\n\t */\n\treadonly signal?: AbortSignal;\n}\n\nexport interface GraphQLExecutorOptions<SchemaCtx = unknown>\n\textends Omit<\n\t\t\tGraxiaOptions<any, GraphQLSchema, any, any>,\n\t\t\t'path' | 'schema' | 'subscriptions' | 'context' | 'plugins'\n\t\t>,\n\t\tLegacyOptions {\n\treadonly schema: GraphQLSchema & { readonly '~context'?: SchemaCtx };\n\treadonly context?: GraxiaOptions['context'];\n\treadonly plugins?: GraxiaOptions['plugins'];\n}\n\n/** Runs one operation in process. */\nexport type GraphQLExecutor<ServerCtx> = ((\n\trequest: ExecutorRequest,\n\tcontext: ServerCtx,\n\tcall?: ExecutorCall,\n) => Promise<ExecutorResult>) & {\n\t/** Releases what the instance holds (plugins' `onDispose`, in-flight operations). A call after it rejects. */\n\tdispose(): Promise<void>;\n};\n\n/** A `GraphQLError` as its plain shape; an error that is already plain stays. */\nfunction plain(error: { toJSON?: () => ExecutorError }): ExecutorError {\n\treturn typeof error.toJSON === 'function'\n\t\t? error.toJSON()\n\t\t: (error as ExecutorError);\n}\n\n/** Runs a GraphQL operation in the process, through `graxia.execute`. Queries and mutations only (graxia refuses a subscription). */\nexport function graphqlExecutor<\n\tSchemaCtx,\n\tServerCtx = Omit<SchemaCtx, 'signal'>,\n>(options: GraphQLExecutorOptions<SchemaCtx>): GraphQLExecutor<ServerCtx> {\n\tconst graxia = createGraxia({\n\t\t...graxiaOptions(\n\t\t\t{ ...options, ide: false },\n\t\t\t{ ws: false, caller: 'graphqlExecutor(' },\n\t\t),\n\t\tcsrf: false,\n\t\tsubscriptions: { sse: false, ws: false },\n\t} as never);\n\tconst run = async (\n\t\trequest: ExecutorRequest,\n\t\tcontext: ServerCtx,\n\t\tcall?: ExecutorCall,\n\t): Promise<ExecutorResult> => {\n\t\tconst body = await (graxia.execute as any)({\n\t\t\tdocument: request.query,\n\t\t\t...(request.operationName !== undefined && {\n\t\t\t\toperationName: request.operationName,\n\t\t\t}),\n\t\t\t...(request.variables !== undefined && {\n\t\t\t\tvariables: request.variables,\n\t\t\t}),\n\t\t\t...(call?.signal !== undefined && { signal: call.signal }),\n\t\t\tserverContext: context,\n\t\t});\n\t\treturn {\n\t\t\t...(body.data !== undefined && { data: body.data }),\n\t\t\t...(body.errors !== undefined && {\n\t\t\t\terrors: body.errors.map(plain),\n\t\t\t}),\n\t\t};\n\t};\n\treturn Object.assign(run, { dispose: () => graxia.dispose() });\n}\nexport type { Empty };\n",
8
+ "/** The IDE of `graphql()`: graxia's GraphiQL or Apollo Sandbox plugin, from alxia's `ide` options. */\n\nimport type { GraxiaPlugin } from '@softistx/graxia';\nimport {\n\ttype ApolloSandboxOptions,\n\tapolloSandbox,\n\ttype GraphiQLOptions,\n\tgraphiql,\n\ttype SandboxInitialState,\n} from '@softistx/graxia-graphiql';\nimport type { SandboxOptions } from './sandbox';\n\n/**\n * The requests the endpoint handler has seen, with the app's dev flag at the\n * moment of each: what the IDE's `enabled` function reads, since graxia hands\n * it the `Request` alone.\n */\nexport type DevOfRequest = WeakMap<Request, boolean>;\n\nexport interface ExplorerOptions {\n\treadonly ide?: 'graphiql' | 'apollo-sandbox' | false | undefined;\n\treadonly graphiql?: GraphiQLOptions | false | undefined;\n\treadonly sandbox?: SandboxOptions | undefined;\n}\n\n/** Defined, by key, so an unset option leaves the default of the plugin alone. */\nfunction defined<T extends object>(\n\tvalues: { [K in keyof T]?: T[K] | undefined },\n): T {\n\treturn Object.fromEntries(\n\t\tObject.entries(values).filter(([, value]) => value !== undefined),\n\t) as T;\n}\n\nfunction sandboxPlugin(\n\tsandbox: SandboxOptions | undefined,\n): GraxiaPlugin<any, any> {\n\tconst options: ApolloSandboxOptions = {\n\t\tenabled: true,\n\t\t...defined<ApolloSandboxOptions>({ title: sandbox?.title }),\n\t\tinitialState: defined<SandboxInitialState>({\n\t\t\tdocument: sandbox?.initialDocument,\n\t\t\theaders: sandbox?.initialHeaders as Record<string, string> | undefined,\n\t\t\tincludeCookies: sandbox?.includeCookies,\n\t\t}),\n\t};\n\treturn apolloSandbox(options) as GraxiaPlugin<any, any>;\n}\n\n/**\n * The IDE plugins: Sandbox for `ide: 'apollo-sandbox'`, nothing for\n * `ide: false` or `graphiql: false`, GraphiQL otherwise. By default GraphiQL\n * answers while the serving app is in dev (`alxia({ dev })`, else\n * `NODE_ENV=development`, read per request from `devs`, which the endpoint\n * handler fills), and everywhere under `ide: 'graphiql'`.\n */\nexport function explorerPlugins(\n\toptions: ExplorerOptions,\n\tdevs: DevOfRequest,\n): GraxiaPlugin<any, any>[] {\n\tconst { ide, graphiql: graphiqlOptions, sandbox } = options;\n\tif (ide === 'apollo-sandbox') return [sandboxPlugin(sandbox)];\n\tif (ide === false || graphiqlOptions === false) return [];\n\treturn [\n\t\tgraphiql({\n\t\t\tenabled:\n\t\t\t\tide === 'graphiql' ? true : (request) => devs.get(request) === true,\n\t\t\t...graphiqlOptions,\n\t\t}) as GraxiaPlugin<any, any>,\n\t];\n}\n",
9
+ "/**\n * The plugin that tells the observers around the endpoint — `@softistx/alxia-logger`,\n * `@softistx/alxia-telemetry` — which operation graxia runs. Over HTTP it reports the\n * request's operation (`reportOperation`). Over a WebSocket, whose upgrade\n * was answered long before, it starts and ends each operation\n * (`startOperation`) from graxia's `onExecute` and `onSubscribe` hooks and\n * the operation's `signal`, as graxia's guide to observing each socket\n * operation describes; a document refused by validation never executes, so\n * `onValidate` tells that one, finding the socket through the `serverContext`\n * graxia gives it. A throwing subscription source reaches `onResultChunk` as\n * an error chunk, which ends the operation with errors. Under `@defer` and\n * `@stream` over a socket, the operation ends with its last payload, with\n * `errors` when one carried errors, or once with the outcome so far when its\n * client leaves.\n */\nimport {\n\ttype OperationOutcome,\n\treportOperation,\n\tstartOperation,\n} from '@softistx/alxia';\nimport { createStateKey, definePlugin } from '@softistx/graxia';\nimport {\n\ttype DocumentNode,\n\ttype ExperimentalIncrementalExecutionResults,\n\tgetOperationAST,\n\ttype LegacyExperimentalIncrementalExecutionResults,\n} from 'graphql';\n\ntype Report = Parameters<typeof reportOperation>[1];\n\nconst nameKey = createStateKey<string | null>('alxia-operation-name');\nconst openKey = createStateKey<{ outcome: OperationOutcome }>(\n\t'alxia-operation-open',\n);\n\ninterface Executed {\n\treadonly document: DocumentNode;\n\treadonly operationName?: string | null | undefined;\n\treadonly contextValue: unknown;\n}\n\nfunction describe(\n\tdocument: DocumentNode,\n\tname: string | null | undefined,\n): Report | undefined {\n\tconst operation = getOperationAST(document, name);\n\tif (operation === undefined || operation === null) return undefined;\n\treturn { type: operation.operation, name: operation.name?.value };\n}\n\nconst isStream = (result: unknown): boolean =>\n\ttypeof result === 'object' &&\n\tresult !== null &&\n\tSymbol.asyncIterator in result;\n\ntype IncrementalResults =\n\t| ExperimentalIncrementalExecutionResults\n\t| LegacyExperimentalIncrementalExecutionResults;\n\n/** An `@defer`/`@stream` result: its first payload, then the rest (graxia's own guard). */\nconst isIncremental = (result: unknown): result is IncrementalResults =>\n\ttypeof result === 'object' &&\n\tresult !== null &&\n\t'initialResult' in result &&\n\ttypeof (result as { subsequentResults?: { next?: unknown } })\n\t\t.subsequentResults?.next === 'function';\n\n/** A payload with errors: its own, or one of its `incremental` or `completed` entries. */\nconst carriesErrors = (chunk: unknown): boolean => {\n\tif (typeof chunk !== 'object' || chunk === null) return false;\n\tconst payload = chunk as {\n\t\terrors?: unknown;\n\t\tincremental?: unknown;\n\t\tcompleted?: unknown;\n\t};\n\tif (Array.isArray(payload.errors) && payload.errors.length > 0) return true;\n\treturn [payload.incremental, payload.completed].some(\n\t\t(entries) =>\n\t\t\tArray.isArray(entries) &&\n\t\t\tentries.some(\n\t\t\t\t(entry) =>\n\t\t\t\t\ttypeof entry === 'object' &&\n\t\t\t\t\tentry !== null &&\n\t\t\t\t\tArray.isArray((entry as { errors?: unknown }).errors) &&\n\t\t\t\t\t(entry as { errors: unknown[] }).errors.length > 0,\n\t\t\t),\n\t);\n};\n\n/**\n * `chunks`, ending the operation once: when it is done, when a payload\n * rejects (`errors`), or when its client leaves (`return`), with the outcome\n * so far. A plain iterator and not a generator, so that `return()` reaches\n * `chunks` at once even while a `next()` is pending, as graxia's source needs.\n */\nfunction observed<Chunks extends AsyncGenerator<unknown, void, void>>(\n\tchunks: Chunks,\n\tprogress: { outcome: OperationOutcome },\n\tend: (outcome: OperationOutcome) => void,\n): Chunks {\n\tconst wrapped = {\n\t\tasync next() {\n\t\t\ttry {\n\t\t\t\tconst step = await chunks.next();\n\t\t\t\tif (step.done === true) end(progress.outcome);\n\t\t\t\telse if (carriesErrors(step.value)) progress.outcome = 'errors';\n\t\t\t\treturn step;\n\t\t\t} catch (error) {\n\t\t\t\tprogress.outcome = 'errors';\n\t\t\t\tend('errors');\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t},\n\t\treturn(value?: void) {\n\t\t\tend(progress.outcome);\n\t\t\treturn chunks.return(value);\n\t\t},\n\t\tthrow(error?: unknown) {\n\t\t\treturn chunks.throw(error);\n\t\t},\n\t\t[Symbol.asyncIterator]() {\n\t\t\treturn wrapped;\n\t\t},\n\t};\n\t// graphql's generator type also asks for `Symbol.asyncDispose`, which\n\t// graxia never calls: the cast stands for that one member.\n\treturn wrapped as unknown as Chunks;\n}\n\nconst failed = (result: unknown): OperationOutcome =>\n\ttypeof result === 'object' && result !== null && 'errors' in result\n\t\t? 'errors'\n\t\t: 'ok';\n\n/** A graxia plugin reporting each operation graxia executes or subscribes to. */\nexport function reportsOperations() {\n\treturn definePlugin({\n\t\tname: 'alxia-report-operations',\n\t\tonParse: ({ params, state }) => {\n\t\t\tstate.set(nameKey, params.operationName ?? null);\n\t\t},\n\t\tonValidate: ({ document, serverContext, state }) => {\n\t\t\treturn ({ errors }) => {\n\t\t\t\tif (errors === undefined || errors.length === 0) return;\n\t\t\t\tconst report = describe(document, state.get(nameKey));\n\t\t\t\tif (report !== undefined)\n\t\t\t\t\tstartOperation(serverContext, report)('errors');\n\t\t\t};\n\t\t},\n\t\tonExecute: ({ args }) => {\n\t\t\tconst { document, operationName, contextValue } = args as Executed;\n\t\t\tconst report = describe(document, operationName);\n\t\t\tif (report === undefined) return;\n\t\t\treportOperation(contextValue as object, report);\n\t\t\tconst end = startOperation(contextValue as object, report);\n\t\t\treturn ({ result, setResult }) => {\n\t\t\t\tif (!isIncremental(result)) return end(failed(result));\n\t\t\t\t// `@defer`/`@stream`: the operation lasts until its last payload, or\n\t\t\t\t// until its client leaves.\n\t\t\t\tconst progress = {\n\t\t\t\t\toutcome: carriesErrors(result.initialResult)\n\t\t\t\t\t\t? ('errors' as const)\n\t\t\t\t\t\t: ('ok' as const),\n\t\t\t\t};\n\t\t\t\tconst signal = (contextValue as { signal?: AbortSignal }).signal;\n\t\t\t\tconst onAbort = () => finish(progress.outcome);\n\t\t\t\tconst finish = (outcome: OperationOutcome) => {\n\t\t\t\t\tsignal?.removeEventListener('abort', onAbort);\n\t\t\t\t\tend(outcome);\n\t\t\t\t};\n\t\t\t\tsignal?.addEventListener('abort', onAbort, { once: true });\n\t\t\t\tconst subsequentResults = observed(\n\t\t\t\t\tresult.subsequentResults,\n\t\t\t\t\tprogress,\n\t\t\t\t\tfinish,\n\t\t\t\t);\n\t\t\t\t// The spread of a union keeps both formats' members apart, so\n\t\t\t\t// TypeScript cannot see the result as one of them again.\n\t\t\t\tsetResult({ ...result, subsequentResults } as typeof result);\n\t\t\t};\n\t\t},\n\t\tonSubscribe: ({ args, state }) => {\n\t\t\tconst { document, operationName, contextValue } = args as Executed;\n\t\t\tconst report = describe(document, operationName);\n\t\t\tif (report === undefined) return;\n\t\t\tconst context = contextValue as { signal?: AbortSignal };\n\t\t\treportOperation(context, report);\n\t\t\tconst end = startOperation(context, report);\n\t\t\tconst open = { outcome: 'ok' as OperationOutcome };\n\t\t\tstate.set(openKey, open);\n\t\t\tcontext.signal?.addEventListener('abort', () => end(open.outcome), {\n\t\t\t\tonce: true,\n\t\t\t});\n\t\t\t// A stream is created; a refusal arrives as a result, not a stream.\n\t\t\treturn ({ result }) => {\n\t\t\t\tif (isStream(result)) return;\n\t\t\t\topen.outcome = failed(result);\n\t\t\t\tend(open.outcome);\n\t\t\t};\n\t\t},\n\t\tonResultChunk: ({ chunk, state }) => {\n\t\t\tconst open = state.get(openKey);\n\t\t\tif (open !== undefined && failed(chunk) === 'errors') {\n\t\t\t\topen.outcome = 'errors';\n\t\t\t}\n\t\t},\n\t});\n}\n",
10
+ "/** The options of the Yoga endpoint that no longer exist, refused with the fix. */\nexport interface RemovedOptions {\n\t/** Removed: unexpected failures go to graxia's `onUnexpected` (`console.error`, off in production); log requests with `@softistx/alxia-logger`. */\n\treadonly logging?: never;\n\t/** Removed: graxia generates its own `x-request-id` and never echoes the client's; the app's own id is `@softistx/alxia`'s. */\n\treadonly requestId?: never;\n\t/** Removed: mount `@softistx/alxia-cors` on the app before `graphql()`. */\n\treadonly cors?: never;\n\t/** Removed with `sameOrigin()`: use `csrf: { sameOrigin: true }` (off by default; the CSRF header check is on). */\n\treadonly sameOrigin?: never;\n}\n\nconst FIXES: Readonly<Record<string, string>> = {\n\tlogging:\n\t\t\"`logging` was Yoga's. Unexpected failures go to graxia's `onUnexpected` (console.error by default, off in production); log requests with `@softistx/alxia-logger`\",\n\trequestId:\n\t\t\"`requestId` was Yoga's. Graxia generates its own `x-request-id` and never echoes the client's; the app's own id is `@softistx/alxia`'s\",\n\tcors: '`cors` is gone. Mount `@softistx/alxia-cors` on the app before `graphql()`',\n\tsameOrigin:\n\t\t'`sameOrigin` is gone. Use `csrf: { sameOrigin: true }` (off by default; the CSRF header check is on)',\n};\n\n/** Throws, where `graphql()` is declared, for an option that was removed. */\nexport function rejectRemoved(\n\toptions: object,\n\tcaller: 'graphql(app' | 'graphqlExecutor(' = 'graphql(app',\n): void {\n\tfor (const name of Object.keys(FIXES)) {\n\t\tif (\n\t\t\tname in options &&\n\t\t\t(options as Record<string, unknown>)[name] !== undefined\n\t\t) {\n\t\t\tconst call =\n\t\t\t\tcaller === 'graphql(app'\n\t\t\t\t\t? `graphql(app, { ${name} })`\n\t\t\t\t\t: `graphqlExecutor({ ${name} })`;\n\t\t\tthrow new TypeError(`${call}: ${FIXES[name]}`);\n\t\t}\n\t}\n}\n",
11
+ "/**\n * What `graphql()` and `graphqlExecutor()` share: alxia's options mapped\n * onto `createGraxia`'s, the legacy names (`maxTokens`, `maxNesting`,\n * `parseCache`, `maskedErrors`) kept, and the operation reporter.\n */\nimport type { GraxiaOptions } from '@softistx/graxia';\nimport {\n\ttype DevOfRequest,\n\ttype ExplorerOptions,\n\texplorerPlugins,\n} from './explorer';\nimport { reportsOperations } from './operation';\nimport { rejectRemoved } from './removed';\n\nexport type { RemovedOptions } from './removed';\n\n/** The cache sizes of the parse cache: graxia's `caches.parse`. */\nexport interface ParseCacheOptions {\n\t/** graxia's `caches.parse.maxBytes`: the estimated bytes of sources kept (64 MiB by default). */\n\treadonly maxBytes?: number;\n\treadonly max?: number;\n\t/** Milliseconds. */\n\treadonly ttl?: number;\n}\n\nexport interface LegacyOptions {\n\t/** @deprecated Use `limits: { tokens }`. Works until the next minor. */\n\treadonly maxTokens?: number | false;\n\t/** @deprecated Use `limits: { nesting }`. Works until the next minor. */\n\treadonly maxNesting?: number | false;\n\t/** @deprecated Use `caches: { parse }`, or `caches: false`. Works until the next minor. */\n\treadonly parseCache?: false | ParseCacheOptions;\n\t/** `false` is graxia's `maskErrors: false`. */\n\treadonly maskedErrors?: boolean;\n}\n\ninterface Wiring {\n\t/** Filled by the endpoint handler; the executor serves no page and gives none. */\n\treadonly devs?: DevOfRequest | undefined;\n\treadonly ws: false | { keepAlive?: number | false | undefined };\n\treadonly bodyLimit?: number | undefined;\n\t/** Whose name an error carries. */\n\treadonly caller?: 'graphqlExecutor(' | undefined;\n}\n\ntype Limits = NonNullable<GraxiaOptions['limits']>;\ntype Caches = GraxiaOptions['caches'];\ntype Subscriptions = NonNullable<GraxiaOptions['subscriptions']>;\n\nfunction limitsOf(\n\tlegacy: {\n\t\treadonly maxTokens: number | false | undefined;\n\t\treadonly maxNesting: number | false | undefined;\n\t},\n\tbodyLimit: number | undefined,\n\tlimits: GraxiaOptions['limits'],\n): Limits {\n\treturn {\n\t\t...(legacy.maxTokens === undefined ? {} : { tokens: legacy.maxTokens }),\n\t\t...(legacy.maxNesting === undefined ? {} : { nesting: legacy.maxNesting }),\n\t\t...(bodyLimit === undefined ? {} : { bodyBytes: bodyLimit }),\n\t\t...limits,\n\t};\n}\n\nfunction cachesOf(\n\tparseCache: LegacyOptions['parseCache'],\n\tcaches: Caches,\n): Caches {\n\tif (caches !== undefined) return caches;\n\tif (parseCache === undefined || parseCache === false) {\n\t\treturn parseCache === false ? false : undefined;\n\t}\n\treturn {\n\t\tparse: {\n\t\t\t...(parseCache.maxBytes === undefined\n\t\t\t\t? {}\n\t\t\t\t: { maxBytes: parseCache.maxBytes }),\n\t\t\t...(parseCache.max === undefined ? {} : { max: parseCache.max }),\n\t\t\t...(parseCache.ttl === undefined ? {} : { ttlMs: parseCache.ttl }),\n\t\t},\n\t};\n}\n\nfunction subscriptionsOf(ws: Wiring['ws']): Subscriptions {\n\tif (ws === false) return { sse: true, ws: false };\n\tconst { keepAlive } = ws;\n\tif (keepAlive === undefined) return { sse: true, ws: true };\n\treturn {\n\t\tsse: true,\n\t\tws: { keepAliveMs: keepAlive === false ? 0 : Math.ceil(keepAlive) },\n\t};\n}\n\n/**\n * @softistx/alxia-telemetry spans the operations; graxia's own operation span would\n * double it, so only its step spans (parse, validate, execute) stay, as\n * children of the active host span. The default is merged under a given\n * `telemetry` object, so one that sets only `resolverSpans` keeps it; `false`\n * turns every span off.\n */\nfunction telemetryOf(telemetry: GraxiaOptions['telemetry']) {\n\tif (telemetry === false) return false;\n\treturn { operationSpans: false, ...telemetry };\n}\n\nexport function graxiaOptions(options: object, wiring: Wiring): GraxiaOptions {\n\trejectRemoved(options, wiring.caller);\n\tconst {\n\t\tmaxTokens,\n\t\tmaxNesting,\n\t\tparseCache,\n\t\tmaskedErrors,\n\t\tide,\n\t\tgraphiql,\n\t\tsandbox,\n\t\tpath: _path,\n\t\tws: _ws,\n\t\tbodyLimit: _bodyLimit,\n\t\tplugins = [],\n\t\tlimits,\n\t\tcaches,\n\t\ttelemetry,\n\t\t...rest\n\t} = options as GraxiaOptions &\n\t\tLegacyOptions &\n\t\tExplorerOptions & {\n\t\t\tpath?: unknown;\n\t\t\tws?: unknown;\n\t\t\tbodyLimit?: unknown;\n\t\t};\n\treturn {\n\t\t...rest,\n\t\ttelemetry: telemetryOf(telemetry),\n\t\tpath: false,\n\t\tplugins: [\n\t\t\t...plugins,\n\t\t\t...explorerPlugins(\n\t\t\t\t{ ide, graphiql, sandbox },\n\t\t\t\twiring.devs ?? new WeakMap(),\n\t\t\t),\n\t\t\treportsOperations(),\n\t\t],\n\t\tlimits: limitsOf({ maxTokens, maxNesting }, wiring.bodyLimit, limits),\n\t\tcaches: cachesOf(parseCache, caches),\n\t\t...(maskedErrors === false ? { maskErrors: false } : {}),\n\t\tsubscriptions: subscriptionsOf(wiring.ws),\n\t} as GraxiaOptions;\n}\n",
12
+ "import type { Alxia, BaseContext, Empty, RoutePath } from '@softistx/alxia';\nimport {\n\ttype ContextInit,\n\ttype ContextOf,\n\ttype CoreContext,\n\tcreateGraxia,\n\ttype GraxiaOptions,\n\ttype GraxiaPlugin,\n} from '@softistx/graxia';\nimport type { GraphiQLOptions } from '@softistx/graxia-graphiql';\nimport type { GraphQLSchema } from 'graphql';\nimport { declareEndpoint } from './endpoint';\nimport type { DevOfRequest } from './explorer';\nimport { graphqlHandler } from './handler';\nimport {\n\tgraxiaOptions,\n\ttype LegacyOptions,\n\ttype RemovedOptions,\n} from './options';\nimport type { SandboxOptions } from './sandbox';\nimport { checkKeepAlive, type GraphQLWsOptions, graphqlSocket } from './ws';\n\n/** The parts of a route's context graxia owns, or that mean nothing to a resolver. */\ntype RouteOnly =\n\t| 'params'\n\t| 'query'\n\t| 'headers'\n\t| 'cookies'\n\t| 'body'\n\t| 'reply'\n\t| 'redirect';\n\n/**\n * What alxia hands graxia for each request as its `serverContext`: the\n * context its middlewares built with `request`, `url`, `ip` and `set`.\n */\nexport type ServerContext<Ctx> = Omit<BaseContext & Ctx, RouteOnly>;\n\n/** What an operation over WebSocket adds to its context: the client's `connectionParams`. */\nexport interface GraphQLWsContext {\n\treadonly connectionParams?: Readonly<Record<string, unknown>>;\n}\n\n/**\n * What a resolver reads as its context: graxia's `signal`, the app's, what\n * the `context` option adds, and over WebSocket the `connectionParams`.\n */\nexport type GraphQLContext<App, UserContext = Empty> = App extends {\n\treadonly '~context': infer Ctx;\n}\n\t? CoreContext & ServerContext<Ctx> & GraphQLWsContext & UserContext\n\t: {\n\t\t\treadonly '~error': 'GraphQLContext needs the type of an app: GraphQLContext<typeof app>';\n\t\t};\n\ntype Passed =\n\t| 'path'\n\t| 'schema'\n\t| 'context'\n\t| 'subscriptions'\n\t| 'plugins'\n\t| 'limits'\n\t| 'caches';\n\nexport interface GraphQLOptions<\n\tCtx,\n\tPath extends RoutePath,\n\tSchemaCtx = unknown,\n\tMade extends object = object,\n\tPlugins extends readonly GraxiaPlugin<any, any>[] = readonly GraxiaPlugin<\n\t\tany,\n\t\tany\n\t>[],\n> extends Omit<\n\t\t\tGraxiaOptions<ServerContext<Ctx>, GraphQLSchema, any, Made>,\n\t\t\tPassed\n\t\t>,\n\t\tLegacyOptions,\n\t\tRemovedOptions {\n\treadonly schema: GraphQLSchema & { readonly '~context'?: SchemaCtx };\n\treadonly context?: (\n\t\tinit: ContextInit<ServerContext<Ctx>>,\n\t) => Made | Promise<Made>;\n\treadonly plugins?: Plugins;\n\treadonly limits?: GraxiaOptions['limits'];\n\treadonly caches?: GraxiaOptions['caches'];\n\treadonly ide?: 'graphiql' | 'apollo-sandbox' | false;\n\treadonly graphiql?: GraphiQLOptions | false;\n\treadonly sandbox?: SandboxOptions;\n\treadonly path?: Path;\n\treadonly ws?: boolean | GraphQLWsOptions;\n\treadonly bodyLimit?: number;\n}\n\n/**\n * The parameter of a `context` factory that reads the app's `serverContext`,\n * typed from the app: `context: ({ serverContext }: GraphQLContextInit<typeof app>) => …`,\n * with no `['~context']` to write.\n */\nexport type GraphQLContextInit<App> = App extends {\n\treadonly '~context': infer Ctx;\n}\n\t? ContextInit<ServerContext<Ctx>>\n\t: {\n\t\t\treadonly '~error': 'GraphQLContextInit needs the type of an app: GraphQLContextInit<typeof app>';\n\t\t};\n\ntype ProvidesContext<Provided, Required> = Provided extends Required\n\t? unknown\n\t: {\n\t\t\treadonly schema: `the schema's resolvers read a context the app does not build: missing ${Exclude<\n\t\t\t\tkeyof Required,\n\t\t\t\tkeyof Provided\n\t\t\t> &\n\t\t\t\tstring}`;\n\t\t};\n\n/**\n * A GraphQL endpoint on `app`, served by `@softistx/graxia`: `GET` and `POST`\n * at `path`, behind every middleware given to `use` on `app` before it.\n */\nexport function graphql<\n\tCtx extends object,\n\tPrefix extends string,\n\tSchemaCtx,\n\tMade extends object = Empty,\n\tconst Path extends RoutePath = '/graphql',\n\tconst Plugins extends readonly GraxiaPlugin<\n\t\tany,\n\t\tany\n\t>[] = readonly GraxiaPlugin<any, any>[],\n>(\n\tapp: Alxia<Ctx, Prefix>,\n\toptions: GraphQLOptions<Ctx, Path, SchemaCtx, Made, Plugins> &\n\t\tProvidesContext<\n\t\t\tCoreContext & ServerContext<Ctx> & Made & ContextOf<Plugins>,\n\t\t\tSchemaCtx\n\t\t>,\n): Alxia<Ctx, Prefix> {\n\tconst { path = '/graphql' as Path, ws = false, bodyLimit } = options;\n\tif (typeof ws === 'object') checkKeepAlive(ws);\n\tconst devs: DevOfRequest = new WeakMap();\n\tdeclareEndpoint(app as never, path, bodyLimit, (bodyBytes) => {\n\t\tconst graxia = createGraxia(\n\t\t\tgraxiaOptions(options, {\n\t\t\t\tdevs,\n\t\t\t\tws: ws === false ? false : ws === true ? {} : ws,\n\t\t\t\tbodyLimit: bodyBytes,\n\t\t\t}) as never,\n\t\t);\n\t\tapp.onStop(() => graxia.dispose());\n\t\treturn {\n\t\t\thandler: graphqlHandler(graxia, devs) as never,\n\t\t\tsocket:\n\t\t\t\tws === false\n\t\t\t\t\t? undefined\n\t\t\t\t\t: graphqlSocket(graxia, path, ws === true ? {} : ws),\n\t\t};\n\t});\n\treturn app as never;\n}\n",
13
+ "import type { Alxia } from '@softistx/alxia';\nimport { GraxiaConfigError } from '@softistx/graxia';\nimport type { graphqlSocket } from './ws';\n\n/** The body limit of a `POST` when neither the option nor the app gives one: 1 MiB. */\nconst DEFAULT_BODY_LIMIT = 1_048_576;\n\n/**\n * The limit core's own counter gets on the `POST`: none in practice. graxia\n * counts the body itself (`limits.bodyBytes`) and answers `413 BODY_TOO_LARGE`;\n * a host counter would make a chunked body past it an unreadable `400`.\n */\nconst HOST_LIMIT_OFF = Number.MAX_SAFE_INTEGER;\n\n/** What `declareEndpoint` asks its caller to build once the body limit is known. */\nexport interface Mounted {\n\treadonly handler: (ctx: never) => unknown;\n\treadonly socket: ReturnType<typeof graphqlSocket> | undefined;\n}\n\n/**\n * `GET` and `POST` at `path` on `app`, and the WebSocket when `ws` is on.\n * `mount` receives the bytes graxia's `limits.bodyBytes` must hold: the\n * option, else the `bodyLimit()` the app declared before, else 1 MiB.\n * A bad limit, the option or an inherited `bodyLimit(0)` (core accepts 0,\n * graxia does not), throws before any route is declared, so the app stays\n * as it was.\n */\nexport function declareEndpoint(\n\tapp: Alxia<never, string>,\n\tpath: string,\n\tbodyLimit: number | undefined,\n\tmount: (bodyBytes: number) => Mounted,\n): void {\n\t// The explicit option first, then the limit the app already holds, both\n\t// read before anything is declared on the app (a group's app included).\n\tconst bodyBytes = bodyLimit ?? app.bodyLimitInForce ?? DEFAULT_BODY_LIMIT;\n\tif (!(Number.isInteger(bodyBytes) && bodyBytes > 0)) {\n\t\tthrow new GraxiaConfigError('limits.bodyBytes must be a positive integer');\n\t}\n\t// `Alxia<never, string>` has no typed route methods for a path given at run\n\t// time; the three used here are the app's own `get`, `post` and `ws`.\n\tconst route = app as unknown as {\n\t\tget(path: string, handler: unknown): unknown;\n\t\tpost(path: string, ...rest: unknown[]): unknown;\n\t\tws(path: string, ...rest: unknown[]): unknown;\n\t};\n\t// Built before any route is declared: graxia refuses a bad option here\n\t// (`shutdownTimeout: -1`), and the app stays as it was.\n\tconst mounted = mount(bodyBytes);\n\troute.get(path, mounted.handler);\n\troute.post(path, { bodyLimit: HOST_LIMIT_OFF }, mounted.handler);\n\tif (mounted.socket !== undefined) {\n\t\troute.ws(\n\t\t\tmounted.socket.path,\n\t\t\tmounted.socket.middleware,\n\t\t\tmounted.socket.handlers,\n\t\t);\n\t}\n}\n",
14
+ "/** The route handler of the endpoint behind `graphql()`: each request goes to graxia. */\nimport {\n\ttype BaseContext,\n\tisDev,\n\ttype StatusCode,\n\tshutdownSignal,\n} from '@softistx/alxia';\nimport type { Graxia } from '@softistx/graxia';\nimport type { DevOfRequest } from './explorer';\n\nexport type GraphQLServerContext = Record<string, any>;\n\n/** What graxia is handed as its server context: the route's, minus what a resolver has no use for. */\nexport function serverContext(\n\tctx: Record<string, unknown>,\n): Record<string, unknown> {\n\tconst {\n\t\tparams: _params,\n\t\tquery: _query,\n\t\theaders: _headers,\n\t\tcookies: _cookies,\n\t\tbody: _body,\n\t\treply: _reply,\n\t\tredirect: _redirect,\n\t\t...server\n\t} = ctx;\n\treturn server;\n}\n\nexport function graphqlHandler(graxia: Graxia<any>, devs: DevOfRequest) {\n\treturn async function graphql(\n\t\tctx: Record<string, unknown> & BaseContext & { readonly route: string },\n\t) {\n\t\tconst { reply } = ctx;\n\t\tdevs.set(ctx.request, isDev(ctx));\n\t\tconst response = await graxia.fetch(\n\t\t\tctx.request,\n\t\t\tserverContext(ctx) as never,\n\t\t);\n\t\tconst body = endedOnShutdown(response, shutdownSignal(ctx));\n\t\treturn reply(response.status as StatusCode, body ?? undefined, {\n\t\t\theaders: new Headers(response.headers),\n\t\t});\n\t};\n}\n\n/** A streaming body ended when the app starts shutting down, so the drain does not wait for it. */\nfunction endedOnShutdown(\n\tresponse: Response,\n\tsignal: AbortSignal,\n): ReadableStream<Uint8Array> | null {\n\tconst body = response.body;\n\tconst type = response.headers.get('content-type') ?? '';\n\tif (body === null || !/text\\/event-stream|multipart\\/mixed/.test(type)) {\n\t\treturn body;\n\t}\n\tconst reader = body.getReader();\n\tconst end = () => {\n\t\tsignal.removeEventListener('abort', end);\n\t\tvoid reader.cancel();\n\t\ttry {\n\t\t\tcontroller.close();\n\t\t} catch {}\n\t};\n\tlet controller: ReadableStreamDefaultController<Uint8Array>;\n\treturn new ReadableStream<Uint8Array>({\n\t\tstart(started) {\n\t\t\tcontroller = started;\n\t\t\tif (signal.aborted) end();\n\t\t\telse signal.addEventListener('abort', end, { once: true });\n\t\t},\n\t\tasync pull(controller) {\n\t\t\tconst result = await reader.read().catch((error: unknown) => {\n\t\t\t\tsignal.removeEventListener('abort', end);\n\t\t\t\tthrow error;\n\t\t\t});\n\t\t\tif (result.done) {\n\t\t\t\tsignal.removeEventListener('abort', end);\n\t\t\t\ttry {\n\t\t\t\t\tcontroller.close();\n\t\t\t\t} catch {}\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tcontroller.enqueue(result.value);\n\t\t},\n\t\tcancel: (reason) => {\n\t\t\tsignal.removeEventListener('abort', end);\n\t\t\treturn reader.cancel(reason);\n\t\t},\n\t});\n}\n",
15
+ "/**\n * GraphQL over WebSocket: the `graphql-transport-ws` protocol is graxia's.\n * alxia owns `Bun.serve`'s websocket handler, so the route's middleware asks\n * `graxia.upgrade` for the socket's data through a stand-in server that only\n * captures it, and each socket's events are handed to `graxia.websocket`.\n * graxia's `maxPayloadBytes` (1 MiB) is applied by `graxia.serve`, which\n * alxia does not use: a message is bounded by Bun's `maxPayloadLength` (16 MiB\n * by default), as the WebSocket guide says.\n */\nimport type {\n\tBaseContext,\n\tNextFunction,\n\tRoutePath,\n\tSocket,\n} from '@softistx/alxia';\nimport type { Graxia } from '@softistx/graxia';\nimport { serverContext } from './handler';\n\nexport interface GraphQLWsOptions {\n\t/** Where a client opens its socket. The endpoint's own path by default. */\n\treadonly path?: RoutePath;\n\t/** Milliseconds between pings, or `false` for none. */\n\treadonly keepAlive?: number | false;\n}\n\nconst KEY = 'graxiaSocket';\n\n/** Refuses, where `graphql()` is declared, a `keepAlive` that would ping in a loop. */\nexport function checkKeepAlive(options: GraphQLWsOptions): void {\n\tconst { keepAlive } = options;\n\tif (keepAlive === undefined || keepAlive === false) return;\n\tconst valid =\n\t\ttypeof keepAlive === 'number' &&\n\t\tNumber.isFinite(keepAlive) &&\n\t\tkeepAlive > 0 &&\n\t\tkeepAlive <= 2 ** 31 - 1;\n\tif (!valid) {\n\t\tthrow new TypeError(\n\t\t\t`graphql(app, { ws: { keepAlive: ${keepAlive} } }): keepAlive is the milliseconds between pings, a positive number up to ${2 ** 31 - 1}, or false for none`,\n\t\t);\n\t}\n}\n\nexport function graphqlSocket(\n\tgraxia: Graxia<any>,\n\tendpoint: string,\n\toptions: GraphQLWsOptions,\n) {\n\tasync function graphqlWs(ctx: BaseContext, next: NextFunction) {\n\t\tlet captured: { data: object; headers: HeadersInit } | undefined;\n\t\tconst standIn = {\n\t\t\tupgrade(\n\t\t\t\t_request: Request,\n\t\t\t\tgiven: { data: object; headers: HeadersInit },\n\t\t\t) {\n\t\t\t\tcaptured = given;\n\t\t\t\treturn true;\n\t\t\t},\n\t\t};\n\t\tconst host = serverContext(ctx as never);\n\t\tconst refused = await (graxia.upgrade as any)(ctx.request, standIn, host);\n\t\tif (refused !== undefined || captured === undefined) return refused;\n\t\tfor (const [name, value] of new Headers(captured.headers)) {\n\t\t\tctx.set.headers.set(name, value);\n\t\t}\n\t\treturn next({ [KEY]: captured.data } as never);\n\t}\n\ttype GraphQLSocket = Socket<Record<string, any> & BaseContext, unknown>;\n\tconst handlers = {\n\t\topen(socket: GraphQLSocket) {\n\t\t\tObject.assign(socket.raw.data as object, socket.data[KEY]);\n\t\t\tgraxia.websocket.open?.(socket.raw as never);\n\t\t},\n\t\tasync message(socket: GraphQLSocket, message: unknown) {\n\t\t\tawait graxia.websocket.message?.(socket.raw as never, message as never);\n\t\t},\n\t\tasync close(socket: GraphQLSocket, code: number, reason: string) {\n\t\t\tawait graxia.websocket.close?.(socket.raw as never, code, reason);\n\t\t},\n\t\tdrain(socket: GraphQLSocket) {\n\t\t\tgraxia.websocket.drain?.(socket.raw as never);\n\t\t},\n\t};\n\treturn { path: options.path ?? endpoint, middleware: graphqlWs, handlers };\n}\n",
16
+ "const caches = new WeakMap<object, Map<string, unknown>>();\n\n/**\n * A value loaded at most once per request and key. `request` is any object\n * that lives as long as the request (the resolvers' context); the cache is\n * released with it. A `load` that throws, or returns a promise that rejects,\n * is not kept, so the next call tries again.\n */\nexport function oncePerRequest<T>(\n\trequest: object,\n\tkey: string,\n\tload: () => T,\n): T {\n\tlet cache = caches.get(request);\n\tif (!cache) {\n\t\tcache = new Map();\n\t\tcaches.set(request, cache);\n\t}\n\tif (cache.has(key)) return cache.get(key) as T;\n\tconst loaded = load();\n\tcache.set(key, loaded);\n\tif (loaded instanceof Promise) {\n\t\tconst mine = cache;\n\t\tloaded.catch(() => {\n\t\t\tif (mine.get(key) === loaded) mine.delete(key);\n\t\t});\n\t}\n\treturn loaded;\n}\n\n/**\n * Forgets what `oncePerRequest` kept for this request, so the next call for\n * any key loads again. A call to `oncePerRequest` already in flight keeps its\n * own value; only later calls see the empty cache.\n */\nexport function clearRequestCache(request: object): void {\n\tcaches.delete(request);\n}\n\n/**\n * A mutation's root fields run one after the other in one request, and one\n * may change what a later one reads. `freshPerMutation(resolvers)` returns\n * the resolvers with every function of `Mutation` wrapped to call\n * `clearRequestCache(context)` before it runs: each root mutation field starts\n * with an empty cache, its own sub-fields share it, and a query (no wrapped\n * field) keeps one cache for the whole request. Other types are untouched.\n *\n * It returns the same type it was given: an array of maps (what\n * `createSchema` takes for `resolvers`) stays an array, each map wrapped on its\n * own, so graxia still merges them (a field defined twice throws there) and\n * each map stays checked.\n */\nexport function freshPerMutation<R extends object>(resolvers: R): R;\nexport function freshPerMutation(\n\tresolvers: object | readonly object[],\n): unknown {\n\tif (Array.isArray(resolvers)) {\n\t\treturn resolvers.map((map: object) => freshPerMutation(map));\n\t}\n\treturn wrapMutation(resolvers);\n}\n\nfunction wrapMutation<R extends object>(resolvers: R): R {\n\tconst mutation = (resolvers as { Mutation?: unknown }).Mutation as\n\t\t| Record<string, unknown>\n\t\t| undefined;\n\tif (!mutation) return resolvers;\n\tconst wrapped: Record<string, unknown> = {};\n\tfor (const [name, field] of Object.entries(mutation)) {\n\t\tif (typeof field !== 'function') {\n\t\t\twrapped[name] = field;\n\t\t\tcontinue;\n\t\t}\n\t\twrapped[name] = function (\n\t\t\tthis: unknown,\n\t\t\tparent: unknown,\n\t\t\targs: unknown,\n\t\t\tcontext: unknown,\n\t\t\tinfo: unknown,\n\t\t) {\n\t\t\tif (typeof context === 'object' && context !== null) {\n\t\t\t\tclearRequestCache(context);\n\t\t\t}\n\t\t\treturn field.call(this, parent, args, context, info);\n\t\t};\n\t}\n\treturn { ...resolvers, Mutation: wrapped };\n}\n"
17
+ ],
18
+ "mappings": ";AACA;AAAA;AAAA;AAAA;;;AC4BA,IAAM,OAAO,EAAE,MAAM,MAAM,OAAO,UAAU;AAerC,SAAS,aAAgB,CAC/B,QACA,SAC2B;AAAA,EAC3B,QAAQ,QAAQ,SAAS,cAAc,OAAO,WAAW;AAAA,EACzD,MAAM,aAAa,QAAQ,mBAAmB;AAAA,EAC9C,MAAM,WAAW,QAAQ,aAAa,CAAC,UAAmB;AAAA,EAC1D,MAAM,WACL,OAAO,iBAAiB,SACpB,OAA4B,OAAO,eAAe,IAClD;AAAA,EAEL,MAAM,YAAY,KAAK,IAAI;AAAA,EAC3B,IAAI,cAAc;AAAA,EAClB,IAAI,cAAc;AAAA,EAClB,IAAI,WAAW;AAAA,EACf,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,IAAI;AAAA,EAEJ,MAAM,UAAU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164756E21",
20
+ "names": []
21
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * A value loaded at most once per request and key. `request` is any object
3
+ * that lives as long as the request (the resolvers' context); the cache is
4
+ * released with it. A `load` that throws, or returns a promise that rejects,
5
+ * is not kept, so the next call tries again.
6
+ */
7
+ export declare function oncePerRequest<T>(request: object, key: string, load: () => T): T;
8
+ /**
9
+ * Forgets what `oncePerRequest` kept for this request, so the next call for
10
+ * any key loads again. A call to `oncePerRequest` already in flight keeps its
11
+ * own value; only later calls see the empty cache.
12
+ */
13
+ export declare function clearRequestCache(request: object): void;
14
+ /**
15
+ * A mutation's root fields run one after the other in one request, and one
16
+ * may change what a later one reads. `freshPerMutation(resolvers)` returns
17
+ * the resolvers with every function of `Mutation` wrapped to call
18
+ * `clearRequestCache(context)` before it runs: each root mutation field starts
19
+ * with an empty cache, its own sub-fields share it, and a query (no wrapped
20
+ * field) keeps one cache for the whole request. Other types are untouched.
21
+ *
22
+ * It returns the same type it was given: an array of maps (what
23
+ * `createSchema` takes for `resolvers`) stays an array, each map wrapped on its
24
+ * own, so graxia still merges them (a field defined twice throws there) and
25
+ * each map stays checked.
26
+ */
27
+ export declare function freshPerMutation<R extends object>(resolvers: R): R;
28
+ //# sourceMappingURL=once-per-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"once-per-request.d.ts","sourceRoot":"","sources":["../src/once-per-request.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,CAAC,EAC/B,OAAO,EAAE,MAAM,EACf,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,CAAC,GACX,CAAC,CAgBH;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAEvD;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAAE,SAAS,EAAE,CAAC,GAAG,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ /** A graxia plugin reporting each operation graxia executes or subscribes to. */
2
+ export declare function reportsOperations(): import("@softistx/graxia").GraxiaPlugin<import("@softistx/graxia").Empty, import("@softistx/graxia").Empty, "alxia-report-operations">;
3
+ //# sourceMappingURL=operation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../src/operation.ts"],"names":[],"mappings":"AAsIA,iFAAiF;AACjF,wBAAgB,iBAAiB,2IAwEhC"}
@@ -0,0 +1,38 @@
1
+ /**
2
+ * What `graphql()` and `graphqlExecutor()` share: alxia's options mapped
3
+ * onto `createGraxia`'s, the legacy names (`maxTokens`, `maxNesting`,
4
+ * `parseCache`, `maskedErrors`) kept, and the operation reporter.
5
+ */
6
+ import type { GraxiaOptions } from '@softistx/graxia';
7
+ import { type DevOfRequest } from './explorer';
8
+ export type { RemovedOptions } from './removed';
9
+ /** The cache sizes of the parse cache: graxia's `caches.parse`. */
10
+ export interface ParseCacheOptions {
11
+ /** graxia's `caches.parse.maxBytes`: the estimated bytes of sources kept (64 MiB by default). */
12
+ readonly maxBytes?: number;
13
+ readonly max?: number;
14
+ /** Milliseconds. */
15
+ readonly ttl?: number;
16
+ }
17
+ export interface LegacyOptions {
18
+ /** @deprecated Use `limits: { tokens }`. Works until the next minor. */
19
+ readonly maxTokens?: number | false;
20
+ /** @deprecated Use `limits: { nesting }`. Works until the next minor. */
21
+ readonly maxNesting?: number | false;
22
+ /** @deprecated Use `caches: { parse }`, or `caches: false`. Works until the next minor. */
23
+ readonly parseCache?: false | ParseCacheOptions;
24
+ /** `false` is graxia's `maskErrors: false`. */
25
+ readonly maskedErrors?: boolean;
26
+ }
27
+ interface Wiring {
28
+ /** Filled by the endpoint handler; the executor serves no page and gives none. */
29
+ readonly devs?: DevOfRequest | undefined;
30
+ readonly ws: false | {
31
+ keepAlive?: number | false | undefined;
32
+ };
33
+ readonly bodyLimit?: number | undefined;
34
+ /** Whose name an error carries. */
35
+ readonly caller?: 'graphqlExecutor(' | undefined;
36
+ }
37
+ export declare function graxiaOptions(options: object, wiring: Wiring): GraxiaOptions;
38
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EACN,KAAK,YAAY,EAGjB,MAAM,YAAY,CAAC;AAIpB,YAAY,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAEhD,mEAAmE;AACnE,MAAM,WAAW,iBAAiB;IACjC,iGAAiG;IACjG,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IACtB,oBAAoB;IACpB,QAAQ,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,aAAa;IAC7B,wEAAwE;IACxE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACpC,yEAAyE;IACzE,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;IACrC,2FAA2F;IAC3F,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,GAAG,iBAAiB,CAAC;IAChD,+CAA+C;IAC/C,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,UAAU,MAAM;IACf,kFAAkF;IAClF,QAAQ,CAAC,IAAI,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;IACzC,QAAQ,CAAC,EAAE,EAAE,KAAK,GAAG;QAAE,SAAS,CAAC,EAAE,MAAM,GAAG,KAAK,GAAG,SAAS,CAAA;KAAE,CAAC;IAChE,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACxC,mCAAmC;IACnC,QAAQ,CAAC,MAAM,CAAC,EAAE,kBAAkB,GAAG,SAAS,CAAC;CACjD;AA+DD,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CA0C5E"}
@@ -0,0 +1,14 @@
1
+ /** The options of the Yoga endpoint that no longer exist, refused with the fix. */
2
+ export interface RemovedOptions {
3
+ /** Removed: unexpected failures go to graxia's `onUnexpected` (`console.error`, off in production); log requests with `@softistx/alxia-logger`. */
4
+ readonly logging?: never;
5
+ /** Removed: graxia generates its own `x-request-id` and never echoes the client's; the app's own id is `@softistx/alxia`'s. */
6
+ readonly requestId?: never;
7
+ /** Removed: mount `@softistx/alxia-cors` on the app before `graphql()`. */
8
+ readonly cors?: never;
9
+ /** Removed with `sameOrigin()`: use `csrf: { sameOrigin: true }` (off by default; the CSRF header check is on). */
10
+ readonly sameOrigin?: never;
11
+ }
12
+ /** Throws, where `graphql()` is declared, for an option that was removed. */
13
+ export declare function rejectRemoved(options: object, caller?: 'graphql(app' | 'graphqlExecutor('): void;
14
+ //# sourceMappingURL=removed.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"removed.d.ts","sourceRoot":"","sources":["../src/removed.ts"],"names":[],"mappings":"AAAA,mFAAmF;AACnF,MAAM,WAAW,cAAc;IAC9B,mJAAmJ;IACnJ,QAAQ,CAAC,OAAO,CAAC,EAAE,KAAK,CAAC;IACzB,+HAA+H;IAC/H,QAAQ,CAAC,SAAS,CAAC,EAAE,KAAK,CAAC;IAC3B,2EAA2E;IAC3E,QAAQ,CAAC,IAAI,CAAC,EAAE,KAAK,CAAC;IACtB,mHAAmH;IACnH,QAAQ,CAAC,UAAU,CAAC,EAAE,KAAK,CAAC;CAC5B;AAYD,6EAA6E;AAC7E,wBAAgB,aAAa,CAC5B,OAAO,EAAE,MAAM,EACf,MAAM,GAAE,aAAa,GAAG,kBAAkC,GACxD,IAAI,CAaN"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * What `ide: 'apollo-sandbox'` gives `@softistx/graxia-graphiql`'s `apolloSandbox()`:
3
+ * the page's title and the state the Sandbox opens with.
4
+ */
5
+ export interface SandboxOptions {
6
+ /** The page's title. `Apollo Sandbox` by default. */
7
+ readonly title?: string;
8
+ /** The operation the Sandbox opens with. */
9
+ readonly initialDocument?: string;
10
+ /** Headers every operation sends, shown and editable in the Sandbox. */
11
+ readonly initialHeaders?: Readonly<Record<string, string>>;
12
+ /** Whether operations send the browser's cookies: a session cookie. On by default. */
13
+ readonly includeCookies?: boolean;
14
+ }
15
+ //# sourceMappingURL=sandbox.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sandbox.d.ts","sourceRoot":"","sources":["../src/sandbox.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,WAAW,cAAc;IAC9B,qDAAqD;IACrD,QAAQ,CAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IACxB,4CAA4C;IAC5C,QAAQ,CAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAClC,wEAAwE;IACxE,QAAQ,CAAC,cAAc,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAC3D,sFAAsF;IACtF,QAAQ,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC;CAClC"}
@@ -0,0 +1,95 @@
1
+ import { type DocumentNode, type TypedQueryDocumentNode } from 'graphql';
2
+ /**
3
+ * A document that carries its types: `graphql`'s own `TypedQueryDocumentNode`,
4
+ * or the `TypedDocumentNode` of `@graphql-typed-document-node/core` that
5
+ * GraphQL Code Generator writes, read by its `__apiType` marker. Both are a
6
+ * `DocumentNode` with an optional function, so neither package is imported.
7
+ */
8
+ export type QueryDocument<TData = unknown, TVars = Record<string, unknown>> = string | TypedQueryDocumentNode<TData extends object ? TData : never, TVars> | (DocumentNode & {
9
+ __apiType?: (variables: TVars) => TData;
10
+ });
11
+ /** One entry of a response's `errors`. */
12
+ export interface ResponseError {
13
+ readonly message: string;
14
+ readonly path?: readonly (string | number)[];
15
+ readonly extensions?: {
16
+ readonly code?: string;
17
+ readonly [key: string]: unknown;
18
+ };
19
+ }
20
+ /** What `query` resolves to: the HTTP status, the parsed body, the response. */
21
+ export interface GraphQLResult<TData = unknown> {
22
+ readonly status: number;
23
+ readonly data?: TData | null;
24
+ readonly errors?: readonly ResponseError[];
25
+ /** The response, its body still unread: `headers`, `ok`. */
26
+ readonly response: Response;
27
+ }
28
+ /** How the operation travels: a JSON body, or the URL's query string. */
29
+ export type HttpMethod = 'GET' | 'POST';
30
+ export interface GraphQLClientOptions {
31
+ /** The endpoint's path. Default `/graphql`. */
32
+ readonly path?: string;
33
+ /** Sent with every query: an `authorization` header, say. */
34
+ readonly headers?: HeadersInit;
35
+ /**
36
+ * The CSRF header a `GET` carries, graxia's `x-graphql-csrf` by default.
37
+ * Name the one the app's `csrf.requireHeader` lists instead, or `false` to
38
+ * send none (to test the refusal). A `POST` never needs it.
39
+ */
40
+ readonly csrfHeader?: string | false;
41
+ /** How a call is sent unless it says. Default `'POST'`. */
42
+ readonly method?: HttpMethod;
43
+ }
44
+ export interface QueryOptions<TVars = Record<string, unknown>> {
45
+ readonly variables?: TVars;
46
+ readonly operationName?: string;
47
+ /** Added to the client's, and replacing one of the same name. */
48
+ readonly headers?: HeadersInit;
49
+ /** This call's method, over the client's. */
50
+ readonly method?: HttpMethod;
51
+ /**
52
+ * Sent as `extensions`, beside the `persistedQuery` that `persisted`
53
+ * adds: what an app that reads an operation's id from its own extension
54
+ * (`extractPersistedOperationId`) is sent.
55
+ */
56
+ readonly extensions?: Record<string, unknown>;
57
+ /**
58
+ * The hash of a persisted operation, sent as Apollo's
59
+ * `extensions.persistedQuery: { version: 1, sha256Hash }`, the shape of
60
+ * graxia's persisted operations by default. With a
61
+ * document it is sent too; alone, only it is.
62
+ */
63
+ readonly persisted?: string;
64
+ }
65
+ /**
66
+ * A call with no document: the operation is the one `persisted` names, or
67
+ * the one an app reads from the `extensions` it is sent (an id).
68
+ */
69
+ export type PersistedQueryOptions<TVars = Record<string, unknown>> = QueryOptions<TVars> & ({
70
+ readonly persisted: string;
71
+ } | {
72
+ readonly extensions: Record<string, unknown>;
73
+ });
74
+ export interface GraphQLClient {
75
+ query<TData = unknown, TVars = Record<string, unknown>>(document: QueryDocument<TData, TVars>, options?: QueryOptions<TVars>): Promise<GraphQLResult<TData>>;
76
+ /** A persisted operation, by its hash or id alone: name `TData` yourself. */
77
+ query<TData = unknown, TVars = Record<string, unknown>>(options: PersistedQueryOptions<TVars>): Promise<GraphQLResult<TData>>;
78
+ }
79
+ /** What it calls: an alxia app, or anything with a `fetch(Request)`. */
80
+ export interface Servable {
81
+ fetch(request: Request): Response | Promise<Response>;
82
+ }
83
+ /**
84
+ * Sends operations to an app's GraphQL endpoint in process, through
85
+ * `app.fetch`: no port, no server, the whole chain (middlewares, body limit,
86
+ * graxia's plugins) in play. Meant for specs; import it from
87
+ * `@softistx/alxia-graphql/testing`, never from the app.
88
+ *
89
+ * It POSTs JSON, or with `method: 'GET'` (sending the CSRF header) puts `query`, `variables`,
90
+ * `operationName` and `extensions` in the URL. A body that is not JSON (a 413
91
+ * from a body limit, a 404) leaves `data` and `errors` unset: read `status`,
92
+ * or `response`'s headers.
93
+ */
94
+ export declare function graphqlClient(app: Servable, options?: GraphQLClientOptions): GraphQLClient;
95
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/testing/client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,YAAY,EAAS,KAAK,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAEhF;;;;;GAKG;AACH,MAAM,MAAM,aAAa,CAAC,KAAK,GAAG,OAAO,EAAE,KAAK,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IACvE,MAAM,GACN,sBAAsB,CAAC,KAAK,SAAS,MAAM,GAAG,KAAK,GAAG,KAAK,EAAE,KAAK,CAAC,GACnE,CA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C,CAAC;CACtD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,aAAa,CAC5B,GAAG,EAAE,QAAQ,EACb,OAAO,GAAE,oBAAyB,GAChC,aAAa,CAiBf"}
@@ -0,0 +1,2 @@
1
+ export { type GraphQLClient, type GraphQLClientOptions, type GraphQLResult, graphqlClient, type HttpMethod, type PersistedQueryOptions, type QueryDocument, type QueryOptions, type ResponseError, } from './client';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testing/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,aAAa,EACb,KAAK,UAAU,EACf,KAAK,qBAAqB,EAC1B,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,aAAa,GAClB,MAAM,UAAU,CAAC"}
@@ -0,0 +1,73 @@
1
+ // src/testing/client.ts
2
+ import { print } from "graphql";
3
+ var DEFAULT_CSRF_HEADER = "x-graphql-csrf";
4
+ function graphqlClient(app, options = {}) {
5
+ const { path = "/graphql" } = options;
6
+ return {
7
+ async query(first, second = {}) {
8
+ const [document, call] = isCall(first) ? [undefined, first] : [first, second];
9
+ const response = await app.fetch(buildRequest(path, document, call, options));
10
+ const text = await response.clone().text();
11
+ return { status: response.status, ...parse(text), response };
12
+ }
13
+ };
14
+ }
15
+ function isCall(value) {
16
+ return typeof value === "object" && !("kind" in value);
17
+ }
18
+ function payload(document, call) {
19
+ const extensions = {
20
+ ...call.extensions,
21
+ ...call.persisted === undefined ? {} : { persistedQuery: { version: 1, sha256Hash: call.persisted } }
22
+ };
23
+ return {
24
+ ...document === undefined ? {} : { query: typeof document === "string" ? document : print(document) },
25
+ ...call.variables === undefined ? {} : { variables: call.variables },
26
+ ...call.operationName === undefined ? {} : { operationName: call.operationName },
27
+ ...Object.keys(extensions).length === 0 ? {} : { extensions }
28
+ };
29
+ }
30
+ function buildRequest(path, document, call, client) {
31
+ const headers = new Headers(client.headers);
32
+ for (const [name, value] of new Headers(call.headers)) {
33
+ headers.set(name, value);
34
+ }
35
+ const url = new URL(path, "http://localhost");
36
+ const csrf = client.csrfHeader ?? DEFAULT_CSRF_HEADER;
37
+ const parts = payload(document, call);
38
+ if ((call.method ?? client.method ?? "POST") === "GET") {
39
+ if (csrf !== false && !headers.has(csrf))
40
+ headers.set(csrf, "1");
41
+ for (const [name, value] of Object.entries(parts)) {
42
+ url.searchParams.set(name, typeof value === "string" ? value : JSON.stringify(value));
43
+ }
44
+ return new Request(url, { method: "GET", headers });
45
+ }
46
+ headers.set("content-type", "application/json");
47
+ return new Request(url, {
48
+ method: "POST",
49
+ headers,
50
+ body: JSON.stringify(parts)
51
+ });
52
+ }
53
+ function parse(text) {
54
+ try {
55
+ const body = JSON.parse(text);
56
+ if (typeof body !== "object" || body === null || Array.isArray(body)) {
57
+ return {};
58
+ }
59
+ const { data, errors } = body;
60
+ return {
61
+ ...data === undefined ? {} : { data },
62
+ ...errors === undefined ? {} : { errors }
63
+ };
64
+ } catch {
65
+ return {};
66
+ }
67
+ }
68
+ export {
69
+ graphqlClient
70
+ };
71
+
72
+ //# debugId=2783394E46FFEAF364756E2164756E21
73
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/testing/client.ts"],
4
+ "sourcesContent": [
5
+ "import { type DocumentNode, print, type TypedQueryDocumentNode } from 'graphql';\n\n/**\n * A document that carries its types: `graphql`'s own `TypedQueryDocumentNode`,\n * or the `TypedDocumentNode` of `@graphql-typed-document-node/core` that\n * GraphQL Code Generator writes, read by its `__apiType` marker. Both are a\n * `DocumentNode` with an optional function, so neither package is imported.\n */\nexport type QueryDocument<TData = unknown, TVars = Record<string, unknown>> =\n\t| string\n\t| TypedQueryDocumentNode<TData extends object ? TData : never, TVars>\n\t| (DocumentNode & { __apiType?: (variables: TVars) => TData });\n\n/** One entry of a response's `errors`. */\nexport interface ResponseError {\n\treadonly message: string;\n\treadonly path?: readonly (string | number)[];\n\treadonly extensions?: {\n\t\treadonly code?: string;\n\t\treadonly [key: string]: unknown;\n\t};\n}\n\n/** What `query` resolves to: the HTTP status, the parsed body, the response. */\nexport interface GraphQLResult<TData = unknown> {\n\treadonly status: number;\n\treadonly data?: TData | null;\n\treadonly errors?: readonly ResponseError[];\n\t/** The response, its body still unread: `headers`, `ok`. */\n\treadonly response: Response;\n}\n\n/** How the operation travels: a JSON body, or the URL's query string. */\nexport type HttpMethod = 'GET' | 'POST';\n\nexport interface GraphQLClientOptions {\n\t/** The endpoint's path. Default `/graphql`. */\n\treadonly path?: string;\n\t/** Sent with every query: an `authorization` header, say. */\n\treadonly headers?: HeadersInit;\n\t/**\n\t * The CSRF header a `GET` carries, graxia's `x-graphql-csrf` by default.\n\t * Name the one the app's `csrf.requireHeader` lists instead, or `false` to\n\t * send none (to test the refusal). A `POST` never needs it.\n\t */\n\treadonly csrfHeader?: string | false;\n\t/** How a call is sent unless it says. Default `'POST'`. */\n\treadonly method?: HttpMethod;\n}\n\nexport interface QueryOptions<TVars = Record<string, unknown>> {\n\treadonly variables?: TVars;\n\treadonly operationName?: string;\n\t/** Added to the client's, and replacing one of the same name. */\n\treadonly headers?: HeadersInit;\n\t/** This call's method, over the client's. */\n\treadonly method?: HttpMethod;\n\t/**\n\t * Sent as `extensions`, beside the `persistedQuery` that `persisted`\n\t * adds: what an app that reads an operation's id from its own extension\n\t * (`extractPersistedOperationId`) is sent.\n\t */\n\treadonly extensions?: Record<string, unknown>;\n\t/**\n\t * The hash of a persisted operation, sent as Apollo's\n\t * `extensions.persistedQuery: { version: 1, sha256Hash }`, the shape of\n\t * graxia's persisted operations by default. With a\n\t * document it is sent too; alone, only it is.\n\t */\n\treadonly persisted?: string;\n}\n\n/**\n * A call with no document: the operation is the one `persisted` names, or\n * the one an app reads from the `extensions` it is sent (an id).\n */\nexport type PersistedQueryOptions<TVars = Record<string, unknown>> =\n\tQueryOptions<TVars> &\n\t\t(\n\t\t\t| { readonly persisted: string }\n\t\t\t| { readonly extensions: Record<string, unknown> }\n\t\t);\n\nexport interface GraphQLClient {\n\tquery<TData = unknown, TVars = Record<string, unknown>>(\n\t\tdocument: QueryDocument<TData, TVars>,\n\t\toptions?: QueryOptions<TVars>,\n\t): Promise<GraphQLResult<TData>>;\n\t/** A persisted operation, by its hash or id alone: name `TData` yourself. */\n\tquery<TData = unknown, TVars = Record<string, unknown>>(\n\t\toptions: PersistedQueryOptions<TVars>,\n\t): Promise<GraphQLResult<TData>>;\n}\n\nconst DEFAULT_CSRF_HEADER = 'x-graphql-csrf';\n\n/** What it calls: an alxia app, or anything with a `fetch(Request)`. */\nexport interface Servable {\n\tfetch(request: Request): Response | Promise<Response>;\n}\n\n/**\n * Sends operations to an app's GraphQL endpoint in process, through\n * `app.fetch`: no port, no server, the whole chain (middlewares, body limit,\n * graxia's plugins) in play. Meant for specs; import it from\n * `@softistx/alxia-graphql/testing`, never from the app.\n *\n * It POSTs JSON, or with `method: 'GET'` (sending the CSRF header) puts `query`, `variables`,\n * `operationName` and `extensions` in the URL. A body that is not JSON (a 413\n * from a body limit, a 404) leaves `data` and `errors` unset: read `status`,\n * or `response`'s headers.\n */\nexport function graphqlClient(\n\tapp: Servable,\n\toptions: GraphQLClientOptions = {},\n): GraphQLClient {\n\tconst { path = '/graphql' } = options;\n\treturn {\n\t\tasync query(\n\t\t\tfirst: QueryDocument | PersistedQueryOptions,\n\t\t\tsecond: QueryOptions = {},\n\t\t) {\n\t\t\tconst [document, call] = isCall(first)\n\t\t\t\t? [undefined, first]\n\t\t\t\t: [first, second];\n\t\t\tconst response = await app.fetch(\n\t\t\t\tbuildRequest(path, document, call, options),\n\t\t\t);\n\t\t\tconst text = await response.clone().text();\n\t\t\treturn { status: response.status, ...parse(text), response };\n\t\t},\n\t} as GraphQLClient;\n}\n\n/** A call's options, not a document: a `DocumentNode` has a `kind`. */\nfunction isCall(\n\tvalue: QueryDocument | PersistedQueryOptions,\n): value is PersistedQueryOptions {\n\treturn typeof value === 'object' && !('kind' in value);\n}\n\n/** The operation's parts, each only when the call has it. */\nfunction payload(\n\tdocument: QueryDocument | undefined,\n\tcall: QueryOptions,\n): Record<string, unknown> {\n\tconst extensions = {\n\t\t...call.extensions,\n\t\t...(call.persisted === undefined\n\t\t\t? {}\n\t\t\t: { persistedQuery: { version: 1, sha256Hash: call.persisted } }),\n\t};\n\treturn {\n\t\t...(document === undefined\n\t\t\t? {}\n\t\t\t: { query: typeof document === 'string' ? document : print(document) }),\n\t\t...(call.variables === undefined ? {} : { variables: call.variables }),\n\t\t...(call.operationName === undefined\n\t\t\t? {}\n\t\t\t: { operationName: call.operationName }),\n\t\t...(Object.keys(extensions).length === 0 ? {} : { extensions }),\n\t};\n}\n\nfunction buildRequest(\n\tpath: string,\n\tdocument: QueryDocument | undefined,\n\tcall: QueryOptions,\n\tclient: GraphQLClientOptions,\n): Request {\n\tconst headers = new Headers(client.headers);\n\tfor (const [name, value] of new Headers(call.headers)) {\n\t\theaders.set(name, value);\n\t}\n\tconst url = new URL(path, 'http://localhost');\n\tconst csrf = client.csrfHeader ?? DEFAULT_CSRF_HEADER;\n\tconst parts = payload(document, call);\n\tif ((call.method ?? client.method ?? 'POST') === 'GET') {\n\t\tif (csrf !== false && !headers.has(csrf)) headers.set(csrf, '1');\n\t\t// `variables` and `extensions` are JSON in the URL.\n\t\tfor (const [name, value] of Object.entries(parts)) {\n\t\t\turl.searchParams.set(\n\t\t\t\tname,\n\t\t\t\ttypeof value === 'string' ? value : JSON.stringify(value),\n\t\t\t);\n\t\t}\n\t\treturn new Request(url, { method: 'GET', headers });\n\t}\n\theaders.set('content-type', 'application/json');\n\treturn new Request(url, {\n\t\tmethod: 'POST',\n\t\theaders,\n\t\tbody: JSON.stringify(parts),\n\t});\n}\n\n/** `data` and `errors` of a JSON object body, each only when it has one. */\nfunction parse<TData>(text: string): {\n\tdata?: TData | null;\n\terrors?: readonly ResponseError[];\n} {\n\ttry {\n\t\tconst body: unknown = JSON.parse(text);\n\t\tif (typeof body !== 'object' || body === null || Array.isArray(body)) {\n\t\t\treturn {};\n\t\t}\n\t\tconst { data, errors } = body as Record<string, unknown>;\n\t\treturn {\n\t\t\t...(data === undefined ? {} : { data: data as TData | null }),\n\t\t\t...(errors === undefined\n\t\t\t\t? {}\n\t\t\t\t: { errors: errors as readonly ResponseError[] }),\n\t\t};\n\t} catch {\n\t\treturn {};\n\t}\n}\n"
6
+ ],
7
+ "mappings": ";AAAA;AA8FA,IAAM,sBAAsB;AAkBrB,SAAS,aAAa,CAC5B,KACA,UAAgC,CAAC,GACjB;AAAA,EAChB,QAAQ,OAAO,eAAe;AAAA,EAC9B,OAAO;AAAA,UACA,KAAK,CACV,OACA,SAAuB,CAAC,GACvB;AAAA,MACD,OAAO,UAAU,QAAQ,OAAO,KAAK,IAClC,CAAC,WAAW,KAAK,IACjB,CAAC,OAAO,MAAM;AAAA,MACjB,MAAM,WAAW,MAAM,IAAI,MAC1B,aAAa,MAAM,UAAU,MAAM,OAAO,CAC3C;AAAA,MACA,MAAM,OAAO,MAAM,SAAS,MAAM,EAAE,KAAK;AAAA,MACzC,OAAO,EAAE,QAAQ,SAAS,WAAW,MAAM,IAAI,GAAG,SAAS;AAAA;AAAA,EAE7D;AAAA;AAID,SAAS,MAAM,CACd,OACiC;AAAA,EACjC,OAAO,OAAO,UAAU,YAAY,EAAE,UAAU;AAAA;AAIjD,SAAS,OAAO,CACf,UACA,MAC0B;AAAA,EAC1B,MAAM,aAAa;AAAA,OACf,KAAK;AAAA,OACJ,KAAK,cAAc,YACpB,CAAC,IACD,EAAE,gBAAgB,EAAE,SAAS,GAAG,YAAY,KAAK,UAAU,EAAE;AAAA,EACjE;AAAA,EACA,OAAO;AAAA,OACF,aAAa,YACd,CAAC,IACD,EAAE,OAAO,OAAO,aAAa,WAAW,WAAW,MAAM,QAAQ,EAAE;AAAA,OAClE,KAAK,cAAc,YAAY,CAAC,IA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G;AAAA,MACrE,OAAO,CAAC;AAAA,IACT;AAAA,IACA,QAAQ,MAAM,WAAW;AAAA,IACzB,OAAO;AAAA,SACF,SAAS,YAAY,CAAC,IAAI,EAAE,KAA2B;AAAA,SACvD,WAAW,YACZ,CAAC,IACD,EAAE,OAA2C;AAAA,IACjD;AAAA,IACC,MAAM;AAAA,IACP,OAAO,CAAC;AAAA;AAAA;",
8
+ "debugId": "2783394E46FFEAF364756E2164756E21",
9
+ "names": []
10
+ }
package/dist/ws.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ /**
2
+ * GraphQL over WebSocket: the `graphql-transport-ws` protocol is graxia's.
3
+ * alxia owns `Bun.serve`'s websocket handler, so the route's middleware asks
4
+ * `graxia.upgrade` for the socket's data through a stand-in server that only
5
+ * captures it, and each socket's events are handed to `graxia.websocket`.
6
+ * graxia's `maxPayloadBytes` (1 MiB) is applied by `graxia.serve`, which
7
+ * alxia does not use: a message is bounded by Bun's `maxPayloadLength` (16 MiB
8
+ * by default), as the WebSocket guide says.
9
+ */
10
+ import type { BaseContext, NextFunction, RoutePath, Socket } from '@softistx/alxia';
11
+ import type { Graxia } from '@softistx/graxia';
12
+ export interface GraphQLWsOptions {
13
+ /** Where a client opens its socket. The endpoint's own path by default. */
14
+ readonly path?: RoutePath;
15
+ /** Milliseconds between pings, or `false` for none. */
16
+ readonly keepAlive?: number | false;
17
+ }
18
+ /** Refuses, where `graphql()` is declared, a `keepAlive` that would ping in a loop. */
19
+ export declare function checkKeepAlive(options: GraphQLWsOptions): void;
20
+ export declare function graphqlSocket(graxia: Graxia<any>, endpoint: string, options: GraphQLWsOptions): {
21
+ path: string;
22
+ middleware: (ctx: BaseContext, next: NextFunction) => Promise<any>;
23
+ handlers: {
24
+ open(socket: Socket<Record<string, any> & BaseContext, unknown>): void;
25
+ message(socket: Socket<Record<string, any> & BaseContext, unknown>, message: unknown): Promise<void>;
26
+ close(socket: Socket<Record<string, any> & BaseContext, unknown>, code: number, reason: string): Promise<void>;
27
+ drain(socket: Socket<Record<string, any> & BaseContext, unknown>): void;
28
+ };
29
+ };
30
+ //# sourceMappingURL=ws.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ws.d.ts","sourceRoot":"","sources":["../src/ws.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EACX,WAAW,EACX,YAAY,EACZ,SAAS,EACT,MAAM,EACN,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAG/C,MAAM,WAAW,gBAAgB;IAChC,2EAA2E;IAC3E,QAAQ,CAAC,IAAI,CAAC,EAAE,SAAS,CAAC;IAC1B,uDAAuD;IACvD,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,KAAK,CAAC;CACpC;AAID,uFAAuF;AACvF,wBAAgB,cAAc,CAAC,OAAO,EAAE,gBAAgB,GAAG,IAAI,CAa9D;AAED,wBAAgB,aAAa,CAC5B,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,EACnB,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,gBAAgB;;sBAEK,WAAW,QAAQ,YAAY;;;qFAyBd,OAAO;gFAGZ,MAAM,UAAU,MAAM;;;EAQhE"}
package/docs/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # @softistx/alxia-graphql documentation
2
+
3
+ The [package README](../README.md) is the short version. This folder is
4
+ the long one: a guide page per area, with the options, defaults, errors and
5
+ a realistic example for each.
6
+
7
+ ## Guide
8
+
9
+ | Page | Read it when |
10
+ | --- | --- |
11
+ | [Mounting the endpoint](guide/endpoint.md) | adding GraphQL to an app, choosing its path under a prefix, putting it behind a guard, reading what it answers, telling GraphQL errors from the problem details of the HTTP layer around it, adding `health()` probes and draining it on `SIGTERM`, or its first spec |
12
+ | [The typed context](guide/context.md) | typing a schema with the app's context, reading `user` or a database handle in a resolver, setting a cookie, adding per-request loaders or a value loaded once per request (`oncePerRequest`, emptied per root mutation field by `freshPerMutation`), or reading the `missing …` compile error |
13
+ | [Plugins and options](guide/plugins.md) | adding graxia or Envelop plugins, exposing or masking errors, batching, serving subscriptions, bounding them with `boundedStream`, or calling the endpoint from another origin |
14
+ | [Migrating to graxia](migrating-to-graxia.md) | moving an app from the Yoga-based `@softistx/alxia-graphql` to graxia: peers, the curried `createSchema`, plugins, options, CSRF headers and refusal codes |
15
+ | [GraphQL over WebSocket](guide/websockets.md) | serving Apollo Client's, urql's or `graphql-ws`'s WebSocket clients with `ws: true`, guarding the upgrade, reading `connectionParams`, the subprotocol, closing the sockets on shutdown, or testing a subscription over a socket |
16
+ | [Running operations in process](guide/executor.md) | calling the schema from an MCP tool, a job or a script with `graphqlExecutor`: the same plugins, limits and error masking as the route, a server context you pass, a signal, what it leaves out |
17
+ | [Harden it for production](guide/production.md) | putting a GraphQL API on the internet: rate limiting the endpoint, counting a field selected under aliases (`fieldRateLimit`), depth limits, the token cap, the nesting cap, the parse cache and the body limit, introspection off outside development, masked errors and the errors a client may read, a body limit, CSRF for a cookie session (`csrf`), persisted operations |
18
+ | [GraphiQL and Apollo Sandbox](guide/ide.md) | choosing the IDE a browser gets, configuring it, keeping it working under a strict `Content-Security-Policy`, or serving it outside dev with `ide: 'graphiql'` |
19
+ | [Testing the endpoint](guide/testing.md) | testing a GraphQL app without a server: `graphqlClient`, an auth header, a custom path, `GET`, persisted operations, the CSRF header, a typed document, the HTTP status of a 400 or a 413 |
20
+ | [Troubleshooting](troubleshooting.md) | something went wrong and you have the message |
21
+ | [Roadmap](roadmap.md) | wondering what is coming, and what is not planned |
22
+
23
+ ## Recipes
24
+
25
+ A task that crosses packages, in [the repository's recipes](https://github.com/softistx/alxia/blob/develop/docs/recipes/README.md), each with a complete example:
26
+
27
+ - [A GraphQL API](https://github.com/softistx/alxia/blob/develop/docs/recipes/graphql-api.md): typed resolvers, a viewer, subscriptions, GraphiQL, auth errors and the drain
28
+ - [Authenticate requests](https://github.com/softistx/alxia/blob/develop/docs/recipes/authentication.md): a bearer token or a cookie session, a role check, the user typed in every handler
29
+ - [Test an alxia app](https://github.com/softistx/alxia/blob/develop/docs/recipes/testing.md): `app.request`, a middleware alone, the typed client, sockets, Redis
30
+ - [Health checks and graceful shutdown](https://github.com/softistx/alxia/blob/develop/docs/recipes/health-and-shutdown.md): probes, the drain, Docker and Kubernetes
31
+ - [Deploy with Docker](https://github.com/softistx/alxia/blob/develop/docs/recipes/deploying.md): the build stage, the final image, `NODE_ENV=production`