@ocap/gql 1.30.23 → 1.30.25

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/README.md CHANGED
@@ -13,3 +13,18 @@ Then:
13
13
  ```javascript
14
14
  // TODO
15
15
  ```
16
+
17
+ ## Fetch-native runtimes (Cloudflare Workers / Durable Objects)
18
+
19
+ `@ocap/gql/http` exposes the HTTP engine without `node:http`, express or the `@arcblock/ws` server:
20
+
21
+ ```ts
22
+ import { createFetchHandler } from '@ocap/gql/http';
23
+
24
+ const handler = createFetchHandler({ resolver, introspection: false, graphiql: false });
25
+ // (request: Request) => Promise<Response>
26
+ ```
27
+
28
+ It enforces the same guards as `createHttpHandler` (query depth, batch size, 100kb body cap, introspection/GraphiQL
29
+ off unless enabled). `process.env.NODE_ENV` is usually unset on Workers, so pass `introspection` / `graphiql`
30
+ explicitly there.
package/esm/http.d.mts ADDED
@@ -0,0 +1,66 @@
1
+ import { GraphQLError } from "graphql";
2
+ import { IResolver, IResolverContext, TPageInfo } from "@ocap/types";
3
+ import { RequestHandler } from "express";
4
+
5
+ //#region src/http.d.ts
6
+ interface ResolverResult {
7
+ paging?: TPageInfo;
8
+ [key: string]: any;
9
+ }
10
+ interface WrapResolverResult {
11
+ code: string;
12
+ page: TPageInfo | Record<string, never> | null;
13
+ [key: string]: any;
14
+ }
15
+ declare const wrapResolver: (_name: string, keys: string | string[], callback: () => Promise<ResolverResult | null> | ResolverResult | null | string) => Promise<WrapResolverResult>;
16
+ interface RequestContext {
17
+ headers?: Record<string, string>;
18
+ ip?: string;
19
+ _remoteAddress?: string;
20
+ connection?: {
21
+ remoteAddress?: string;
22
+ };
23
+ }
24
+ declare const formatContext: (ctx?: RequestContext) => IResolverContext;
25
+ type Resolver = IResolver;
26
+ type ResolverFn = (args: unknown, ctx: unknown) => Promise<WrapResolverResult>;
27
+ declare const createResolvers: (resolver: Resolver) => Record<string, ResolverFn>;
28
+ interface HttpHandlerOptions {
29
+ resolver?: IResolver;
30
+ onError?: (err: GraphQLError) => void;
31
+ graphiql?: boolean;
32
+ introspection?: boolean;
33
+ showStack?: boolean;
34
+ maxQueryDepth?: number;
35
+ }
36
+ /**
37
+ * Transport-agnostic view of an incoming GraphQL request, so the same engine serves express (`createHttpHandler`)
38
+ * and fetch-native runtimes such as Cloudflare Workers (`createFetchHandler`).
39
+ */
40
+ interface GqlRequestLike {
41
+ method: string;
42
+ /** Request target, path plus optional `?query` string. */
43
+ url: string;
44
+ /** Lower-cased header names. */
45
+ headers: Record<string, string | string[] | undefined>;
46
+ /** Body already parsed by upstream middleware (express.json()), if any. */
47
+ body?: unknown;
48
+ /** Read the raw body as utf-8, rejecting with `status: 413` above `limit` bytes. */
49
+ readBody: (limit: number) => Promise<string>;
50
+ }
51
+ /** Transport-agnostic response produced by the engine. */
52
+ interface GqlResponseLike {
53
+ status: number;
54
+ headers: Record<string, string>;
55
+ body: string;
56
+ }
57
+ /** Express / connect adapter. Behavior is unchanged from the pre-split `createHttpHandler`. */
58
+ declare const createHttpHandler: (options: HttpHandlerOptions) => RequestHandler;
59
+ /**
60
+ * Fetch-native adapter (Cloudflare Workers / Durable Objects, Deno, Bun): `(Request) => Promise<Response>`.
61
+ * Same engine, same guards (depth limit, batch guard, introspection off in production, 100kb body cap) as
62
+ * `createHttpHandler`; no `node:http`, no express and no WebSocket server are imported.
63
+ */
64
+ declare const createFetchHandler: (options: HttpHandlerOptions) => (request: globalThis.Request) => Promise<globalThis.Response>;
65
+ //#endregion
66
+ export { GqlRequestLike, GqlResponseLike, HttpHandlerOptions, type Resolver, createFetchHandler, createHttpHandler, createResolvers, formatContext, wrapResolver };