@nxgt/graphql-codegen-msw 0.0.0-stage → 0.1.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 (50) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +293 -2
  3. package/THIRD-PARTY-NOTICES.md +71 -0
  4. package/dist/config.d.ts +66 -0
  5. package/dist/config.d.ts.map +1 -0
  6. package/dist/imports.d.ts +17 -0
  7. package/dist/imports.d.ts.map +1 -0
  8. package/dist/index.d.ts +13 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +365 -0
  11. package/dist/index.js.map +15 -0
  12. package/dist/input-types.d.ts +11 -0
  13. package/dist/input-types.d.ts.map +1 -0
  14. package/dist/naming.d.ts +23 -0
  15. package/dist/naming.d.ts.map +1 -0
  16. package/dist/operations.d.ts +17 -0
  17. package/dist/operations.d.ts.map +1 -0
  18. package/dist/options.d.ts +31 -0
  19. package/dist/options.d.ts.map +1 -0
  20. package/dist/runtime/coercion/cross-inspect.d.ts +19 -0
  21. package/dist/runtime/coercion/cross-inspect.d.ts.map +1 -0
  22. package/dist/runtime/coercion/document.d.ts +51 -0
  23. package/dist/runtime/coercion/document.d.ts.map +1 -0
  24. package/dist/runtime/coercion/index.d.ts +30 -0
  25. package/dist/runtime/coercion/index.d.ts.map +1 -0
  26. package/dist/runtime/coercion/inspect.d.ts +9 -0
  27. package/dist/runtime/coercion/inspect.d.ts.map +1 -0
  28. package/dist/runtime/coercion/issues.d.ts +19 -0
  29. package/dist/runtime/coercion/issues.d.ts.map +1 -0
  30. package/dist/runtime/coercion/messages.d.ts +37 -0
  31. package/dist/runtime/coercion/messages.d.ts.map +1 -0
  32. package/dist/runtime/coercion/suggestions.d.ts +15 -0
  33. package/dist/runtime/coercion/suggestions.d.ts.map +1 -0
  34. package/dist/runtime/coercion/validate.d.ts +39 -0
  35. package/dist/runtime/coercion/validate.d.ts.map +1 -0
  36. package/dist/runtime/index.d.ts +6 -0
  37. package/dist/runtime/index.d.ts.map +1 -0
  38. package/dist/runtime/index.js +595 -0
  39. package/dist/runtime/index.js.map +21 -0
  40. package/dist/runtime/mock-operation.d.ts +65 -0
  41. package/dist/runtime/mock-operation.d.ts.map +1 -0
  42. package/dist/runtime/refusals.d.ts +36 -0
  43. package/dist/runtime/refusals.d.ts.map +1 -0
  44. package/dist/runtime/response.d.ts +34 -0
  45. package/dist/runtime/response.d.ts.map +1 -0
  46. package/docs/README.md +14 -0
  47. package/docs/guide/handlers.md +654 -0
  48. package/docs/roadmap.md +40 -0
  49. package/docs/troubleshooting.md +304 -0
  50. package/package.json +80 -5
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Steve Tsala
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,294 @@
1
- # Temporary Holding Version
1
+ # @nxgt/graphql-codegen-msw
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A [graphql-codegen](https://the-guild.dev/graphql/codegen) plugin that writes
4
+ one typed [msw](https://mswjs.io) 3 handler per named query and mutation of
5
+ your documents: `mockUserQuery(resolver, options?)`, built on msw's
6
+ `graphql.link(endpoint)`. Each handler checks the variables it receives with
7
+ the Zod schema
8
+ [`@nxgt/graphql-codegen-zod`](https://www.npmjs.com/package/@nxgt/graphql-codegen-zod)
9
+ writes for that operation, so the mock refuses what your server refuses, and
10
+ answers an invalid input as your API does, without calling your resolver. For
11
+ graphql-codegen 5 to 7 (ESM), `graphql` 16 and 17, and msw 3.
12
+
13
+ ## Install
14
+
15
+ ```sh
16
+ bun add -d @nxgt/graphql-codegen-msw @nxgt/graphql-codegen-zod @graphql-codegen/cli msw
17
+ bun add graphql zod typescript
18
+ ```
19
+
20
+ Peers, all **required**:
21
+
22
+ | Peer | Range |
23
+ | --- | --- |
24
+ | `msw` | `^3.0.3` |
25
+ | `graphql` | `^16.11.0 \|\| ^17.0.0` |
26
+ | `zod` | `>=4.6.5 <5` |
27
+ | `typescript` | `^6.0.3 \|\| ^7.0.0` |
28
+
29
+ The generated file imports `@nxgt/graphql-codegen-msw/runtime` at run time:
30
+ keep the package wherever the mocks run. A dev dependency is enough for tests
31
+ and a development server; a production build that ships its mocks (a demo
32
+ mode) needs it as a dependency. `@nxgt/graphql-validation`, which builds the
33
+ refusals, comes with it, and `./runtime` re-exports what a function of your
34
+ own builds with (`invalidInputError`, `fieldsError`, `fieldIssueOf`,
35
+ `inputPath`, the types `Translate`, `FieldIssue`, `FieldError`): import them
36
+ from `@nxgt/graphql-codegen-msw/runtime`. An application that also imports
37
+ `@nxgt/graphql-validation` itself needs `^0.4.0`.
38
+
39
+ ## Setup
40
+
41
+ The schema must declare `@constraint` (the first entry below) when it uses
42
+ it, and `scalarSchemas` names the module holding a schema per custom scalar;
43
+ drop either from the example when your schema has no `@constraint` or no
44
+ custom scalar. Three outputs go in one folder: the client preset's files (its
45
+ `graphql.ts` holds each operation's result and variables types), the Zod
46
+ schemas `@nxgt/graphql-codegen-zod` writes (`zod.ts`), and the handlers
47
+ (`msw.ts`).
48
+
49
+ ```ts
50
+ // codegen.ts
51
+ import type { CodegenConfig } from '@graphql-codegen/cli';
52
+
53
+ const config: CodegenConfig = {
54
+ schema: ['generated/graphql/constraint.graphqls', 'src/schema/**/*.graphql'],
55
+ documents: 'src/operations/**/*.graphql',
56
+ generates: {
57
+ // The operations' types: the client preset...
58
+ 'src/generated/': { preset: 'client' },
59
+ 'src/generated/zod.ts': {
60
+ plugins: ['@nxgt/graphql-codegen-zod'],
61
+ config: { scalarSchemas: '@nxgt/graphql-scalars' },
62
+ },
63
+ 'src/generated/msw.ts': {
64
+ plugins: ['@nxgt/graphql-codegen-msw'],
65
+ config: {
66
+ endpoint: 'https://api.example.com/graphql',
67
+ schemasImport: './zod',
68
+ typesImport: './graphql',
69
+ },
70
+ },
71
+ },
72
+ };
73
+ export default config;
74
+ ```
75
+
76
+ Without the client preset, `typescript-operations` writes the same types
77
+ (`typesImport: './types'` then names its file):
78
+
79
+ ```ts
80
+ 'src/generated/types.ts': {
81
+ plugins: ['typescript', 'typescript-operations'],
82
+ },
83
+ ```
84
+
85
+ Where they come from: `generated/graphql/constraint.graphqls` is written by
86
+ `bunx nxgt-graphql-validation typedefs --out` (see
87
+ [`@nxgt/graphql-validation`](https://www.npmjs.com/package/@nxgt/graphql-validation)),
88
+ and `@nxgt/graphql-scalars` is `bun add @nxgt/graphql-scalars`, which exports
89
+ the `scalarSchemas` record codegen-zod reads.
90
+
91
+ `schemasImport` and `typesImport` are written into the generated imports as
92
+ you give them, relative to the generated file. Under `moduleResolution:
93
+ nodenext`, give them the `.js` extension: `'./zod.js'`, `'./graphql.js'`.
94
+
95
+ For an operation
96
+
97
+ ```graphql
98
+ query User($id: ID!) { user(id: $id) { id name } }
99
+ ```
100
+
101
+ the plugin writes
102
+
103
+ ```ts
104
+ export const endpoint = "https://api.example.com/graphql";
105
+ export const invalidInput: InvalidInput = invalidInputRefusal();
106
+
107
+ export function mockUserQuery(
108
+ resolver: GraphQLMockResolver<UserQuery, UserQueryVariables>,
109
+ options?: MockOptions,
110
+ ): GraphQLHandler { … }
111
+ ```
112
+
113
+ ## Usage
114
+
115
+ ### Answer an operation
116
+
117
+ A resolver is msw's own: it receives msw's resolver info, `variables` typed
118
+ with the operation's variables type, and answers with `HttpResponse.json`,
119
+ its `data` typed with the operation's result type.
120
+
121
+ ```ts
122
+ import { HttpResponse } from 'msw';
123
+ import { setupWorker } from 'msw/browser';
124
+ import { mockSignUpMutation, mockUserQuery } from './generated/msw';
125
+
126
+ export const worker = setupWorker(
127
+ mockUserQuery(({ variables }) =>
128
+ HttpResponse.json({ data: { user: { id: String(variables.id), name: 'Ada' } } }),
129
+ ),
130
+ mockSignUpMutation(() => HttpResponse.json({ data: { signUp: { id: 'u_1' } } })),
131
+ );
132
+ ```
133
+
134
+ The resolver runs only once the variables pass the operation's schema
135
+ (`zUserQueryVariables`): `@constraint` rules, input types, scalars. It receives
136
+ the variables as sent, not parsed.
137
+
138
+ ### An invalid input
139
+
140
+ By default, the handler answers an invalid input with one 400 error that
141
+ lists the refused fields, one per Zod issue: the shape of
142
+ [`invalidInputError`](https://www.npmjs.com/package/@nxgt/graphql-validation),
143
+ for an API that answers invalid input that way.
144
+
145
+ ```json
146
+ {
147
+ "errors": [{
148
+ "message": "validation.errors.invalid-input",
149
+ "extensions": {
150
+ "code": "validation.errors.invalid-input",
151
+ "fields": [
152
+ { "path": "person.firstName", "code": "validation.errors.too-short",
153
+ "message": "validation.errors.too-short" }
154
+ ]
155
+ }
156
+ }]
157
+ }
158
+ ```
159
+
160
+ The codes are `too-short`, `too-long`, `out-of-range`, `too-few`, `too-many`,
161
+ `invalid-format` (a format or a pattern) and `invalid` (anything else, a
162
+ prefix, suffix or substring included), under `validation.errors.`, with no
163
+ params: `@nxgt/graphql-validation`'s `fieldIssueOf`, the mapping a server
164
+ using it applies. Each message is its code, unless you name a translator:
165
+ `translate: './i18n#translate'`.
166
+
167
+ A value the API refuses before its validation (a missing or `null` value for a
168
+ non-null type, a wrong type, an unknown enum value or input field, an Int
169
+ beyond 32 bits, a value a custom scalar refuses) is answered as graphql-yoga
170
+ answers it, whatever `invalidInput` is: status 400, one plain error per
171
+ problem in graphql 17's wording, types named and "Did you mean …?" included,
172
+ no `extensions`. The generated file describes the input types from the schema
173
+ for it. The few cases where the mock still differs are listed in
174
+ [the handlers guide](./docs/guide/handlers.md#known-differences).
175
+
176
+ ```json
177
+ { "errors": [{ "message": "Variable \"$id\" of required type \"ID!\" was not provided.", "locations": [{ "line": 1, "column": 12 }] }] }
178
+ ```
179
+
180
+ Any other invalid input, a constraint, gets the answer `invalidInput` picks:
181
+
182
+ | `invalidInput` | Answer |
183
+ | --- | --- |
184
+ | `'invalid-input'` (default) | one 400 error listing the fields, as above |
185
+ | `'bad-user-input'` | the `BAD_USER_INPUT` error `withValidation` raises, status 200 |
186
+ | `'<module>#<export>'` | your function's error and status |
187
+
188
+ ```ts
189
+ // src/mocks/invalid-input.ts, for invalidInput: '../mocks/invalid-input#invalidInput'
190
+ import type { InvalidInput } from '@nxgt/graphql-codegen-msw/runtime';
191
+
192
+ export const invalidInput: InvalidInput = (issues, operation) => ({
193
+ error: { message: `${operation.name}: ${issues[0]?.message}`, extensions: { code: 'INVALID' } },
194
+ status: 422,
195
+ });
196
+ ```
197
+
198
+ ### Refuse from the resolver
199
+
200
+ Throw a `GraphQLError`, as your server's resolver would: the handler answers
201
+ `{ errors: [error] }` at its `extensions.http.status`, else 200. Or return
202
+ `errorResponse(error, { status })`. As graphql-yoga does, the body leaves out
203
+ `extensions.http` (and `extensions.unexpected`), and several errors answer at
204
+ the highest status among them.
205
+
206
+ ```ts
207
+ import { errorResponse, fieldsError } from '@nxgt/graphql-codegen-msw/runtime';
208
+
209
+ mockSignUpMutation(() => {
210
+ throw fieldsError('person.errors.duplicate', [{ path: 'person.email', code: 'person.errors.email-taken' }], { status: 409 });
211
+ });
212
+ mockUserQuery(() => errorResponse({ message: 'Not found', extensions: { code: 'NOT_FOUND' } }));
213
+ ```
214
+
215
+ Anything else a resolver throws is msw's to answer: a 500.
216
+
217
+ ### Options per handler
218
+
219
+ `options` takes msw's own (`once`) and an `endpoint` for that handler only:
220
+
221
+ ```ts
222
+ mockUserQuery(resolver, { endpoint: 'https://staging.example.com/graphql', once: true });
223
+ ```
224
+
225
+ ### In tests
226
+
227
+ ```ts
228
+ import { HttpResponse } from 'msw';
229
+ import { setupServer } from 'msw/node';
230
+ import { mockUserQuery } from './generated/msw';
231
+
232
+ const server = setupServer();
233
+ beforeAll(() => server.listen({ onUnhandledFrame: 'error' }));
234
+ afterEach(() => server.resetHandlers());
235
+ afterAll(() => server.close());
236
+
237
+ test('shows the user', async () => {
238
+ server.use(mockUserQuery(() => HttpResponse.json({ data: { user: null } })));
239
+ // …
240
+ });
241
+ ```
242
+
243
+ Under Bun, msw 3's `setupServer` intercepts no `fetch`: see
244
+ [Under Bun](docs/guide/handlers.md#under-bun).
245
+
246
+ ## Options
247
+
248
+ | Option | Type | Default | Effect |
249
+ | --- | --- | --- | --- |
250
+ | `endpoint` | `string` | required | where the client sends its operations, a URL or a path msw matches (`'*/graphql'`) |
251
+ | `schemasImport` | `string` | required | the module `@nxgt/graphql-codegen-zod` writes, as the generated file imports it |
252
+ | `typesImport` | `string` | required | the module exporting each operation's result and variables types: the client preset's `graphql.ts`, or `typescript-operations`' file |
253
+ | `invalidInput` | `'invalid-input' \| 'bad-user-input' \| '<module>#<export>'` | `'invalid-input'` | how an invalid input is answered |
254
+ | `translate` | `'<module>#<export>'` | none | a `Translate` for the default answer's messages |
255
+ | `schemaPrefix` | `string` | `'z'` | as `@nxgt/graphql-codegen-zod`'s |
256
+ | `namingConvention`, `typesPrefix`, `typesSuffix`, `dedupeOperationSuffix`, `omitOperationSuffix` | | | as the typescript plugins read them: set them at the root of the codegen config, for the three files alike |
257
+
258
+ Each is detailed in [Handlers](docs/guide/handlers.md).
259
+
260
+ ## Traps
261
+
262
+ - A handler is written for a **named** query or mutation. An anonymous
263
+ operation has no name for msw to match, and a subscription none: msw 3 mocks
264
+ subscriptions over WebSocket only (see the [roadmap](docs/roadmap.md)).
265
+ - Take the types from the client preset or `typescript-operations` (the wire
266
+ types), not from codegen-zod's file, whose result types are decoded (a
267
+ `DateTime` is a `Date` there).
268
+ - The resolver receives the variables as sent: a `DateTime` is its string, a
269
+ default is not filled in. Parse them with the schema when you need the
270
+ decoded values: `zSignUpMutationVariables.parse(variables)`.
271
+ - A generator resolver is refused: msw would answer the next requests from
272
+ its iterator, without checking their variables. Register one handler per
273
+ answer with `{ once: true }`.
274
+ - `msw/node`'s `setupServer` intercepts nothing under Bun (msw 3.0.3, Bun
275
+ 1.4.2): run those tests under Node, or see
276
+ [Under Bun](docs/guide/handlers.md#under-bun).
277
+ - Persisted queries and batched requests are not matched (see the roadmap).
278
+
279
+ Every error and its fix is in [Troubleshooting](docs/troubleshooting.md).
280
+
281
+ ## Documentation
282
+
283
+ The package exports `plugin` and the `CodegenMswConfig` and `DocumentFile`
284
+ types from `.`; graphql-codegen finds `plugin` by the package name. The
285
+ generated file's runtime is `./runtime`: `mockOperation`,
286
+ `invalidInputRefusal`, `badUserInputRefusal`, `errorResponse`,
287
+ `isGraphQLError` and their types, and, re-exported from
288
+ `@nxgt/graphql-validation`, `invalidInputError`, `fieldsError`,
289
+ `fieldIssueOf`, `inputPath`, `Translate`, `FieldIssue` and `FieldError`.
290
+
291
+ - [Documentation index](docs/README.md)
292
+ - Guides: [Handlers](docs/guide/handlers.md)
293
+ - [Troubleshooting](docs/troubleshooting.md)
294
+ - [Roadmap](docs/roadmap.md)
@@ -0,0 +1,71 @@
1
+ # Third-party notices
2
+
3
+ `@nxgt/graphql-codegen-msw` ports a few functions from the projects below, so
4
+ that its mocks word a refused variable exactly as graphql-yoga on graphql 17
5
+ does. Each ported file in `src/runtime/coercion/` (bundled into
6
+ `dist/runtime/index.js`) starts with a `/*! … @license MIT */` header naming
7
+ its source; the full licenses follow.
8
+
9
+ ## graphql-js
10
+
11
+ - Source: https://github.com/graphql/graphql-js, version 17.0.2
12
+ - Ported: `inspect` (`inspect.ts`); `suggestionList`, `didYouMean`,
13
+ `orList`, `naturalCompare` (`suggestions.ts`); the built-in scalars' and
14
+ enums' messages (`messages.ts`); `validateInputValue`, through
15
+ `@graphql-tools/executor`'s copy (`validate.ts`); `inspect`, through
16
+ `cross-inspect` (`cross-inspect.ts`)
17
+
18
+ ```text
19
+ MIT License
20
+
21
+ Copyright (c) GraphQL Contributors
22
+
23
+ Permission is hereby granted, free of charge, to any person obtaining a copy
24
+ of this software and associated documentation files (the "Software"), to deal
25
+ in the Software without restriction, including without limitation the rights
26
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
27
+ copies of the Software, and to permit persons to whom the Software is
28
+ furnished to do so, subject to the following conditions:
29
+
30
+ The above copyright notice and this permission notice shall be included in all
31
+ copies or substantial portions of the Software.
32
+
33
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
34
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
35
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
36
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
37
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
38
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
39
+ SOFTWARE.
40
+ ```
41
+
42
+ ## graphql-tools: `@graphql-tools/executor` and `cross-inspect`
43
+
44
+ - Source: https://github.com/ardatan/graphql-tools, `@graphql-tools/executor`
45
+ 2.0.3 and `cross-inspect` 1.0.1
46
+ - Ported: `validateInputValue` (`validate.ts`); the input objects' messages
47
+ and the variable's prefix (`messages.ts`); `inspect` (`cross-inspect.ts`)
48
+
49
+ ```text
50
+ The MIT License (MIT)
51
+
52
+ Copyright (c) 2020 The Guild, Inc.
53
+
54
+ Permission is hereby granted, free of charge, to any person obtaining a copy
55
+ of this software and associated documentation files (the "Software"), to deal
56
+ in the Software without restriction, including without limitation the rights
57
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
58
+ copies of the Software, and to permit persons to whom the Software is
59
+ furnished to do so, subject to the following conditions:
60
+
61
+ The above copyright notice and this permission notice shall be included in all
62
+ copies or substantial portions of the Software.
63
+
64
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
65
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
66
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
67
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
68
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
69
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
70
+ SOFTWARE.
71
+ ```
@@ -0,0 +1,66 @@
1
+ import type { DocumentNode } from 'graphql';
2
+ /**
3
+ * The plugin's options, under `config` in `codegen.ts`. The naming options
4
+ * mean what they mean to `@graphql-codegen/typescript-operations` and to
5
+ * `@nxgt/graphql-codegen-zod`: set them once at the root of the codegen
6
+ * config, so the three files name each operation alike.
7
+ */
8
+ export interface CodegenMswConfig {
9
+ /**
10
+ * Where the client sends its operations, as msw's `graphql.link()` takes
11
+ * it: `'https://api.example.com/graphql'`, or a path msw matches on any
12
+ * origin, `'*\/graphql'`. Required; each handler's `options.endpoint`
13
+ * overrides it.
14
+ */
15
+ readonly endpoint?: string;
16
+ /**
17
+ * The file `@nxgt/graphql-codegen-zod` writes, as the generated file
18
+ * imports it: `'./zod'` (relative to the generated file) or a package.
19
+ * Each handler checks its variables with that file's
20
+ * `z<Operation>Variables`. Required.
21
+ */
22
+ readonly schemasImport?: string;
23
+ /**
24
+ * The module exporting each operation's result and variables types
25
+ * (`UserQuery`, `UserQueryVariables`): the client preset's `'./graphql'`,
26
+ * or the file `typescript-operations` writes. Required.
27
+ */
28
+ readonly typesImport?: string;
29
+ /**
30
+ * How an invalid input is answered, without calling the resolver:
31
+ * `'invalid-input'` (the default: one 400 error listing the fields, as
32
+ * `invalidInputError` builds it), `'bad-user-input'` (the
33
+ * `BAD_USER_INPUT` error `withValidation` raises, status 200), or
34
+ * `'<module>#<export>'`, a function of yours typed `InvalidInput`.
35
+ */
36
+ readonly invalidInput?: string;
37
+ /**
38
+ * `'<module>#<export>'`, a `Translate` function the default
39
+ * `invalidInput` words each message with. Without it a message is its
40
+ * code.
41
+ */
42
+ readonly translate?: string;
43
+ /** Before each schema's name, as codegen-zod's: `zUserQueryVariables`. Default `'z'`. */
44
+ readonly schemaPrefix?: string;
45
+ /**
46
+ * As the typescript plugins read it, for type names: `'keep'`,
47
+ * `'change-case-all#<case>'`, a function, or `{ typeNames,
48
+ * transformUnderscore }`. Default: PascalCase each part between
49
+ * underscores.
50
+ */
51
+ readonly namingConvention?: string | ((name: string) => string) | {
52
+ readonly typeNames?: string | ((name: string) => string);
53
+ readonly enumValues?: unknown;
54
+ readonly transformUnderscore?: boolean;
55
+ };
56
+ readonly typesPrefix?: string;
57
+ readonly typesSuffix?: string;
58
+ readonly dedupeOperationSuffix?: boolean;
59
+ readonly omitOperationSuffix?: boolean;
60
+ }
61
+ /** A file of `documents`, as graphql-codegen hands it to a plugin. */
62
+ export interface DocumentFile {
63
+ readonly document?: DocumentNode | undefined;
64
+ readonly location?: string | undefined;
65
+ }
66
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAE5C;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB;IAChC;;;;;OAKG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAC3B;;;;;OAKG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;IAChC;;;;OAIG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;;;OAMG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAC5B,yFAAyF;IACzF,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B;;;;;OAKG;IACH,QAAQ,CAAC,gBAAgB,CAAC,EACvB,MAAM,GACN,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,GAC1B;QACA,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC;QACzD,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;QAC9B,QAAQ,CAAC,mBAAmB,CAAC,EAAE,OAAO,CAAC;KACtC,CAAC;IACL,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;IAC9B,QAAQ,CAAC,qBAAqB,CAAC,EAAE,OAAO,CAAC;IACzC,QAAQ,CAAC,mBAAmB,CAAC,EAAE,OAAO,CAAC;CACvC;AAED,sEAAsE;AACtE,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,YAAY,GAAG,SAAS,CAAC;IAC7C,QAAQ,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACvC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * The named imports of the generated file, one line per module in the order
3
+ * they were first asked for, an alias when a name is taken. A module whose
4
+ * every name is a type is written `import type`.
5
+ */
6
+ export declare class Imports {
7
+ #private;
8
+ /** `reserved`: the names the file declares, which no import may take. */
9
+ constructor(reserved?: Iterable<string>);
10
+ /** The local name of the value `exported` from `module`. */
11
+ value(module: string, exported: string): string;
12
+ /** The local name of the type `exported` from `module`. */
13
+ type(module: string, exported: string): string;
14
+ /** The import lines, double-quoted as every string the file holds. */
15
+ lines(): string[];
16
+ }
17
+ //# sourceMappingURL=imports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"imports.d.ts","sourceRoot":"","sources":["../src/imports.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,qBAAa,OAAO;;IAInB,yEAAyE;gBAC7D,QAAQ,GAAE,QAAQ,CAAC,MAAM,CAAM;IAI3C,4DAA4D;IAC5D,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;IAI/C,2DAA2D;IAC3D,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,MAAM;IAmB9C,sEAAsE;IACtE,KAAK,IAAI,MAAM,EAAE;CAWjB"}
@@ -0,0 +1,13 @@
1
+ import type { GraphQLSchema } from 'graphql';
2
+ import type { CodegenMswConfig, DocumentFile } from './config.js';
3
+ export type { CodegenMswConfig, DocumentFile } from './config.js';
4
+ /**
5
+ * The graphql-codegen plugin: one msw handler factory per named query and
6
+ * mutation of `documents`, `mock<Operation>(resolver, options?)`, typed with
7
+ * the operation's result and variables types, its variables checked with
8
+ * `@nxgt/graphql-codegen-zod`'s schema before the resolver runs. The schema
9
+ * gives the input types the variables reach, written once as `inputTypes`
10
+ * for the answer to a value graphql refuses.
11
+ */
12
+ export declare function plugin(schema: GraphQLSchema, documents: readonly DocumentFile[], config?: CodegenMswConfig): string;
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7C,OAAO,KAAK,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAO/D,YAAY,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAK/D;;;;;;;GAOG;AACH,wBAAgB,MAAM,CACrB,MAAM,EAAE,aAAa,EACrB,SAAS,EAAE,SAAS,YAAY,EAAE,EAClC,MAAM,GAAE,gBAAqB,GAC3B,MAAM,CA0DR"}