@glubean/graphql 0.1.7 → 0.2.1
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 +433 -0
- package/dist/contract/adapter.d.ts +27 -0
- package/dist/contract/adapter.d.ts.map +1 -0
- package/dist/contract/adapter.js +543 -0
- package/dist/contract/adapter.js.map +1 -0
- package/dist/contract/factory.d.ts +34 -0
- package/dist/contract/factory.d.ts.map +1 -0
- package/dist/contract/factory.js +90 -0
- package/dist/contract/factory.js.map +1 -0
- package/dist/contract/index.d.ts +37 -0
- package/dist/contract/index.d.ts.map +1 -0
- package/dist/contract/index.js +55 -0
- package/dist/contract/index.js.map +1 -0
- package/dist/contract/matchers.d.ts +95 -0
- package/dist/contract/matchers.d.ts.map +1 -0
- package/dist/contract/matchers.js +246 -0
- package/dist/contract/matchers.js.map +1 -0
- package/dist/contract/types.d.ts +369 -0
- package/dist/contract/types.d.ts.map +1 -0
- package/dist/contract/types.js +41 -0
- package/dist/contract/types.js.map +1 -0
- package/dist/index.d.ts +24 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -7
- package/dist/index.js.map +1 -1
- package/package.json +6 -2
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GraphQL contract types.
|
|
3
|
+
*
|
|
4
|
+
* User-facing authoring types + adapter-level payload types for the
|
|
5
|
+
* GraphQL contract adapter (single-package model — see
|
|
6
|
+
* `internal/40-discovery/proposals/contract-grpc-graphql-expansion.md` §6.1).
|
|
7
|
+
*
|
|
8
|
+
* Structure mirrors `packages/grpc/src/contract/types.ts` where applicable,
|
|
9
|
+
* with GraphQL-specific design:
|
|
10
|
+
*
|
|
11
|
+
* - **Target model:** GraphQL typically has a single `/graphql` endpoint,
|
|
12
|
+
* so `endpoint` is spec-level (not per-case). `endpoint` is
|
|
13
|
+
* **projection-only** in Phase 1 — it travels on `meta.endpoint`
|
|
14
|
+
* for markdown / scanner / MCP display, but the adapter dispatches
|
|
15
|
+
* through the supplied `GraphQLClient` whose endpoint was fixed at
|
|
16
|
+
* construction time. Multi-endpoint is expressed by multiple
|
|
17
|
+
* clients, not by per-contract endpoint strings. Contract identity
|
|
18
|
+
* = `contractId + caseKey`, NOT operationName (proposal §3.2).
|
|
19
|
+
*
|
|
20
|
+
* - **Selection-set-per-case coupling (proposal §3.2 b):** unlike
|
|
21
|
+
* HTTP/gRPC where response shape is determined by endpoint/method,
|
|
22
|
+
* GraphQL response shape is determined by the *query string* in each
|
|
23
|
+
* case. Each case therefore carries its own `query` + `variables` +
|
|
24
|
+
* `responseSchema` triple. A contract-level `responseSchema` may still
|
|
25
|
+
* apply if all cases share the same selection set (rare).
|
|
26
|
+
*
|
|
27
|
+
* - **Explicit type declarations (proposal §7b.2):** `types` is a
|
|
28
|
+
* deferred projection hint for Phase 2 SDL generation. Phase 1 stores
|
|
29
|
+
* it as opaque metadata — adapter / scanner carry it forward so
|
|
30
|
+
* projection tooling can consume it later.
|
|
31
|
+
*
|
|
32
|
+
* - **3-layer classifyFailure (proposal §3.2 c):**
|
|
33
|
+
* transport (HTTP status 4xx/5xx/network)
|
|
34
|
+
* → payload errors (GraphQL `errors` array, HTTP 200)
|
|
35
|
+
* → data shape mismatch (schema validation on `data`)
|
|
36
|
+
*
|
|
37
|
+
* - **Phase 1 scope:** query + mutation only (subscriptions deferred
|
|
38
|
+
* to Phase 2 streaming work).
|
|
39
|
+
*/
|
|
40
|
+
import type { SchemaLike, TestContext } from "@glubean/sdk";
|
|
41
|
+
import type { CaseDefaultRun, CaseRequires, CaseSeverity, Extensions } from "@glubean/sdk";
|
|
42
|
+
import type { GraphQLClient, GraphQLError } from "../index.js";
|
|
43
|
+
/**
|
|
44
|
+
* Field-map declaration for a GraphQL type. Kept minimal and stringly-typed
|
|
45
|
+
* so the declaration surface can evolve without a breaking bump.
|
|
46
|
+
*
|
|
47
|
+
* Phase 1 stores this as opaque metadata. Phase 2 `.gql` projection will
|
|
48
|
+
* consume it — see proposal §7b.2.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* types: {
|
|
53
|
+
* User: { id: "ID!", name: "String!", orders: "[Order!]!" },
|
|
54
|
+
* Order: { id: "ID!", total: "Float!" },
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export type GraphqlTypeDef = Record<string, string>;
|
|
59
|
+
/**
|
|
60
|
+
* Map of type-name → field declaration. Optional; when present, projection
|
|
61
|
+
* tools can emit SDL alongside the per-case markdown.
|
|
62
|
+
*/
|
|
63
|
+
export type GraphqlTypeDefs = Record<string, GraphqlTypeDef>;
|
|
64
|
+
/**
|
|
65
|
+
* Defaults for a GraphQL contract instance
|
|
66
|
+
* (`contract.graphql.with("name", {...})`).
|
|
67
|
+
*
|
|
68
|
+
* The `client` binding is the primary reason to use `.with`: supplying a
|
|
69
|
+
* pre-configured GraphQLClient lets the adapter call through it without
|
|
70
|
+
* rebuilding per contract. The GraphQLClient is itself bound to an
|
|
71
|
+
* endpoint at construction time (via `createGraphQLClient(http, { endpoint })`
|
|
72
|
+
* or the `graphql({ endpoint })` plugin factory) — the contract layer
|
|
73
|
+
* does not override that at runtime.
|
|
74
|
+
*/
|
|
75
|
+
export interface GraphqlContractDefaults {
|
|
76
|
+
/** Default GraphQL client for all contracts in this instance. */
|
|
77
|
+
client?: GraphQLClient;
|
|
78
|
+
/**
|
|
79
|
+
* Default endpoint **for projection / display only.**
|
|
80
|
+
*
|
|
81
|
+
* This value travels on the projection meta (`meta.endpoint`) so the
|
|
82
|
+
* scanner, `glubean contracts` markdown, and MCP surfaces can show
|
|
83
|
+
* which endpoint the contract points at. At runtime the adapter
|
|
84
|
+
* dispatches through the supplied `client`, whose endpoint was fixed
|
|
85
|
+
* at client-construction time. Changing `endpoint` here does **not**
|
|
86
|
+
* redirect the live call — use a different client instead
|
|
87
|
+
* (e.g. `api_v1 = graphql({endpoint: "/v1/graphql"})`,
|
|
88
|
+
* `api_v2 = graphql({endpoint: "/v2/graphql"})`).
|
|
89
|
+
*/
|
|
90
|
+
endpoint?: string;
|
|
91
|
+
/** Tags inherited by all contracts in this instance. */
|
|
92
|
+
tags?: string[];
|
|
93
|
+
/** Default feature grouping key. */
|
|
94
|
+
feature?: string;
|
|
95
|
+
/** Default headers merged into every case. */
|
|
96
|
+
headers?: Record<string, string>;
|
|
97
|
+
/** OpenAPI-style extensions (x-* keys). Inherited by all contracts. */
|
|
98
|
+
extensions?: Extensions;
|
|
99
|
+
}
|
|
100
|
+
export interface GraphqlContractExample<T = unknown> {
|
|
101
|
+
value: T;
|
|
102
|
+
summary?: string;
|
|
103
|
+
description?: string;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Sentinel values for the `errors` expectation.
|
|
107
|
+
*
|
|
108
|
+
* - `"absent"` — `errors` must be undefined or empty (strict success).
|
|
109
|
+
* - `"any"` — accept any errors (only useful with `data` partial match).
|
|
110
|
+
* - `GraphQLError[]` — match each listed error by `message` / `extensions.code`
|
|
111
|
+
* (partial — unlisted errors still fail unless length check relaxed).
|
|
112
|
+
*/
|
|
113
|
+
export type GraphqlErrorsExpect = "absent" | "any" | Array<Partial<GraphQLError>>;
|
|
114
|
+
/**
|
|
115
|
+
* Response expectations for a GraphQL case.
|
|
116
|
+
*
|
|
117
|
+
* GraphQL success is nuanced: `errors` may be present alongside `data`
|
|
118
|
+
* (partial success). The adapter's 3-layer `classifyFailure` handles the
|
|
119
|
+
* interpretation. At expect-time:
|
|
120
|
+
*
|
|
121
|
+
* - `data` — partial shape to match against `response.data`.
|
|
122
|
+
* - `errors` — sentinel or array (see `GraphqlErrorsExpect`).
|
|
123
|
+
* - `schema` — per-case Zod/Valibot schema for `data` (selection-set
|
|
124
|
+
* coupling lives here — each case owns its response shape).
|
|
125
|
+
* - `httpStatus` — transport-layer assertion (4xx/5xx for negative cases).
|
|
126
|
+
*/
|
|
127
|
+
export interface GraphqlContractExpect<T = unknown> {
|
|
128
|
+
/** Expected HTTP status (from the underlying POST). Default: 200. */
|
|
129
|
+
httpStatus?: number;
|
|
130
|
+
/** Per-case response schema (selection-set-coupled). */
|
|
131
|
+
schema?: SchemaLike<T>;
|
|
132
|
+
/** Partial expected `data` shape (toMatchObject semantics). */
|
|
133
|
+
data?: Partial<T>;
|
|
134
|
+
/** Assertion on GraphQL `errors` array. Default: `"absent"`. */
|
|
135
|
+
errors?: GraphqlErrorsExpect;
|
|
136
|
+
/** Schema for response headers. */
|
|
137
|
+
headers?: SchemaLike<Record<string, string | string[]>>;
|
|
138
|
+
/** Partial expected response headers. */
|
|
139
|
+
headersMatch?: Record<string, string>;
|
|
140
|
+
/** Single response example (for docs / projection). */
|
|
141
|
+
example?: T;
|
|
142
|
+
/** Named response examples. */
|
|
143
|
+
examples?: Record<string, GraphqlContractExample<T>>;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* One case on a GraphQL contract.
|
|
147
|
+
*
|
|
148
|
+
* Each case owns its own `query` string — the selection-set is
|
|
149
|
+
* per-case (proposal §3.2 b). Function-valued fields (`variables`,
|
|
150
|
+
* `headers`) reference case-local setup state; in flow mode these are
|
|
151
|
+
* rejected by `validateCaseForFlow`, same discipline as HTTP.
|
|
152
|
+
*/
|
|
153
|
+
export interface GraphqlContractCase<Vars = Record<string, unknown>, Res = unknown, S = void> {
|
|
154
|
+
/** Per-case client override. */
|
|
155
|
+
client?: GraphQLClient;
|
|
156
|
+
/** Why this case exists — required. */
|
|
157
|
+
description: string;
|
|
158
|
+
/**
|
|
159
|
+
* Operation type. Defaults to `"query"` when omitted.
|
|
160
|
+
* Phase 1: `query | mutation`. `subscription` is Phase 2 (streaming).
|
|
161
|
+
*/
|
|
162
|
+
operation?: "query" | "mutation";
|
|
163
|
+
/**
|
|
164
|
+
* GraphQL document. Required per case (selection-set is per-case).
|
|
165
|
+
*
|
|
166
|
+
* Can be authored inline, via the `gql` tagged template, or loaded from
|
|
167
|
+
* a `.gql` file via `fromGql()`.
|
|
168
|
+
*/
|
|
169
|
+
query: string;
|
|
170
|
+
/** Optional operationName override. If omitted, parsed from `query`. */
|
|
171
|
+
operationName?: string;
|
|
172
|
+
/** Expected response. */
|
|
173
|
+
expect?: GraphqlContractExpect<Res>;
|
|
174
|
+
/**
|
|
175
|
+
* Variables. Object shorthand or a function of setup state.
|
|
176
|
+
* Merged deep-style over `defaults.variables` → `spec.defaultVariables`.
|
|
177
|
+
*/
|
|
178
|
+
variables?: Vars | ((state: S) => Vars);
|
|
179
|
+
/** Per-call headers (merged with instance + contract defaults). */
|
|
180
|
+
headers?: Record<string, string> | ((state: S) => Record<string, string>);
|
|
181
|
+
/** Setup runs before the call. Return value flows to variables/headers fn + teardown. */
|
|
182
|
+
setup?: (ctx: TestContext) => Promise<S>;
|
|
183
|
+
/** Teardown runs after verify, even on failure. */
|
|
184
|
+
teardown?: (ctx: TestContext, state: S) => Promise<void>;
|
|
185
|
+
/** Business-logic verify — runs after transport + schema + data match. */
|
|
186
|
+
verify?: (ctx: TestContext, res: GraphqlCaseResult<Res>) => void | Promise<void>;
|
|
187
|
+
/** Not yet executable; reason shown in skip message. */
|
|
188
|
+
deferred?: string;
|
|
189
|
+
/** Deprecated; value is the reason. */
|
|
190
|
+
deprecated?: string;
|
|
191
|
+
/** Additional tags (merged with contract-level tags). */
|
|
192
|
+
tags?: string[];
|
|
193
|
+
severity?: CaseSeverity;
|
|
194
|
+
requires?: CaseRequires;
|
|
195
|
+
defaultRun?: CaseDefaultRun;
|
|
196
|
+
/** Per-case extensions. */
|
|
197
|
+
extensions?: Extensions;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Result of running a single case. This is also the `CaseOutput` shape that
|
|
201
|
+
* flow `step.out(state, res)` lens receives.
|
|
202
|
+
*
|
|
203
|
+
* Mirrors `GraphQLResult<T>` from the transport layer (CG-10) plus the
|
|
204
|
+
* parsed `operationName` for display/routing. Kept as a distinct type so
|
|
205
|
+
* adapter-layer additions (e.g. assertion diagnostics) can grow
|
|
206
|
+
* independently of the transport envelope.
|
|
207
|
+
*/
|
|
208
|
+
export interface GraphqlCaseResult<Res = unknown> {
|
|
209
|
+
/** Decoded `data` field (null if all fields errored or transport failed). */
|
|
210
|
+
data: Res | null;
|
|
211
|
+
/** GraphQL `errors` array (undefined when absent). */
|
|
212
|
+
errors?: GraphQLError[];
|
|
213
|
+
/** GraphQL `extensions` (server-side tracing/cost/etc). */
|
|
214
|
+
extensions?: Record<string, unknown>;
|
|
215
|
+
/** HTTP status from the underlying POST. */
|
|
216
|
+
httpStatus: number;
|
|
217
|
+
/** Response headers (lowercased keys). */
|
|
218
|
+
headers: Record<string, string | string[]>;
|
|
219
|
+
/** Raw response body string (null on network error). */
|
|
220
|
+
rawBody: string | null;
|
|
221
|
+
/** Resolved operation name (from case.operationName or parsed from query). */
|
|
222
|
+
operationName: string;
|
|
223
|
+
/** Duration in ms. */
|
|
224
|
+
duration: number;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* User-facing GraphQL contract specification.
|
|
228
|
+
*
|
|
229
|
+
* Contract identity = contract id (string) + case key. `operationName` is
|
|
230
|
+
* a display/routing hint, NOT an identity (proposal §5.3 — same rule as
|
|
231
|
+
* gRPC `Service/Method`).
|
|
232
|
+
*/
|
|
233
|
+
export interface GraphqlContractSpec<Vars extends Record<string, unknown> = Record<string, unknown>, Res = unknown, Cases extends Record<string, GraphqlContractCase<Vars, Res, any>> = Record<string, GraphqlContractCase<Vars, Res>>> {
|
|
234
|
+
/**
|
|
235
|
+
* Endpoint URL **for projection / display only.**
|
|
236
|
+
*
|
|
237
|
+
* Travels on the projection `meta.endpoint`. The adapter does NOT use
|
|
238
|
+
* this to redirect the runtime call — the call is dispatched through
|
|
239
|
+
* the supplied `client`, whose endpoint was fixed at construction time
|
|
240
|
+
* (see `GraphqlContractDefaults.endpoint` for the full rationale). To
|
|
241
|
+
* target a different endpoint at runtime, construct a separate client.
|
|
242
|
+
*/
|
|
243
|
+
endpoint?: string;
|
|
244
|
+
/** Default GraphQL client for all cases. */
|
|
245
|
+
client?: GraphQLClient;
|
|
246
|
+
description?: string;
|
|
247
|
+
feature?: string;
|
|
248
|
+
/**
|
|
249
|
+
* Explicit type declarations (proposal §7b.2). Stored opaque in Phase 1;
|
|
250
|
+
* consumed by Phase 2 `.gql` projection. Safe to omit — nothing else
|
|
251
|
+
* depends on it at runtime.
|
|
252
|
+
*/
|
|
253
|
+
types?: GraphqlTypeDefs;
|
|
254
|
+
/**
|
|
255
|
+
* Default operation type for cases that don't set their own.
|
|
256
|
+
* Default when both spec and case omit: `"query"`.
|
|
257
|
+
*/
|
|
258
|
+
defaultOperation?: "query" | "mutation";
|
|
259
|
+
/**
|
|
260
|
+
* Contract-level variables schema. Per-case schemas (on `expect.schema`)
|
|
261
|
+
* cover response shape; variables often share structure so this sits at
|
|
262
|
+
* the contract level.
|
|
263
|
+
*/
|
|
264
|
+
variablesSchema?: SchemaLike<Vars>;
|
|
265
|
+
/**
|
|
266
|
+
* Contract-level response schema — used when all cases share the same
|
|
267
|
+
* selection set. Per-case `expect.schema` overrides.
|
|
268
|
+
*/
|
|
269
|
+
responseSchema?: SchemaLike<Res>;
|
|
270
|
+
/** Contract-level default variables (merged under each case's variables). */
|
|
271
|
+
defaultVariables?: Partial<Vars>;
|
|
272
|
+
/** Contract-level default headers (merged under each case's headers). */
|
|
273
|
+
defaultHeaders?: Record<string, string>;
|
|
274
|
+
tags?: string[];
|
|
275
|
+
deprecated?: string;
|
|
276
|
+
extensions?: Extensions;
|
|
277
|
+
/** Named spec cases. */
|
|
278
|
+
cases: Cases;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Runtime (live) payload shape for the GraphQL adapter. Contains SchemaLike
|
|
282
|
+
* references. Converted to `GraphqlSafeSchemas` by adapter.normalize.
|
|
283
|
+
*
|
|
284
|
+
* Per the selection-set coupling (proposal §3.2 b), the most important
|
|
285
|
+
* field here is `response` — it's the per-case response schema. `variables`
|
|
286
|
+
* and `request` (= the query document string) accompany it so the triple
|
|
287
|
+
* travels together through projection.
|
|
288
|
+
*/
|
|
289
|
+
export interface GraphqlPayloadSchemas {
|
|
290
|
+
/** Query document string (the "request" for GraphQL). */
|
|
291
|
+
query?: string;
|
|
292
|
+
/** Operation type (query / mutation). */
|
|
293
|
+
operation?: "query" | "mutation";
|
|
294
|
+
/** Resolved operationName (display/routing hint). */
|
|
295
|
+
operationName?: string;
|
|
296
|
+
/** Variables schema. */
|
|
297
|
+
variables?: SchemaLike<unknown>;
|
|
298
|
+
/** Per-case response schema (selection-set-coupled). */
|
|
299
|
+
response?: SchemaLike<unknown>;
|
|
300
|
+
/** Response headers schema. */
|
|
301
|
+
headers?: SchemaLike<Record<string, string | string[]>>;
|
|
302
|
+
/** Variables examples (for docs / projection). */
|
|
303
|
+
variablesExample?: unknown;
|
|
304
|
+
variablesExamples?: Record<string, GraphqlContractExample<unknown>>;
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* JSON-safe payload shape. Produced by adapter.normalize.
|
|
308
|
+
* SchemaLike references are converted to JSON Schema fragments.
|
|
309
|
+
*/
|
|
310
|
+
export interface GraphqlSafeSchemas {
|
|
311
|
+
query?: string;
|
|
312
|
+
operation?: "query" | "mutation";
|
|
313
|
+
operationName?: string;
|
|
314
|
+
variables?: Record<string, unknown>;
|
|
315
|
+
response?: Record<string, unknown>;
|
|
316
|
+
headers?: Record<string, unknown>;
|
|
317
|
+
variablesExample?: unknown;
|
|
318
|
+
variablesExamples?: Record<string, GraphqlContractExample<unknown>>;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* Runtime contract-level meta. Carried on the projection so scanner / MCP /
|
|
322
|
+
* Cloud can surface structural info without needing the live spec.
|
|
323
|
+
*
|
|
324
|
+
* Note: explicit `types` map (when present) is JSON-safe by construction
|
|
325
|
+
* (stringly-typed field declarations), so it travels unchanged from
|
|
326
|
+
* runtime to safe meta.
|
|
327
|
+
*/
|
|
328
|
+
export interface GraphqlContractMeta {
|
|
329
|
+
/** Endpoint URL (normalized; may be undefined if transport-owned). */
|
|
330
|
+
endpoint?: string;
|
|
331
|
+
/** Default operation type for the contract. */
|
|
332
|
+
defaultOperation?: "query" | "mutation";
|
|
333
|
+
/** Contract-level default headers (for projection display). */
|
|
334
|
+
defaultHeaders?: Record<string, string>;
|
|
335
|
+
/** Explicit type declarations (Phase 2 projection hint). */
|
|
336
|
+
types?: GraphqlTypeDefs;
|
|
337
|
+
/** Contract instance name (contract.graphql.with("name")). */
|
|
338
|
+
instanceName?: string;
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* JSON-safe meta. Same shape as runtime meta (no live references).
|
|
342
|
+
*/
|
|
343
|
+
export type GraphqlContractSafeMeta = GraphqlContractMeta;
|
|
344
|
+
/**
|
|
345
|
+
* What `executeCaseInFlow` returns, and what flow `step.out(state, res)`
|
|
346
|
+
* receives in its `res` parameter. Mirrors `GraphqlCaseResult` — kept as a
|
|
347
|
+
* distinct export to make the flow-output contract explicit (parallel to
|
|
348
|
+
* gRPC's `GrpcFlowCaseOutput` convention).
|
|
349
|
+
*/
|
|
350
|
+
export type GraphqlFlowCaseOutput<Res = unknown> = GraphqlCaseResult<Res>;
|
|
351
|
+
/**
|
|
352
|
+
* Signature of `contract.graphql.with("name", defaults)`. Returns a contract
|
|
353
|
+
* factory that creates contracts under this instance's defaults.
|
|
354
|
+
*
|
|
355
|
+
* Actual implementation in `./factory.ts` (CG-12).
|
|
356
|
+
*/
|
|
357
|
+
export type GraphqlContractRoot = {
|
|
358
|
+
with: (instanceName: string, defaults?: GraphqlContractDefaults) => GraphqlContractFactory;
|
|
359
|
+
};
|
|
360
|
+
export type GraphqlContractFactory = <Vars extends Record<string, unknown>, Res, Cases extends Record<string, GraphqlContractCase<Vars, Res, any>>>(id: string, spec: GraphqlContractSpec<Vars, Res, Cases>) => unknown;
|
|
361
|
+
/**
|
|
362
|
+
* Infer variables type from a GraphqlContractCase.
|
|
363
|
+
*/
|
|
364
|
+
export type InferGraphqlVariables<C> = C extends GraphqlContractCase<infer V, any, any> ? V : never;
|
|
365
|
+
/**
|
|
366
|
+
* Infer response type from a GraphqlContractCase.
|
|
367
|
+
*/
|
|
368
|
+
export type InferGraphqlResponse<C> = C extends GraphqlContractCase<any, infer R, any> ? R : never;
|
|
369
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/contract/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,EACV,cAAc,EACd,YAAY,EACZ,YAAY,EACZ,UAAU,EACX,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM/D;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEpD;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;AAM7D;;;;;;;;;;GAUG;AACH,MAAM,WAAW,uBAAuB;IACtC,iEAAiE;IACjE,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB;;;;;;;;;;;OAWG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,wDAAwD;IACxD,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAChB,oCAAoC;IACpC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,8CAA8C;IAC9C,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,uEAAuE;IACvE,UAAU,CAAC,EAAE,UAAU,CAAC;CACzB;AAMD,MAAM,WAAW,sBAAs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qBAAqB,CAAC,CAAC,IAAI,CAAC,SAAS,mBAAmB,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAEpG;;GAEG;AACH,MAAM,MAAM,oBAAoB,CAAC,CAAC,IAAI,CAAC,SAAS,mBAAmB,CAAC,GAAG,EAAE,MAAM,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* GraphQL contract types.
|
|
3
|
+
*
|
|
4
|
+
* User-facing authoring types + adapter-level payload types for the
|
|
5
|
+
* GraphQL contract adapter (single-package model — see
|
|
6
|
+
* `internal/40-discovery/proposals/contract-grpc-graphql-expansion.md` §6.1).
|
|
7
|
+
*
|
|
8
|
+
* Structure mirrors `packages/grpc/src/contract/types.ts` where applicable,
|
|
9
|
+
* with GraphQL-specific design:
|
|
10
|
+
*
|
|
11
|
+
* - **Target model:** GraphQL typically has a single `/graphql` endpoint,
|
|
12
|
+
* so `endpoint` is spec-level (not per-case). `endpoint` is
|
|
13
|
+
* **projection-only** in Phase 1 — it travels on `meta.endpoint`
|
|
14
|
+
* for markdown / scanner / MCP display, but the adapter dispatches
|
|
15
|
+
* through the supplied `GraphQLClient` whose endpoint was fixed at
|
|
16
|
+
* construction time. Multi-endpoint is expressed by multiple
|
|
17
|
+
* clients, not by per-contract endpoint strings. Contract identity
|
|
18
|
+
* = `contractId + caseKey`, NOT operationName (proposal §3.2).
|
|
19
|
+
*
|
|
20
|
+
* - **Selection-set-per-case coupling (proposal §3.2 b):** unlike
|
|
21
|
+
* HTTP/gRPC where response shape is determined by endpoint/method,
|
|
22
|
+
* GraphQL response shape is determined by the *query string* in each
|
|
23
|
+
* case. Each case therefore carries its own `query` + `variables` +
|
|
24
|
+
* `responseSchema` triple. A contract-level `responseSchema` may still
|
|
25
|
+
* apply if all cases share the same selection set (rare).
|
|
26
|
+
*
|
|
27
|
+
* - **Explicit type declarations (proposal §7b.2):** `types` is a
|
|
28
|
+
* deferred projection hint for Phase 2 SDL generation. Phase 1 stores
|
|
29
|
+
* it as opaque metadata — adapter / scanner carry it forward so
|
|
30
|
+
* projection tooling can consume it later.
|
|
31
|
+
*
|
|
32
|
+
* - **3-layer classifyFailure (proposal §3.2 c):**
|
|
33
|
+
* transport (HTTP status 4xx/5xx/network)
|
|
34
|
+
* → payload errors (GraphQL `errors` array, HTTP 200)
|
|
35
|
+
* → data shape mismatch (schema validation on `data`)
|
|
36
|
+
*
|
|
37
|
+
* - **Phase 1 scope:** query + mutation only (subscriptions deferred
|
|
38
|
+
* to Phase 2 streaming work).
|
|
39
|
+
*/
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/contract/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG"}
|
package/dist/index.d.ts
CHANGED
|
@@ -96,6 +96,25 @@ export interface GraphQLResponse<T = unknown> {
|
|
|
96
96
|
/** Optional server extensions (e.g., tracing, cost). */
|
|
97
97
|
extensions?: Record<string, unknown>;
|
|
98
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Extended result type returned by the client. Contains the full
|
|
101
|
+
* `GraphQLResponse` shape plus transport envelope fields used by
|
|
102
|
+
* the contract adapter layer (negative-transport assertions,
|
|
103
|
+
* `classifyFailure`, flow `out` lens inspection).
|
|
104
|
+
*
|
|
105
|
+
* Additive since v0.2.0 — users who only destructure `{ data, errors }`
|
|
106
|
+
* see no change. Users who need transport info read the new fields.
|
|
107
|
+
*
|
|
108
|
+
* @template T Shape of the `data` field
|
|
109
|
+
*/
|
|
110
|
+
export interface GraphQLResult<T = unknown> extends GraphQLResponse<T> {
|
|
111
|
+
/** HTTP status from the underlying POST (200 on most GraphQL success, even with `errors`). */
|
|
112
|
+
httpStatus: number;
|
|
113
|
+
/** Response headers (lowercased keys). */
|
|
114
|
+
headers: Record<string, string | string[]>;
|
|
115
|
+
/** Raw response body string — present when available (null on network error). */
|
|
116
|
+
rawBody: string | null;
|
|
117
|
+
}
|
|
99
118
|
/**
|
|
100
119
|
* Options for a single GraphQL request.
|
|
101
120
|
*/
|
|
@@ -179,7 +198,7 @@ export interface GraphQLClient {
|
|
|
179
198
|
* `, { variables: { limit: 10 } });
|
|
180
199
|
* ```
|
|
181
200
|
*/
|
|
182
|
-
query<T = unknown>(query: string, options?: GraphQLRequestOptions): Promise<
|
|
201
|
+
query<T = unknown>(query: string, options?: GraphQLRequestOptions): Promise<GraphQLResult<T>>;
|
|
183
202
|
/**
|
|
184
203
|
* Execute a GraphQL mutation.
|
|
185
204
|
*
|
|
@@ -200,7 +219,7 @@ export interface GraphQLClient {
|
|
|
200
219
|
* `, { variables: { input: { name: "Alice" } } });
|
|
201
220
|
* ```
|
|
202
221
|
*/
|
|
203
|
-
mutate<T = unknown>(mutation: string, options?: GraphQLRequestOptions): Promise<
|
|
222
|
+
mutate<T = unknown>(mutation: string, options?: GraphQLRequestOptions): Promise<GraphQLResult<T>>;
|
|
204
223
|
}
|
|
205
224
|
/**
|
|
206
225
|
* Extract the first named operation from a GraphQL query string.
|
|
@@ -322,4 +341,7 @@ export declare function createGraphQLClient(http: HttpClient, options: GraphQLCl
|
|
|
322
341
|
*/
|
|
323
342
|
export declare function graphql(options: GraphQLClientOptions): PluginFactory<GraphQLClient>;
|
|
324
343
|
export { fromGql } from "./data.js";
|
|
344
|
+
import "./contract/index.js";
|
|
345
|
+
export { graphqlAdapter, createGraphqlFactory, createGraphqlRoot, } from "./contract/index.js";
|
|
346
|
+
export type { GraphqlContractCase, GraphqlContractDefaults, GraphqlContractExample, GraphqlContractExpect, GraphqlContractFactory, GraphqlContractMeta, GraphqlContractRoot, GraphqlContractSafeMeta, GraphqlContractSpec, GraphqlCaseResult, GraphqlErrorsExpect, GraphqlFlowCaseOutput, GraphqlPayloadSchemas, GraphqlSafeSchemas, GraphqlTypeDef, GraphqlTypeDefs, InferGraphqlVariables, InferGraphqlResponse, } from "./contract/index.js";
|
|
325
347
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAGH,OAAO,KAAK,EAAkB,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAM9E;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,YAAY;IAC3B,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,2DAA2D;IAC3D,SAAS,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC/C,gDAAgD;IAChD,IAAI,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAC3B,wDAAwD;IACxD,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,eAAe,CAAC,CAAC,GAAG,OAAO;IAC1C,sEAAsE;IACtE,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;IACf,sDAAsD;IACtD,MAAM,CAAC,EAAE,YAAY,EAAE,CAAC;IACxB,wDAAwD;IACxD,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACtC;AAED;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,8CAA8C;IAC9C,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACpC;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;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O,EACL,cAAc,EACd,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,qBAAqB,CAAC;AAC7B,YAAY,EACV,mBAAmB,EACnB,uBAAuB,EACvB,sBAAsB,EACtB,qBAAqB,EACrB,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,uBAAuB,EACvB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,qBAAqB,EACrB,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,qBAAqB,EACrB,oBAAoB,GACrB,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -186,17 +186,33 @@ export function createGraphQLClient(http, options) {
|
|
|
186
186
|
if (opName !== "anonymous") {
|
|
187
187
|
body.operationName = opName;
|
|
188
188
|
}
|
|
189
|
-
const
|
|
190
|
-
.post(endpoint, {
|
|
189
|
+
const res = await http.post(endpoint, {
|
|
191
190
|
json: body,
|
|
192
191
|
headers: mergedHeaders,
|
|
193
192
|
throwHttpErrors: false,
|
|
194
|
-
})
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
193
|
+
});
|
|
194
|
+
const rawBody = await res.text();
|
|
195
|
+
const headers = {};
|
|
196
|
+
res.headers.forEach((value, key) => {
|
|
197
|
+
headers[key.toLowerCase()] = value;
|
|
198
|
+
});
|
|
199
|
+
let parsed;
|
|
200
|
+
try {
|
|
201
|
+
parsed = rawBody ? JSON.parse(rawBody) : { data: null };
|
|
198
202
|
}
|
|
199
|
-
|
|
203
|
+
catch {
|
|
204
|
+
parsed = { data: null };
|
|
205
|
+
}
|
|
206
|
+
const result = {
|
|
207
|
+
...parsed,
|
|
208
|
+
httpStatus: res.status,
|
|
209
|
+
headers,
|
|
210
|
+
rawBody,
|
|
211
|
+
};
|
|
212
|
+
if (throwOnGraphQLErrors && result.errors && result.errors.length > 0) {
|
|
213
|
+
throw new GraphQLResponseError(result.errors, result);
|
|
214
|
+
}
|
|
215
|
+
return result;
|
|
200
216
|
}
|
|
201
217
|
return {
|
|
202
218
|
query: (query, options) => execute(query, options),
|
|
@@ -257,4 +273,9 @@ export function graphql(options) {
|
|
|
257
273
|
}
|
|
258
274
|
// Re-export data loader for convenience (spec: `import { fromGql } from "@glubean/graphql"`)
|
|
259
275
|
export { fromGql } from "./data.js";
|
|
276
|
+
// Side-effect: register the contract adapter so `contract.graphql.with(...)` works.
|
|
277
|
+
// Kept at the bottom so transport exports land first, parallel to @glubean/grpc.
|
|
278
|
+
import "./contract/index.js";
|
|
279
|
+
// Re-export contract surface for type consumers
|
|
280
|
+
export { graphqlAdapter, createGraphqlFactory, createGraphqlRoot, } from "./contract/index.js";
|
|
260
281
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAsHnD;;;GAGG;AACH,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAC7C,2CAA2C;IAClC,MAAM,CAAiB;IAChC,yDAAyD;IAChD,QAAQ,CAAkB;IAEnC,YAAY,MAAsB,EAAE,QAAyB;QAC3D,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QACxD,KAAK,CAAC,mBAAmB,OAAO,EAAE,CAAC,CAAC;QACpC,IAAI,C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C;AAEpC,oFAAoF;AACpF,iFAAiF;AACjF,OAAO,qBAAqB,CAAC;AAE7B,gDAAgD;AAChD,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,iBAAiB,GAClB,MAAM,qBAAqB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glubean/graphql",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"type": "module",
|
|
5
|
+
"sideEffects": [
|
|
6
|
+
"./dist/index.js",
|
|
7
|
+
"./dist/contract/index.js"
|
|
8
|
+
],
|
|
5
9
|
"exports": {
|
|
6
10
|
".": {
|
|
7
11
|
"types": "./dist/index.d.ts",
|
|
@@ -20,7 +24,7 @@
|
|
|
20
24
|
"access": "public"
|
|
21
25
|
},
|
|
22
26
|
"dependencies": {
|
|
23
|
-
"@glubean/sdk": "0.2.
|
|
27
|
+
"@glubean/sdk": "0.2.1"
|
|
24
28
|
},
|
|
25
29
|
"devDependencies": {
|
|
26
30
|
"vitest": "^3.2.1",
|