diff options
| author | netop://ウィビ <paul@webb.page> | 2026-04-24 07:43:33 -0700 |
|---|---|---|
| committer | netop://ウィビ <paul@webb.page> | 2026-04-24 07:43:33 -0700 |
| commit | 4c6194c4c2b5506f6d482347b0c13033ef17b5c7 (patch) | |
| tree | 310b315b23487b9a44da94cd21a970f6cc95c831 /source/utility | |
| download | gq-4c6194c4c2b5506f6d482347b0c13033ef17b5c7.tar.gz gq-4c6194c4c2b5506f6d482347b0c13033ef17b5c7.zip | |
initial commit
Diffstat (limited to 'source/utility')
| -rwxr-xr-x | source/utility/types.ts | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/source/utility/types.ts b/source/utility/types.ts new file mode 100755 index 0000000..0d8b443 --- /dev/null +++ b/source/utility/types.ts @@ -0,0 +1,55 @@ + + + +/*** IMPORT ------------------------------------------- ***/ + +import type { GraphQLArgs, GraphQLSchema } from "graphql"; + +/*** UTILITY ------------------------------------------ ***/ + +import type { RenderPageOptions } from "../graphiql/render.ts"; + +interface MutationParams { + mutation: string; + operationName?: string; + query?: never; + variables?: Record<string, unknown>; +} + +interface QueryParams { + mutation?: never; + operationName?: string; + query: string; + variables?: Record<string, unknown>; +} + +/*** EXPORT ------------------------------------------- ***/ + +/** + * Configuration accepted by `GraphQLHTTP` and `runHttpQuery`. + * + * Extends `GraphQLArgs` from `graphql-js` minus `source` (supplied per request). + */ +export interface GQLOptions<Context, Req extends GQLRequest = GQLRequest> extends Omit<GraphQLArgs, "source"> { + /** Builds the context value passed to resolvers. Runs per request. */ + context?: (val: Req) => Context | Promise<Context>; + /** Serve the GraphQL Playground on `GET` + `Accept: text/html`. */ + graphiql?: boolean; + /** Extra headers merged into every response. */ + headers?: HeadersInit; + /** Passthrough options for the Playground renderer (minus `endpoint`). */ + playgroundOptions?: Omit<RenderPageOptions, "endpoint">; + /** The executable schema to query against. */ + schema: GraphQLSchema; +} + +/** A single GraphQL operation — either a `query` or a `mutation`, never both. */ +export type GraphQLParams = QueryParams | MutationParams; + +/** Minimal Fetch-shaped request accepted by the HTTP handler. */ +export type GQLRequest = { + headers: Headers; + json: () => Promise<GraphQLParams>; + method: string; + url: string; +}; |