@softistx/alxia-graphql 0.0.0-stage → 0.19.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.
- package/LICENSE +21 -0
- package/README.md +445 -2
- package/dist/bounded-stream.d.ts +37 -0
- package/dist/bounded-stream.d.ts.map +1 -0
- package/dist/endpoint.d.ts +17 -0
- package/dist/endpoint.d.ts.map +1 -0
- package/dist/executor.d.ts +49 -0
- package/dist/executor.d.ts.map +1 -0
- package/dist/explorer.d.ts +24 -0
- package/dist/explorer.d.ts.map +1 -0
- package/dist/graphql.d.ts +63 -0
- package/dist/graphql.d.ts.map +1 -0
- package/dist/handler.d.ts +11 -0
- package/dist/handler.d.ts.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +621 -0
- package/dist/index.js.map +21 -0
- package/dist/once-per-request.d.ts +28 -0
- package/dist/once-per-request.d.ts.map +1 -0
- package/dist/operation.d.ts +3 -0
- package/dist/operation.d.ts.map +1 -0
- package/dist/options.d.ts +38 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/removed.d.ts +14 -0
- package/dist/removed.d.ts.map +1 -0
- package/dist/sandbox.d.ts +15 -0
- package/dist/sandbox.d.ts.map +1 -0
- package/dist/testing/client.d.ts +95 -0
- package/dist/testing/client.d.ts.map +1 -0
- package/dist/testing/index.d.ts +2 -0
- package/dist/testing/index.d.ts.map +1 -0
- package/dist/testing/index.js +73 -0
- package/dist/testing/index.js.map +10 -0
- package/dist/ws.d.ts +30 -0
- package/dist/ws.d.ts.map +1 -0
- package/docs/README.md +31 -0
- package/docs/guide/context.md +351 -0
- package/docs/guide/endpoint.md +293 -0
- package/docs/guide/executor.md +75 -0
- package/docs/guide/ide.md +160 -0
- package/docs/guide/plugins.md +316 -0
- package/docs/guide/production.md +374 -0
- package/docs/guide/testing.md +171 -0
- package/docs/guide/websockets.md +329 -0
- package/docs/migrating-to-graxia.md +408 -0
- package/docs/roadmap.md +122 -0
- package/docs/troubleshooting.md +963 -0
- package/package.json +69 -5
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import type { Alxia, BaseContext, Empty, RoutePath } from '@softistx/alxia';
|
|
2
|
+
import { type ContextInit, type ContextOf, type CoreContext, type GraxiaOptions, type GraxiaPlugin } from '@softistx/graxia';
|
|
3
|
+
import type { GraphiQLOptions } from '@softistx/graxia-graphiql';
|
|
4
|
+
import type { GraphQLSchema } from 'graphql';
|
|
5
|
+
import { type LegacyOptions, type RemovedOptions } from './options';
|
|
6
|
+
import type { SandboxOptions } from './sandbox';
|
|
7
|
+
import { type GraphQLWsOptions } from './ws';
|
|
8
|
+
/** The parts of a route's context graxia owns, or that mean nothing to a resolver. */
|
|
9
|
+
type RouteOnly = 'params' | 'query' | 'headers' | 'cookies' | 'body' | 'reply' | 'redirect';
|
|
10
|
+
/**
|
|
11
|
+
* What alxia hands graxia for each request as its `serverContext`: the
|
|
12
|
+
* context its middlewares built with `request`, `url`, `ip` and `set`.
|
|
13
|
+
*/
|
|
14
|
+
export type ServerContext<Ctx> = Omit<BaseContext & Ctx, RouteOnly>;
|
|
15
|
+
/** What an operation over WebSocket adds to its context: the client's `connectionParams`. */
|
|
16
|
+
export interface GraphQLWsContext {
|
|
17
|
+
readonly connectionParams?: Readonly<Record<string, unknown>>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* What a resolver reads as its context: graxia's `signal`, the app's, what
|
|
21
|
+
* the `context` option adds, and over WebSocket the `connectionParams`.
|
|
22
|
+
*/
|
|
23
|
+
export type GraphQLContext<App, UserContext = Empty> = App extends {
|
|
24
|
+
readonly '~context': infer Ctx;
|
|
25
|
+
} ? CoreContext & ServerContext<Ctx> & GraphQLWsContext & UserContext : {
|
|
26
|
+
readonly '~error': 'GraphQLContext needs the type of an app: GraphQLContext<typeof app>';
|
|
27
|
+
};
|
|
28
|
+
type Passed = 'path' | 'schema' | 'context' | 'subscriptions' | 'plugins' | 'limits' | 'caches';
|
|
29
|
+
export interface GraphQLOptions<Ctx, Path extends RoutePath, SchemaCtx = unknown, Made extends object = object, Plugins extends readonly GraxiaPlugin<any, any>[] = readonly GraxiaPlugin<any, any>[]> extends Omit<GraxiaOptions<ServerContext<Ctx>, GraphQLSchema, any, Made>, Passed>, LegacyOptions, RemovedOptions {
|
|
30
|
+
readonly schema: GraphQLSchema & {
|
|
31
|
+
readonly '~context'?: SchemaCtx;
|
|
32
|
+
};
|
|
33
|
+
readonly context?: (init: ContextInit<ServerContext<Ctx>>) => Made | Promise<Made>;
|
|
34
|
+
readonly plugins?: Plugins;
|
|
35
|
+
readonly limits?: GraxiaOptions['limits'];
|
|
36
|
+
readonly caches?: GraxiaOptions['caches'];
|
|
37
|
+
readonly ide?: 'graphiql' | 'apollo-sandbox' | false;
|
|
38
|
+
readonly graphiql?: GraphiQLOptions | false;
|
|
39
|
+
readonly sandbox?: SandboxOptions;
|
|
40
|
+
readonly path?: Path;
|
|
41
|
+
readonly ws?: boolean | GraphQLWsOptions;
|
|
42
|
+
readonly bodyLimit?: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The parameter of a `context` factory that reads the app's `serverContext`,
|
|
46
|
+
* typed from the app: `context: ({ serverContext }: GraphQLContextInit<typeof app>) => …`,
|
|
47
|
+
* with no `['~context']` to write.
|
|
48
|
+
*/
|
|
49
|
+
export type GraphQLContextInit<App> = App extends {
|
|
50
|
+
readonly '~context': infer Ctx;
|
|
51
|
+
} ? ContextInit<ServerContext<Ctx>> : {
|
|
52
|
+
readonly '~error': 'GraphQLContextInit needs the type of an app: GraphQLContextInit<typeof app>';
|
|
53
|
+
};
|
|
54
|
+
type ProvidesContext<Provided, Required> = Provided extends Required ? unknown : {
|
|
55
|
+
readonly schema: `the schema's resolvers read a context the app does not build: missing ${Exclude<keyof Required, keyof Provided> & string}`;
|
|
56
|
+
};
|
|
57
|
+
/**
|
|
58
|
+
* A GraphQL endpoint on `app`, served by `@softistx/graxia`: `GET` and `POST`
|
|
59
|
+
* at `path`, behind every middleware given to `use` on `app` before it.
|
|
60
|
+
*/
|
|
61
|
+
export declare function graphql<Ctx extends object, Prefix extends string, SchemaCtx, Made extends object = Empty, const Path extends RoutePath = '/graphql', const Plugins extends readonly GraxiaPlugin<any, any>[] = readonly GraxiaPlugin<any, any>[]>(app: Alxia<Ctx, Prefix>, options: GraphQLOptions<Ctx, Path, SchemaCtx, Made, Plugins> & ProvidesContext<CoreContext & ServerContext<Ctx> & Made & ContextOf<Plugins>, SchemaCtx>): Alxia<Ctx, Prefix>;
|
|
62
|
+
export {};
|
|
63
|
+
//# sourceMappingURL=graphql.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql.d.ts","sourceRoot":"","sources":["../src/graphql.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5E,OAAO,EACN,KAAK,WAAW,EAChB,KAAK,SAAS,EACd,KAAK,WAAW,EAEhB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAI7C,OAAO,EAEN,KAAK,aAAa,EAClB,KAAK,cAAc,EACnB,MAAM,WAAW,CAAC;AACnB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChD,OAAO,EAAkB,KAAK,gBAAgB,EAAiB,MAAM,MAAM,CAAC;AAE5E,sFAAsF;AACtF,KAAK,SAAS,GACX,QAAQ,GACR,OAAO,GACP,SAAS,GACT,SAAS,GACT,MAAM,GACN,OAAO,GACP,UAAU,CAAC;AAEd;;;GAGG;AACH,MAAM,MAAM,aAAa,CAAC,GAAG,IAAI,IAAI,CAAC,WAAW,GAAG,GAAG,EAA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AAG,EAAE,GAAG,CAAC,EAAE,EAEvC,GAAG,EAAE,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,EACvB,OAAO,EAAE,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,CAAC,GAC3D,eAAe,CACd,WAAW,GAAG,aAAa,CAAC,GAAG,CAAC,GAAG,IAAI,GAAG,SAAS,CAAC,OAAO,CAAC,EAC5D,SAAS,CACT,GACA,KAAK,CAAC,GAAG,EAAE,MAAM,CAAC,CAsBpB"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** The route handler of the endpoint behind `graphql()`: each request goes to graxia. */
|
|
2
|
+
import { type BaseContext, type StatusCode } from '@softistx/alxia';
|
|
3
|
+
import type { Graxia } from '@softistx/graxia';
|
|
4
|
+
import type { DevOfRequest } from './explorer';
|
|
5
|
+
export type GraphQLServerContext = Record<string, any>;
|
|
6
|
+
/** What graxia is handed as its server context: the route's, minus what a resolver has no use for. */
|
|
7
|
+
export declare function serverContext(ctx: Record<string, unknown>): Record<string, unknown>;
|
|
8
|
+
export declare function graphqlHandler(graxia: Graxia<any>, devs: DevOfRequest): (ctx: Record<string, unknown> & BaseContext & {
|
|
9
|
+
readonly route: string;
|
|
10
|
+
}) => Promise<import("@softistx/alxia").Reply<StatusCode, ReadableStream<Uint8Array<ArrayBufferLike>>>>;
|
|
11
|
+
//# sourceMappingURL=handler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../src/handler.ts"],"names":[],"mappings":"AAAA,yFAAyF;AACzF,OAAO,EACN,KAAK,WAAW,EAEhB,KAAK,UAAU,EAEf,MAAM,iBAAiB,CAAC;AACzB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/C,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAEvD,sGAAsG;AACtG,wBAAgB,aAAa,CAC5B,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC1B,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAYzB;AAED,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,YAAY,IAEpE,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,WAAW,GAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,uGAaxE"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { type CostlessStore, type FieldDecision, type FieldLimit, type FieldRateLimitOptions, type FieldRule, fieldRateLimit, type GraxiaErrorCode, limitFromStore, } from '@softistx/graxia';
|
|
2
|
+
export { type BoundedStreamOptions, boundedStream } from './bounded-stream';
|
|
3
|
+
export { type ExecutorCall, type ExecutorError, type ExecutorRequest, type ExecutorResult, type GraphQLExecutor, type GraphQLExecutorOptions, graphqlExecutor, } from './executor';
|
|
4
|
+
export { type GraphQLContext, type GraphQLContextInit, type GraphQLOptions, type GraphQLWsContext, graphql, type ServerContext, } from './graphql';
|
|
5
|
+
export { clearRequestCache, freshPerMutation, oncePerRequest, } from './once-per-request';
|
|
6
|
+
export type { SandboxOptions } from './sandbox';
|
|
7
|
+
export type { GraphQLWsOptions } from './ws';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EACN,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,qBAAqB,EAC1B,KAAK,SAAS,EACd,cAAc,EACd,KAAK,eAAe,EACpB,cAAc,GACd,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,KAAK,oBAAoB,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAC5E,OAAO,EACN,KAAK,YAAY,EACjB,KAAK,aAAa,EAClB,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,sBAAsB,EAC3B,eAAe,GACf,MAAM,YAAY,CAAC;AACpB,OAAO,EACN,KAAK,cAAc,EACnB,KAAK,kBAAkB,EACvB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,OAAO,EACP,KAAK,aAAa,GAClB,MAAM,WAAW,CAAC;AACnB,OAAO,EACN,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,GACd,MAAM,oBAAoB,CAAC;AAC5B,YAAY,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAChD,YAAY,EAAE,gBAAgB,EAAE,MAAM,MAAM,CAAC"}
|