@nxgt/graphql-codegen-msw 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +293 -2
- package/THIRD-PARTY-NOTICES.md +71 -0
- package/dist/config.d.ts +66 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/imports.d.ts +17 -0
- package/dist/imports.d.ts.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +365 -0
- package/dist/index.js.map +15 -0
- package/dist/input-types.d.ts +11 -0
- package/dist/input-types.d.ts.map +1 -0
- package/dist/naming.d.ts +23 -0
- package/dist/naming.d.ts.map +1 -0
- package/dist/operations.d.ts +17 -0
- package/dist/operations.d.ts.map +1 -0
- package/dist/options.d.ts +31 -0
- package/dist/options.d.ts.map +1 -0
- package/dist/runtime/coercion/cross-inspect.d.ts +19 -0
- package/dist/runtime/coercion/cross-inspect.d.ts.map +1 -0
- package/dist/runtime/coercion/document.d.ts +51 -0
- package/dist/runtime/coercion/document.d.ts.map +1 -0
- package/dist/runtime/coercion/index.d.ts +30 -0
- package/dist/runtime/coercion/index.d.ts.map +1 -0
- package/dist/runtime/coercion/inspect.d.ts +9 -0
- package/dist/runtime/coercion/inspect.d.ts.map +1 -0
- package/dist/runtime/coercion/issues.d.ts +20 -0
- package/dist/runtime/coercion/issues.d.ts.map +1 -0
- package/dist/runtime/coercion/messages.d.ts +37 -0
- package/dist/runtime/coercion/messages.d.ts.map +1 -0
- package/dist/runtime/coercion/suggestions.d.ts +15 -0
- package/dist/runtime/coercion/suggestions.d.ts.map +1 -0
- package/dist/runtime/coercion/validate.d.ts +39 -0
- package/dist/runtime/coercion/validate.d.ts.map +1 -0
- package/dist/runtime/index.d.ts +6 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +595 -0
- package/dist/runtime/index.js.map +21 -0
- package/dist/runtime/mock-operation.d.ts +65 -0
- package/dist/runtime/mock-operation.d.ts.map +1 -0
- package/dist/runtime/refusals.d.ts +36 -0
- package/dist/runtime/refusals.d.ts.map +1 -0
- package/dist/runtime/response.d.ts +34 -0
- package/dist/runtime/response.d.ts.map +1 -0
- package/docs/README.md +14 -0
- package/docs/guide/handlers.md +658 -0
- package/docs/roadmap.md +40 -0
- package/docs/troubleshooting.md +304 -0
- package/package.json +80 -5
package/dist/index.js
ADDED
|
@@ -0,0 +1,365 @@
|
|
|
1
|
+
// src/imports.ts
|
|
2
|
+
class Imports {
|
|
3
|
+
#byModule = new Map;
|
|
4
|
+
#taken;
|
|
5
|
+
constructor(reserved = []) {
|
|
6
|
+
this.#taken = new Set(reserved);
|
|
7
|
+
}
|
|
8
|
+
value(module, exported) {
|
|
9
|
+
return this.#add(module, exported, false);
|
|
10
|
+
}
|
|
11
|
+
type(module, exported) {
|
|
12
|
+
return this.#add(module, exported, true);
|
|
13
|
+
}
|
|
14
|
+
#add(module, exported, type) {
|
|
15
|
+
const names = this.#byModule.get(module) ?? new Map;
|
|
16
|
+
this.#byModule.set(module, names);
|
|
17
|
+
const known = names.get(exported);
|
|
18
|
+
if (known) {
|
|
19
|
+
if (!type && known.type)
|
|
20
|
+
names.set(exported, { ...known, type: false });
|
|
21
|
+
return known.local;
|
|
22
|
+
}
|
|
23
|
+
let local = exported;
|
|
24
|
+
for (let n = 2;this.#taken.has(local); n++)
|
|
25
|
+
local = `${exported}${n}`;
|
|
26
|
+
this.#taken.add(local);
|
|
27
|
+
names.set(exported, { local, type });
|
|
28
|
+
return local;
|
|
29
|
+
}
|
|
30
|
+
lines() {
|
|
31
|
+
return [...this.#byModule].map(([module, names]) => {
|
|
32
|
+
const all = [...names];
|
|
33
|
+
const typeOnly = all.every(([, { type }]) => type);
|
|
34
|
+
const specifiers = all.map(([exported, { local, type }]) => {
|
|
35
|
+
const name = exported === local ? local : `${exported} as ${local}`;
|
|
36
|
+
return type && !typeOnly ? `type ${name}` : name;
|
|
37
|
+
});
|
|
38
|
+
return `import ${typeOnly ? "type " : ""}{ ${specifiers.join(", ")} } from ${JSON.stringify(module)};`;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// src/input-types.ts
|
|
44
|
+
import {
|
|
45
|
+
getNamedType,
|
|
46
|
+
isEnumType,
|
|
47
|
+
isInputObjectType,
|
|
48
|
+
isNonNullType,
|
|
49
|
+
isRequiredInputField,
|
|
50
|
+
isSpecifiedScalarType,
|
|
51
|
+
Kind,
|
|
52
|
+
print
|
|
53
|
+
} from "graphql";
|
|
54
|
+
function variableTypesCode(node) {
|
|
55
|
+
const entries = (node.variableDefinitions ?? []).map((definition) => {
|
|
56
|
+
const type = print(definition.type);
|
|
57
|
+
const source = definition.defaultValue ? `${type} = ${print(definition.defaultValue)}` : type;
|
|
58
|
+
return `${definition.variable.name.value}: ${JSON.stringify(source)}`;
|
|
59
|
+
});
|
|
60
|
+
return entries.length > 0 ? `{ ${entries.join(", ")} }` : "{}";
|
|
61
|
+
}
|
|
62
|
+
function inputTypesCode(schema, operations) {
|
|
63
|
+
const reached = new Map;
|
|
64
|
+
const visit = (type) => {
|
|
65
|
+
if (!type || reached.has(type.name))
|
|
66
|
+
return;
|
|
67
|
+
reached.set(type.name, type);
|
|
68
|
+
if (isInputObjectType(type))
|
|
69
|
+
for (const field of Object.values(type.getFields()))
|
|
70
|
+
visit(getNamedType(field.type));
|
|
71
|
+
};
|
|
72
|
+
for (const operation of operations)
|
|
73
|
+
for (const definition of operation.variableDefinitions ?? [])
|
|
74
|
+
visit(schema.getType(namedTypeOf(definition.type)) ?? undefined);
|
|
75
|
+
const entries = [...reached.values()].sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0).map((type) => ` ${type.name}: ${entryCode(type)},`);
|
|
76
|
+
return entries.length > 0 ? `{
|
|
77
|
+
${entries.join(`
|
|
78
|
+
`)}
|
|
79
|
+
}` : "{}";
|
|
80
|
+
}
|
|
81
|
+
function namedTypeOf(type) {
|
|
82
|
+
return type.kind === Kind.NAMED_TYPE ? type.name.value : namedTypeOf(type.type);
|
|
83
|
+
}
|
|
84
|
+
function entryCode(type) {
|
|
85
|
+
if (isInputObjectType(type)) {
|
|
86
|
+
const fields = Object.values(type.getFields()).map((field) => `${field.name}: ${JSON.stringify(fieldSource(field))}`);
|
|
87
|
+
return block([
|
|
88
|
+
'kind: "input"',
|
|
89
|
+
`fields: ${block(fields, 2)}`,
|
|
90
|
+
...type.isOneOf ? ["oneOf: true"] : []
|
|
91
|
+
]);
|
|
92
|
+
}
|
|
93
|
+
if (isEnumType(type)) {
|
|
94
|
+
const values = type.getValues().map((value) => JSON.stringify(value.name));
|
|
95
|
+
return block(['kind: "enum"', `values: ${list(values, 2)}`]);
|
|
96
|
+
}
|
|
97
|
+
return isSpecifiedScalarType(type) ? '{ kind: "builtin" }' : '{ kind: "scalar" }';
|
|
98
|
+
}
|
|
99
|
+
function block(properties, depth = 1) {
|
|
100
|
+
return wrapped("{", "}", properties, depth);
|
|
101
|
+
}
|
|
102
|
+
function list(items, depth) {
|
|
103
|
+
return wrapped("[", "]", items, depth);
|
|
104
|
+
}
|
|
105
|
+
function wrapped(open, close, items, depth) {
|
|
106
|
+
if (items.length === 0)
|
|
107
|
+
return `${open}${close}`;
|
|
108
|
+
const indent = "\t".repeat(depth + 1);
|
|
109
|
+
const lines = items.map((item) => `${indent}${item},`);
|
|
110
|
+
return `${open}
|
|
111
|
+
${lines.join(`
|
|
112
|
+
`)}
|
|
113
|
+
${"\t".repeat(depth)}${close}`;
|
|
114
|
+
}
|
|
115
|
+
function fieldSource(field) {
|
|
116
|
+
const type = String(field.type);
|
|
117
|
+
const literal = field.astNode?.defaultValue;
|
|
118
|
+
if (literal)
|
|
119
|
+
return `${type} = ${print(literal)}`;
|
|
120
|
+
return isNonNullType(field.type) && !isRequiredInputField(field) ? `${type} = …` : type;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
// src/naming.ts
|
|
124
|
+
import * as changeCase from "change-case";
|
|
125
|
+
|
|
126
|
+
class Naming {
|
|
127
|
+
#config;
|
|
128
|
+
#convert;
|
|
129
|
+
constructor(config) {
|
|
130
|
+
this.#config = config;
|
|
131
|
+
this.#convert = converter(config.namingConvention);
|
|
132
|
+
}
|
|
133
|
+
variables(operation, kind) {
|
|
134
|
+
return this.#wrap(this.#convert(`${operation}${this.#suffix(operation, kind)}Variables`));
|
|
135
|
+
}
|
|
136
|
+
result(operation, kind) {
|
|
137
|
+
return this.#wrap(this.#convert(`${operation}${this.#suffix(operation, kind)}`));
|
|
138
|
+
}
|
|
139
|
+
schema(type) {
|
|
140
|
+
return `${this.#config.schemaPrefix ?? "z"}${type}`;
|
|
141
|
+
}
|
|
142
|
+
handler(operation, kind) {
|
|
143
|
+
return `mock${this.#convert(`${operation}${this.#suffix(operation, kind)}`)}`;
|
|
144
|
+
}
|
|
145
|
+
#suffix(operation, kind) {
|
|
146
|
+
const type = changeCase.pascalCase(kind);
|
|
147
|
+
const { omitOperationSuffix, dedupeOperationSuffix } = this.#config;
|
|
148
|
+
return omitOperationSuffix || dedupeOperationSuffix && operation.toLowerCase().endsWith(type.toLowerCase()) ? "" : type;
|
|
149
|
+
}
|
|
150
|
+
#wrap(name) {
|
|
151
|
+
return `${this.#config.typesPrefix ?? ""}${name}${this.#config.typesSuffix ?? ""}`;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
var lowerCaseFirst = (name) => name.charAt(0).toLowerCase() + name.slice(1);
|
|
155
|
+
var upperCaseFirst = (name) => name.charAt(0).toUpperCase() + name.slice(1);
|
|
156
|
+
var cases = {
|
|
157
|
+
"change-case-all": {
|
|
158
|
+
camelCase: changeCase.camelCase,
|
|
159
|
+
capitalCase: changeCase.capitalCase,
|
|
160
|
+
constantCase: changeCase.constantCase,
|
|
161
|
+
dotCase: changeCase.dotCase,
|
|
162
|
+
headerCase: changeCase.trainCase,
|
|
163
|
+
noCase: changeCase.noCase,
|
|
164
|
+
paramCase: changeCase.kebabCase,
|
|
165
|
+
pascalCase: changeCase.pascalCase,
|
|
166
|
+
pathCase: changeCase.pathCase,
|
|
167
|
+
sentenceCase: changeCase.sentenceCase,
|
|
168
|
+
snakeCase: changeCase.snakeCase,
|
|
169
|
+
lowerCase: (name) => name.toLowerCase(),
|
|
170
|
+
upperCase: (name) => name.toUpperCase(),
|
|
171
|
+
lowerCaseFirst,
|
|
172
|
+
upperCaseFirst
|
|
173
|
+
},
|
|
174
|
+
"change-case": {
|
|
175
|
+
camelCase: changeCase.camelCase,
|
|
176
|
+
capitalCase: changeCase.capitalCase,
|
|
177
|
+
constantCase: changeCase.constantCase,
|
|
178
|
+
dotCase: changeCase.dotCase,
|
|
179
|
+
kebabCase: changeCase.kebabCase,
|
|
180
|
+
noCase: changeCase.noCase,
|
|
181
|
+
pascalCase: changeCase.pascalCase,
|
|
182
|
+
pascalSnakeCase: changeCase.pascalSnakeCase,
|
|
183
|
+
pathCase: changeCase.pathCase,
|
|
184
|
+
sentenceCase: changeCase.sentenceCase,
|
|
185
|
+
snakeCase: changeCase.snakeCase,
|
|
186
|
+
trainCase: changeCase.trainCase
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
var byPart = (fn, transformUnderscore) => (name) => transformUnderscore ? fn(name) : name.split("_").map(fn).join("_");
|
|
190
|
+
function converter(convention) {
|
|
191
|
+
if (convention === undefined)
|
|
192
|
+
return byPart(changeCase.pascalCase, false);
|
|
193
|
+
if (convention === "keep")
|
|
194
|
+
return (name) => name;
|
|
195
|
+
if (typeof convention === "function")
|
|
196
|
+
return byPart(convention, false);
|
|
197
|
+
if (typeof convention === "string")
|
|
198
|
+
return byPart(caseNamed(convention), false);
|
|
199
|
+
const { typeNames, transformUnderscore } = convention;
|
|
200
|
+
if (typeNames === "keep")
|
|
201
|
+
return (name) => name;
|
|
202
|
+
if (typeNames === undefined)
|
|
203
|
+
return byPart(changeCase.pascalCase, transformUnderscore ?? false);
|
|
204
|
+
const fn = typeof typeNames === "function" ? typeNames : caseNamed(typeNames);
|
|
205
|
+
return byPart(fn, true);
|
|
206
|
+
}
|
|
207
|
+
function caseNamed(spec) {
|
|
208
|
+
const [module = "", name = ""] = spec.split("#");
|
|
209
|
+
const fn = cases[module]?.[name];
|
|
210
|
+
if (fn)
|
|
211
|
+
return fn;
|
|
212
|
+
throw new Error(`@nxgt/graphql-codegen-msw: namingConvention "${spec}" is not one this plugin reads. Use 'keep', a function, or 'change-case-all#<case>' with one of ${Object.keys(cases["change-case-all"] ?? {}).join(", ")}.`);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// src/operations.ts
|
|
216
|
+
import { Kind as Kind2 } from "graphql";
|
|
217
|
+
function mockedOperations(documents) {
|
|
218
|
+
return documents.flatMap((file) => file.document?.definitions ?? []).filter((node) => node.kind === Kind2.OPERATION_DEFINITION).flatMap((node) => {
|
|
219
|
+
const name = node.name?.value;
|
|
220
|
+
const kind = node.operation;
|
|
221
|
+
if (!name || kind !== "query" && kind !== "mutation")
|
|
222
|
+
return [];
|
|
223
|
+
return [{ name, kind, node }];
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// src/options.ts
|
|
228
|
+
var NAME = "@nxgt/graphql-codegen-msw";
|
|
229
|
+
function checkedOptions(config) {
|
|
230
|
+
const endpoint = required(config, "endpoint", `set it to the URL your client sends its operations to, e.g. endpoint: 'https://api.example.com/graphql', or a path msw matches on any origin: '*/graphql'`);
|
|
231
|
+
const schemasImport = required(config, "schemasImport", `point it at the file @nxgt/graphql-codegen-zod writes, as this file imports it, e.g. schemasImport: './zod'`);
|
|
232
|
+
const typesImport = required(config, "typesImport", `point it at the module that exports each operation's result and variables types, as this file imports it: './graphql' for the client preset, or the file typescript-operations writes`);
|
|
233
|
+
return {
|
|
234
|
+
endpoint,
|
|
235
|
+
schemasImport,
|
|
236
|
+
typesImport,
|
|
237
|
+
invalidInput: invalidInputOf(config)
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
function required(config, option, what) {
|
|
241
|
+
const value = config[option];
|
|
242
|
+
if (typeof value === "string" && value.trim() !== "")
|
|
243
|
+
return value;
|
|
244
|
+
throw new Error(`${NAME}: ${option} is not set; ${what}.`);
|
|
245
|
+
}
|
|
246
|
+
function invalidInputOf(config) {
|
|
247
|
+
const choice = config.invalidInput ?? "invalid-input";
|
|
248
|
+
const translate = config.translate === undefined ? undefined : moduleExport("translate", config.translate, "./i18n#translate");
|
|
249
|
+
if (choice === "invalid-input")
|
|
250
|
+
return translate ? { kind: choice, translate } : { kind: choice };
|
|
251
|
+
if (translate) {
|
|
252
|
+
throw new Error(`${NAME}: translate words the default invalidInput's messages only, and invalidInput is "${choice}". Remove translate, or translate inside your own function.`);
|
|
253
|
+
}
|
|
254
|
+
if (choice === "bad-user-input")
|
|
255
|
+
return { kind: choice };
|
|
256
|
+
return {
|
|
257
|
+
kind: "own",
|
|
258
|
+
fn: moduleExport("invalidInput", choice, "./invalid-input#invalidInput")
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
function moduleExport(option, value, example) {
|
|
262
|
+
const at = value.lastIndexOf("#");
|
|
263
|
+
if (at <= 0 || at === value.length - 1) {
|
|
264
|
+
const choices = option === "invalidInput" ? `'invalid-input', 'bad-user-input' or ` : "";
|
|
265
|
+
throw new Error(`${NAME}: ${option} is "${value}"; write ${choices}'<module>#<export>', e.g. '${example}'.`);
|
|
266
|
+
}
|
|
267
|
+
return { module: value.slice(0, at), exported: value.slice(at + 1) };
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// src/index.ts
|
|
271
|
+
var RUNTIME = "@nxgt/graphql-codegen-msw/runtime";
|
|
272
|
+
function plugin(schema, documents, config = {}) {
|
|
273
|
+
const options = checkedOptions(config);
|
|
274
|
+
const naming = new Naming(config);
|
|
275
|
+
const operations = mockedOperations(documents);
|
|
276
|
+
const handlers = operations.map(({ name, kind }) => naming.handler(name, kind));
|
|
277
|
+
const twice = handlers.find((handler, index) => handlers.indexOf(handler) !== index);
|
|
278
|
+
if (twice) {
|
|
279
|
+
throw new Error(`@nxgt/graphql-codegen-msw: the file would declare ${twice} twice: two operations give it the same name. Rename one of them.`);
|
|
280
|
+
}
|
|
281
|
+
const imports = new Imports([
|
|
282
|
+
"endpoint",
|
|
283
|
+
"invalidInput",
|
|
284
|
+
"inputTypes",
|
|
285
|
+
...handlers
|
|
286
|
+
]);
|
|
287
|
+
const any = operations.length > 0;
|
|
288
|
+
const handler = any ? imports.type("msw/graphql", "GraphQLHandler") : "";
|
|
289
|
+
const runtime = {
|
|
290
|
+
resolver: any ? imports.type(RUNTIME, "GraphQLMockResolver") : "",
|
|
291
|
+
options: any ? imports.type(RUNTIME, "MockOptions") : "",
|
|
292
|
+
invalidInput: imports.type(RUNTIME, "InvalidInput"),
|
|
293
|
+
inputTypes: any ? imports.type(RUNTIME, "InputTypes") : "",
|
|
294
|
+
mock: any ? imports.value(RUNTIME, "mockOperation") : ""
|
|
295
|
+
};
|
|
296
|
+
const refusal = refusalCode(options, imports);
|
|
297
|
+
const blocks = operations.map((operation) => {
|
|
298
|
+
const { name, kind } = operation;
|
|
299
|
+
const result = imports.type(options.typesImport, naming.result(name, kind));
|
|
300
|
+
const variables = imports.type(options.typesImport, naming.variables(name, kind));
|
|
301
|
+
const schema = imports.value(options.schemasImport, naming.schema(naming.variables(name, kind)));
|
|
302
|
+
return handlerBlock(operation, naming.handler(name, kind), {
|
|
303
|
+
...runtime,
|
|
304
|
+
handler,
|
|
305
|
+
result,
|
|
306
|
+
variables,
|
|
307
|
+
schema
|
|
308
|
+
});
|
|
309
|
+
});
|
|
310
|
+
return `${[
|
|
311
|
+
imports.lines().join(`
|
|
312
|
+
`),
|
|
313
|
+
`/** Where the client sends its operations; a handler's \`options.endpoint\` overrides it. */
|
|
314
|
+
export const endpoint = ${JSON.stringify(options.endpoint)};`,
|
|
315
|
+
`/** How an invalid input is answered, without calling the resolver. */
|
|
316
|
+
export const invalidInput: ${runtime.invalidInput} = ${refusal};`,
|
|
317
|
+
...any ? [inputTypesBlock(schema, operations, runtime.inputTypes)] : [],
|
|
318
|
+
...blocks
|
|
319
|
+
].join(`
|
|
320
|
+
|
|
321
|
+
`)}
|
|
322
|
+
`;
|
|
323
|
+
}
|
|
324
|
+
function refusalCode(options, imports) {
|
|
325
|
+
const choice = options.invalidInput;
|
|
326
|
+
if (choice.kind === "bad-user-input")
|
|
327
|
+
return imports.value(RUNTIME, "badUserInputRefusal");
|
|
328
|
+
if (choice.kind === "own")
|
|
329
|
+
return imports.value(choice.fn.module, choice.fn.exported);
|
|
330
|
+
const refusal = imports.value(RUNTIME, "invalidInputRefusal");
|
|
331
|
+
if (!choice.translate)
|
|
332
|
+
return `${refusal}()`;
|
|
333
|
+
const translate = imports.value(choice.translate.module, choice.translate.exported);
|
|
334
|
+
return `${refusal}({ ${translate === "translate" ? translate : `translate: ${translate}`} })`;
|
|
335
|
+
}
|
|
336
|
+
function inputTypesBlock(schema, operations, type) {
|
|
337
|
+
const code = inputTypesCode(schema, operations.map(({ node }) => node));
|
|
338
|
+
return [
|
|
339
|
+
"/**",
|
|
340
|
+
" * The input types the variables reach, from the schema: how a handler words",
|
|
341
|
+
" * a value graphql refuses. Internal: its shape may change in any version.",
|
|
342
|
+
" */",
|
|
343
|
+
`const inputTypes: ${type} = ${code};`
|
|
344
|
+
].join(`
|
|
345
|
+
`);
|
|
346
|
+
}
|
|
347
|
+
function handlerBlock({ name, kind, node }, factory, names) {
|
|
348
|
+
const operation = `{ type: ${JSON.stringify(kind)}, name: ${JSON.stringify(name)}, variables: ${names.schema}, variableTypes: ${variableTypesCode(node)}, inputTypes, endpoint, invalidInput }`;
|
|
349
|
+
return [
|
|
350
|
+
`/** Mocks the ${name} ${kind}: \`resolver\` answers once the variables pass \`${names.schema}\`. */`,
|
|
351
|
+
`export function ${factory}(`,
|
|
352
|
+
` resolver: ${names.resolver}<${names.result}, ${names.variables}>,`,
|
|
353
|
+
` options?: ${names.options},`,
|
|
354
|
+
`): ${names.handler} {`,
|
|
355
|
+
` return ${names.mock}(${operation}, resolver, options);`,
|
|
356
|
+
"}"
|
|
357
|
+
].join(`
|
|
358
|
+
`);
|
|
359
|
+
}
|
|
360
|
+
export {
|
|
361
|
+
plugin
|
|
362
|
+
};
|
|
363
|
+
|
|
364
|
+
//# debugId=9EF728C8AF82F3D964756E2164756E21
|
|
365
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/imports.ts", "../src/input-types.ts", "../src/naming.ts", "../src/operations.ts", "../src/options.ts", "../src/index.ts"],
|
|
4
|
+
"sourcesContent": [
|
|
5
|
+
"/** One name imported from a module: its local name, and whether it is a type only. */\ninterface Imported {\n\treadonly local: string;\n\treadonly type: boolean;\n}\n\n/**\n * The named imports of the generated file, one line per module in the order\n * they were first asked for, an alias when a name is taken. A module whose\n * every name is a type is written `import type`.\n */\nexport class Imports {\n\treadonly #byModule = new Map<string, Map<string, Imported>>();\n\treadonly #taken: Set<string>;\n\n\t/** `reserved`: the names the file declares, which no import may take. */\n\tconstructor(reserved: Iterable<string> = []) {\n\t\tthis.#taken = new Set(reserved);\n\t}\n\n\t/** The local name of the value `exported` from `module`. */\n\tvalue(module: string, exported: string): string {\n\t\treturn this.#add(module, exported, false);\n\t}\n\n\t/** The local name of the type `exported` from `module`. */\n\ttype(module: string, exported: string): string {\n\t\treturn this.#add(module, exported, true);\n\t}\n\n\t#add(module: string, exported: string, type: boolean): string {\n\t\tconst names = this.#byModule.get(module) ?? new Map<string, Imported>();\n\t\tthis.#byModule.set(module, names);\n\t\tconst known = names.get(exported);\n\t\tif (known) {\n\t\t\tif (!type && known.type) names.set(exported, { ...known, type: false });\n\t\t\treturn known.local;\n\t\t}\n\t\tlet local = exported;\n\t\tfor (let n = 2; this.#taken.has(local); n++) local = `${exported}${n}`;\n\t\tthis.#taken.add(local);\n\t\tnames.set(exported, { local, type });\n\t\treturn local;\n\t}\n\n\t/** The import lines, double-quoted as every string the file holds. */\n\tlines(): string[] {\n\t\treturn [...this.#byModule].map(([module, names]) => {\n\t\t\tconst all = [...names];\n\t\t\tconst typeOnly = all.every(([, { type }]) => type);\n\t\t\tconst specifiers = all.map(([exported, { local, type }]) => {\n\t\t\t\tconst name = exported === local ? local : `${exported} as ${local}`;\n\t\t\t\treturn type && !typeOnly ? `type ${name}` : name;\n\t\t\t});\n\t\t\treturn `import ${typeOnly ? 'type ' : ''}{ ${specifiers.join(', ')} } from ${JSON.stringify(module)};`;\n\t\t});\n\t}\n}\n",
|
|
6
|
+
"import {\n\ttype GraphQLInputField,\n\ttype GraphQLNamedType,\n\ttype GraphQLSchema,\n\tgetNamedType,\n\tisEnumType,\n\tisInputObjectType,\n\tisNonNullType,\n\tisRequiredInputField,\n\tisSpecifiedScalarType,\n\tKind,\n\ttype OperationDefinitionNode,\n\tprint,\n\ttype TypeNode,\n} from 'graphql';\n\n// What the generated file tells the runtime of the variables, from the\n// schema at generation time, so the mock words a value graphql refuses as\n// graphql-yoga does: each variable's type, and every input type the\n// variables reach (the runtime's `InputTypes`, an internal shape).\n\n/** `{ first: \"Int = 10\", role: \"Role\" }`: each variable's type and default, as written. */\nexport function variableTypesCode(node: OperationDefinitionNode): string {\n\tconst entries = (node.variableDefinitions ?? []).map((definition) => {\n\t\tconst type = print(definition.type);\n\t\tconst source = definition.defaultValue\n\t\t\t? `${type} = ${print(definition.defaultValue)}`\n\t\t\t: type;\n\t\treturn `${definition.variable.name.value}: ${JSON.stringify(source)}`;\n\t});\n\treturn entries.length > 0 ? `{ ${entries.join(', ')} }` : '{}';\n}\n\n/**\n * The `inputTypes` object's source: every type the operations' variables\n * reach, input objects followed field by field, sorted by name so the file\n * does not move when the documents are reordered; a scalar on one line, an\n * input object's fields and an enum's values one per line.\n */\nexport function inputTypesCode(\n\tschema: GraphQLSchema,\n\toperations: readonly OperationDefinitionNode[],\n): string {\n\tconst reached = new Map<string, GraphQLNamedType>();\n\tconst visit = (type: GraphQLNamedType | undefined): void => {\n\t\tif (!type || reached.has(type.name)) return;\n\t\treached.set(type.name, type);\n\t\tif (isInputObjectType(type))\n\t\t\tfor (const field of Object.values(type.getFields()))\n\t\t\t\tvisit(getNamedType(field.type));\n\t};\n\tfor (const operation of operations)\n\t\tfor (const definition of operation.variableDefinitions ?? [])\n\t\t\tvisit(schema.getType(namedTypeOf(definition.type)) ?? undefined);\n\tconst entries = [...reached.values()]\n\t\t.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0))\n\t\t.map((type) => `\\t${type.name}: ${entryCode(type)},`);\n\treturn entries.length > 0 ? `{\\n${entries.join('\\n')}\\n}` : '{}';\n}\n\nfunction namedTypeOf(type: TypeNode): string {\n\treturn type.kind === Kind.NAMED_TYPE\n\t\t? type.name.value\n\t\t: namedTypeOf(type.type);\n}\n\n/**\n * One type's entry: a scalar on its line, an input object one field per\n * line and an enum one value per line, so a schema change moves the lines\n * it changes only.\n */\nfunction entryCode(type: GraphQLNamedType): string {\n\tif (isInputObjectType(type)) {\n\t\tconst fields = Object.values(type.getFields()).map(\n\t\t\t(field) => `${field.name}: ${JSON.stringify(fieldSource(field))}`,\n\t\t);\n\t\treturn block([\n\t\t\t'kind: \"input\"',\n\t\t\t`fields: ${block(fields, 2)}`,\n\t\t\t...(type.isOneOf ? ['oneOf: true'] : []),\n\t\t]);\n\t}\n\tif (isEnumType(type)) {\n\t\tconst values = type.getValues().map((value) => JSON.stringify(value.name));\n\t\treturn block(['kind: \"enum\"', `values: ${list(values, 2)}`]);\n\t}\n\treturn isSpecifiedScalarType(type)\n\t\t? '{ kind: \"builtin\" }'\n\t\t: '{ kind: \"scalar\" }';\n}\n\n/** `{ … }`, one property per line at `depth` tabs, its brace one tab less. */\nfunction block(properties: readonly string[], depth = 1): string {\n\treturn wrapped('{', '}', properties, depth);\n}\n\n/** `[ … ]`, one item per line, as `block`. */\nfunction list(items: readonly string[], depth: number): string {\n\treturn wrapped('[', ']', items, depth);\n}\n\nfunction wrapped(\n\topen: string,\n\tclose: string,\n\titems: readonly string[],\n\tdepth: number,\n): string {\n\tif (items.length === 0) return `${open}${close}`;\n\tconst indent = '\\t'.repeat(depth + 1);\n\tconst lines = items.map((item) => `${indent}${item},`);\n\treturn `${open}\\n${lines.join('\\n')}\\n${'\\t'.repeat(depth)}${close}`;\n}\n\n/**\n * `\"Int! = 1\"`: the field's type, and its default when it has one. Only a\n * non-null field's default changes what graphql refuses (it is then not\n * required); a schema built in code has no default to print, written `…`.\n */\nfunction fieldSource(field: GraphQLInputField): string {\n\tconst type = String(field.type);\n\tconst literal = field.astNode?.defaultValue;\n\tif (literal) return `${type} = ${print(literal)}`;\n\treturn isNonNullType(field.type) && !isRequiredInputField(field)\n\t\t? `${type} = …`\n\t\t: type;\n}\n",
|
|
7
|
+
"import * as changeCase from 'change-case';\nimport type { CodegenMswConfig } from './config';\n\n/** The operation kinds a handler is written for. */\nexport type MockedKind = 'query' | 'mutation';\n\n/**\n * The names the generated file uses: each type as `typescript-operations`\n * names it, each schema as `@nxgt/graphql-codegen-zod` names it (the type's\n * name behind `schemaPrefix`), and each handler `mock` and the operation's\n * converted name. Kept as codegen-zod's `naming.ts` (AGENTS.md lists the\n * copy): the spec generates both files and imports one from the other.\n */\nexport class Naming {\n\treadonly #config: CodegenMswConfig;\n\treadonly #convert: (name: string) => string;\n\n\tconstructor(config: CodegenMswConfig) {\n\t\tthis.#config = config;\n\t\tthis.#convert = converter(config.namingConvention);\n\t}\n\n\t/** An operation's variables type name: `SignUpMutationVariables`. */\n\tvariables(operation: string, kind: MockedKind): string {\n\t\treturn this.#wrap(\n\t\t\tthis.#convert(`${operation}${this.#suffix(operation, kind)}Variables`),\n\t\t);\n\t}\n\n\t/** An operation's result type name: `SignUpMutation`. */\n\tresult(operation: string, kind: MockedKind): string {\n\t\treturn this.#wrap(\n\t\t\tthis.#convert(`${operation}${this.#suffix(operation, kind)}`),\n\t\t);\n\t}\n\n\t/** The schema of the type named `type`: `zSignUpMutationVariables`. */\n\tschema(type: string): string {\n\t\treturn `${this.#config.schemaPrefix ?? 'z'}${type}`;\n\t}\n\n\t/** An operation's handler factory: `mockSignUpMutation`, no type prefix or suffix. */\n\thandler(operation: string, kind: MockedKind): string {\n\t\treturn `mock${this.#convert(`${operation}${this.#suffix(operation, kind)}`)}`;\n\t}\n\n\t/** As visitor-plugin-common's `getOperationSuffix`. */\n\t#suffix(operation: string, kind: MockedKind): string {\n\t\tconst type = changeCase.pascalCase(kind);\n\t\tconst { omitOperationSuffix, dedupeOperationSuffix } = this.#config;\n\t\treturn omitOperationSuffix ||\n\t\t\t(dedupeOperationSuffix &&\n\t\t\t\toperation.toLowerCase().endsWith(type.toLowerCase()))\n\t\t\t? ''\n\t\t\t: type;\n\t}\n\n\t#wrap(name: string): string {\n\t\treturn `${this.#config.typesPrefix ?? ''}${name}${this.#config.typesSuffix ?? ''}`;\n\t}\n}\n\ntype Convention = NonNullable<CodegenMswConfig['namingConvention']>;\ntype Case = (name: string) => string;\n\nconst lowerCaseFirst: Case = (name) =>\n\tname.charAt(0).toLowerCase() + name.slice(1);\nconst upperCaseFirst: Case = (name) =>\n\tname.charAt(0).toUpperCase() + name.slice(1);\n\n/**\n * The cases a `namingConvention` string can name, by module: change-case-all\n * 2's names (what the typescript plugins resolve), and change-case 5's.\n */\nconst cases: Readonly<Record<string, Readonly<Record<string, Case>>>> = {\n\t'change-case-all': {\n\t\tcamelCase: changeCase.camelCase,\n\t\tcapitalCase: changeCase.capitalCase,\n\t\tconstantCase: changeCase.constantCase,\n\t\tdotCase: changeCase.dotCase,\n\t\theaderCase: changeCase.trainCase,\n\t\tnoCase: changeCase.noCase,\n\t\tparamCase: changeCase.kebabCase,\n\t\tpascalCase: changeCase.pascalCase,\n\t\tpathCase: changeCase.pathCase,\n\t\tsentenceCase: changeCase.sentenceCase,\n\t\tsnakeCase: changeCase.snakeCase,\n\t\tlowerCase: (name) => name.toLowerCase(),\n\t\tupperCase: (name) => name.toUpperCase(),\n\t\tlowerCaseFirst,\n\t\tupperCaseFirst,\n\t},\n\t'change-case': {\n\t\tcamelCase: changeCase.camelCase,\n\t\tcapitalCase: changeCase.capitalCase,\n\t\tconstantCase: changeCase.constantCase,\n\t\tdotCase: changeCase.dotCase,\n\t\tkebabCase: changeCase.kebabCase,\n\t\tnoCase: changeCase.noCase,\n\t\tpascalCase: changeCase.pascalCase,\n\t\tpascalSnakeCase: changeCase.pascalSnakeCase,\n\t\tpathCase: changeCase.pathCase,\n\t\tsentenceCase: changeCase.sentenceCase,\n\t\tsnakeCase: changeCase.snakeCase,\n\t\ttrainCase: changeCase.trainCase,\n\t},\n};\n\n/** Applies `fn` to each part between underscores, or to the whole name. */\nconst byPart =\n\t(fn: Case, transformUnderscore: boolean): Case =>\n\t(name) =>\n\t\ttransformUnderscore ? fn(name) : name.split('_').map(fn).join('_');\n\n/**\n * A `namingConvention` as `@graphql-codegen/visitor-plugin-common`'s\n * `convertFactory` reads it for type names: undefined is PascalCase per\n * part; `'keep'`; a `'change-case-all#<case>'` string or a function, per\n * part; an object's `typeNames`, on the whole name, or, without\n * `typeNames`, PascalCase per part unless `transformUnderscore` is true.\n */\nfunction converter(convention: Convention | undefined): Case {\n\tif (convention === undefined) return byPart(changeCase.pascalCase, false);\n\tif (convention === 'keep') return (name) => name;\n\tif (typeof convention === 'function') return byPart(convention, false);\n\tif (typeof convention === 'string')\n\t\treturn byPart(caseNamed(convention), false);\n\tconst { typeNames, transformUnderscore } = convention;\n\tif (typeNames === 'keep') return (name) => name;\n\tif (typeNames === undefined)\n\t\treturn byPart(changeCase.pascalCase, transformUnderscore ?? false);\n\tconst fn = typeof typeNames === 'function' ? typeNames : caseNamed(typeNames);\n\treturn byPart(fn, true);\n}\n\nfunction caseNamed(spec: string): Case {\n\tconst [module = '', name = ''] = spec.split('#');\n\tconst fn = cases[module]?.[name];\n\tif (fn) return fn;\n\tthrow new Error(\n\t\t`@nxgt/graphql-codegen-msw: namingConvention \"${spec}\" is not one this plugin reads. Use 'keep', a function, or 'change-case-all#<case>' with one of ${Object.keys(cases['change-case-all'] ?? {}).join(', ')}.`,\n\t);\n}\n",
|
|
8
|
+
"import { Kind, type OperationDefinitionNode } from 'graphql';\nimport type { DocumentFile } from './config';\nimport type { MockedKind } from './naming';\n\n/** A named query or mutation of the documents. */\nexport interface MockedOperationNode {\n\treadonly name: string;\n\treadonly kind: MockedKind;\n\treadonly node: OperationDefinitionNode;\n}\n\n/**\n * Every named query and mutation, in document order. An anonymous\n * operation has no name for msw to match, and a subscription is not an\n * HTTP request msw's `query` or `mutation` handler answers: neither gets a\n * handler.\n */\nexport function mockedOperations(\n\tdocuments: readonly DocumentFile[],\n): MockedOperationNode[] {\n\treturn documents\n\t\t.flatMap((file) => file.document?.definitions ?? [])\n\t\t.filter(\n\t\t\t(node): node is OperationDefinitionNode =>\n\t\t\t\tnode.kind === Kind.OPERATION_DEFINITION,\n\t\t)\n\t\t.flatMap((node) => {\n\t\t\tconst name = node.name?.value;\n\t\t\tconst kind: string = node.operation;\n\t\t\tif (!name || (kind !== 'query' && kind !== 'mutation')) return [];\n\t\t\treturn [{ name, kind: kind as MockedKind, node }];\n\t\t});\n}\n",
|
|
9
|
+
"import type { CodegenMswConfig } from './config';\n\n/** The plugin's name, before each of its messages. */\nconst NAME = '@nxgt/graphql-codegen-msw';\n\n/** How an invalid input is answered, as the config names it. */\nexport type InvalidInputChoice =\n\t| { readonly kind: 'invalid-input'; readonly translate?: ModuleExport }\n\t| { readonly kind: 'bad-user-input' }\n\t| { readonly kind: 'own'; readonly fn: ModuleExport };\n\n/** A `'<module>#<export>'` option, split. */\nexport interface ModuleExport {\n\treadonly module: string;\n\treadonly exported: string;\n}\n\n/** The options the plugin cannot write a file without, checked. */\nexport interface CheckedOptions {\n\treadonly endpoint: string;\n\treadonly schemasImport: string;\n\treadonly typesImport: string;\n\treadonly invalidInput: InvalidInputChoice;\n}\n\n/**\n * The config, checked before anything is written: each required option is\n * set, and `invalidInput` and `translate` say something this plugin reads.\n * Each message names the option and what to write; each has an entry in\n * docs/troubleshooting.md, headed by it.\n */\nexport function checkedOptions(config: CodegenMswConfig): CheckedOptions {\n\tconst endpoint = required(\n\t\tconfig,\n\t\t'endpoint',\n\t\t`set it to the URL your client sends its operations to, e.g. endpoint: 'https://api.example.com/graphql', or a path msw matches on any origin: '*/graphql'`,\n\t);\n\tconst schemasImport = required(\n\t\tconfig,\n\t\t'schemasImport',\n\t\t`point it at the file @nxgt/graphql-codegen-zod writes, as this file imports it, e.g. schemasImport: './zod'`,\n\t);\n\tconst typesImport = required(\n\t\tconfig,\n\t\t'typesImport',\n\t\t`point it at the module that exports each operation's result and variables types, as this file imports it: './graphql' for the client preset, or the file typescript-operations writes`,\n\t);\n\treturn {\n\t\tendpoint,\n\t\tschemasImport,\n\t\ttypesImport,\n\t\tinvalidInput: invalidInputOf(config),\n\t};\n}\n\nfunction required(\n\tconfig: CodegenMswConfig,\n\toption: 'endpoint' | 'schemasImport' | 'typesImport',\n\twhat: string,\n): string {\n\tconst value: unknown = config[option];\n\tif (typeof value === 'string' && value.trim() !== '') return value;\n\tthrow new Error(`${NAME}: ${option} is not set; ${what}.`);\n}\n\nfunction invalidInputOf(config: CodegenMswConfig): InvalidInputChoice {\n\tconst choice = config.invalidInput ?? 'invalid-input';\n\tconst translate =\n\t\tconfig.translate === undefined\n\t\t\t? undefined\n\t\t\t: moduleExport('translate', config.translate, './i18n#translate');\n\tif (choice === 'invalid-input')\n\t\treturn translate ? { kind: choice, translate } : { kind: choice };\n\tif (translate) {\n\t\tthrow new Error(\n\t\t\t`${NAME}: translate words the default invalidInput's messages only, and invalidInput is \"${choice}\". Remove translate, or translate inside your own function.`,\n\t\t);\n\t}\n\tif (choice === 'bad-user-input') return { kind: choice };\n\treturn {\n\t\tkind: 'own',\n\t\tfn: moduleExport('invalidInput', choice, './invalid-input#invalidInput'),\n\t};\n}\n\n/** `'<module>#<export>'` split in two, or an error naming the option. */\nfunction moduleExport(\n\toption: string,\n\tvalue: string,\n\texample: string,\n): ModuleExport {\n\tconst at = value.lastIndexOf('#');\n\tif (at <= 0 || at === value.length - 1) {\n\t\tconst choices =\n\t\t\toption === 'invalidInput' ? `'invalid-input', 'bad-user-input' or ` : '';\n\t\tthrow new Error(\n\t\t\t`${NAME}: ${option} is \"${value}\"; write ${choices}'<module>#<export>', e.g. '${example}'.`,\n\t\t);\n\t}\n\treturn { module: value.slice(0, at), exported: value.slice(at + 1) };\n}\n",
|
|
10
|
+
"import type { GraphQLSchema } from 'graphql';\nimport type { CodegenMswConfig, DocumentFile } from './config';\nimport { Imports } from './imports';\nimport { inputTypesCode, variableTypesCode } from './input-types';\nimport { Naming } from './naming';\nimport { type MockedOperationNode, mockedOperations } from './operations';\nimport { type CheckedOptions, checkedOptions } from './options';\n\nexport type { CodegenMswConfig, DocumentFile } from './config';\n\n/** Where the generated file takes `mockOperation` and the refusals from. */\nconst RUNTIME = '@nxgt/graphql-codegen-msw/runtime';\n\n/**\n * The graphql-codegen plugin: one msw handler factory per named query and\n * mutation of `documents`, `mock<Operation>(resolver, options?)`, typed with\n * the operation's result and variables types, its variables checked with\n * `@nxgt/graphql-codegen-zod`'s schema before the resolver runs. The schema\n * gives the input types the variables reach, written once as `inputTypes`\n * for the answer to a value graphql refuses.\n */\nexport function plugin(\n\tschema: GraphQLSchema,\n\tdocuments: readonly DocumentFile[],\n\tconfig: CodegenMswConfig = {},\n): string {\n\tconst options = checkedOptions(config);\n\tconst naming = new Naming(config);\n\tconst operations = mockedOperations(documents);\n\tconst handlers = operations.map(({ name, kind }) =>\n\t\tnaming.handler(name, kind),\n\t);\n\tconst twice = handlers.find(\n\t\t(handler, index) => handlers.indexOf(handler) !== index,\n\t);\n\tif (twice) {\n\t\tthrow new Error(\n\t\t\t`@nxgt/graphql-codegen-msw: the file would declare ${twice} twice: two operations give it the same name. Rename one of them.`,\n\t\t);\n\t}\n\tconst imports = new Imports([\n\t\t'endpoint',\n\t\t'invalidInput',\n\t\t'inputTypes',\n\t\t...handlers,\n\t]);\n\t// Only what the file uses is imported: no operation, no handler types.\n\tconst any = operations.length > 0;\n\tconst handler = any ? imports.type('msw/graphql', 'GraphQLHandler') : '';\n\tconst runtime = {\n\t\tresolver: any ? imports.type(RUNTIME, 'GraphQLMockResolver') : '',\n\t\toptions: any ? imports.type(RUNTIME, 'MockOptions') : '',\n\t\tinvalidInput: imports.type(RUNTIME, 'InvalidInput'),\n\t\tinputTypes: any ? imports.type(RUNTIME, 'InputTypes') : '',\n\t\tmock: any ? imports.value(RUNTIME, 'mockOperation') : '',\n\t};\n\tconst refusal = refusalCode(options, imports);\n\tconst blocks = operations.map((operation) => {\n\t\tconst { name, kind } = operation;\n\t\tconst result = imports.type(options.typesImport, naming.result(name, kind));\n\t\tconst variables = imports.type(\n\t\t\toptions.typesImport,\n\t\t\tnaming.variables(name, kind),\n\t\t);\n\t\tconst schema = imports.value(\n\t\t\toptions.schemasImport,\n\t\t\tnaming.schema(naming.variables(name, kind)),\n\t\t);\n\t\treturn handlerBlock(operation, naming.handler(name, kind), {\n\t\t\t...runtime,\n\t\t\thandler,\n\t\t\tresult,\n\t\t\tvariables,\n\t\t\tschema,\n\t\t});\n\t});\n\treturn `${[\n\t\timports.lines().join('\\n'),\n\t\t`/** Where the client sends its operations; a handler's \\`options.endpoint\\` overrides it. */\\nexport const endpoint = ${JSON.stringify(options.endpoint)};`,\n\t\t`/** How an invalid input is answered, without calling the resolver. */\\nexport const invalidInput: ${runtime.invalidInput} = ${refusal};`,\n\t\t...(any ? [inputTypesBlock(schema, operations, runtime.inputTypes)] : []),\n\t\t...blocks,\n\t].join('\\n\\n')}\\n`;\n}\n\n/** The source of the `invalidInput` constant, its imports added. */\nfunction refusalCode(options: CheckedOptions, imports: Imports): string {\n\tconst choice = options.invalidInput;\n\tif (choice.kind === 'bad-user-input')\n\t\treturn imports.value(RUNTIME, 'badUserInputRefusal');\n\tif (choice.kind === 'own')\n\t\treturn imports.value(choice.fn.module, choice.fn.exported);\n\tconst refusal = imports.value(RUNTIME, 'invalidInputRefusal');\n\tif (!choice.translate) return `${refusal}()`;\n\tconst translate = imports.value(\n\t\tchoice.translate.module,\n\t\tchoice.translate.exported,\n\t);\n\treturn `${refusal}({ ${translate === 'translate' ? translate : `translate: ${translate}`} })`;\n}\n\n/** The file's private `inputTypes`, which every handler passes on. */\nfunction inputTypesBlock(\n\tschema: GraphQLSchema,\n\toperations: readonly MockedOperationNode[],\n\ttype: string,\n): string {\n\tconst code = inputTypesCode(\n\t\tschema,\n\t\toperations.map(({ node }) => node),\n\t);\n\treturn [\n\t\t'/**',\n\t\t' * The input types the variables reach, from the schema: how a handler words',\n\t\t' * a value graphql refuses. Internal: its shape may change in any version.',\n\t\t' */',\n\t\t`const inputTypes: ${type} = ${code};`,\n\t].join('\\n');\n}\n\n/** The local names one handler's source uses. */\ninterface HandlerNames {\n\treadonly handler: string;\n\treadonly resolver: string;\n\treadonly options: string;\n\treadonly mock: string;\n\treadonly result: string;\n\treadonly variables: string;\n\treadonly schema: string;\n}\n\nfunction handlerBlock(\n\t{ name, kind, node }: MockedOperationNode,\n\tfactory: string,\n\tnames: HandlerNames,\n): string {\n\tconst operation = `{ type: ${JSON.stringify(kind)}, name: ${JSON.stringify(name)}, variables: ${names.schema}, variableTypes: ${variableTypesCode(node)}, inputTypes, endpoint, invalidInput }`;\n\treturn [\n\t\t`/** Mocks the ${name} ${kind}: \\`resolver\\` answers once the variables pass \\`${names.schema}\\`. */`,\n\t\t`export function ${factory}(`,\n\t\t`\\tresolver: ${names.resolver}<${names.result}, ${names.variables}>,`,\n\t\t`\\toptions?: ${names.options},`,\n\t\t`): ${names.handler} {`,\n\t\t`\\treturn ${names.mock}(${operation}, resolver, options);`,\n\t\t'}',\n\t].join('\\n');\n}\n"
|
|
11
|
+
],
|
|
12
|
+
"mappings": ";AAWO,MAAM,QAAQ;AAAA,EACX,YAAY,IAAI;AAAA,EAChB;AAAA,EAGT,WAAW,CAA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C,EAAE,KAAK;AAAA,CAAI;AAAA;AAcZ,SAAS,YAAY,GAClB,MAAM,MAAM,QACd,SACA,OACS;AAAA,EACT,MAAM,YAAY,WAAW,KAAK,UAAU,IAAI,YAAY,KAAK,UAAU,IAAI,iBAAiB,MAAM,0BAA0B,kBAAkB,IAAI;AAAA,EACtJ,OAAO;AAAA,IACN,iBAAiB,QAAQ,wDAAwD,MAAM;AAAA,IACvF,mBAAmB;AAAA,IACnB,cAAe,MAAM,YAAY,MAAM,WAAW,MAAM;AAAA,IACxD,cAAe,MAAM;AAAA,IACrB,MAAM,MAAM;AAAA,IACZ,WAAY,MAAM,QAAQ;AAAA,IAC1B;AAAA,EACD,EAAE,KAAK;AAAA,CAAI;AAAA;",
|
|
13
|
+
"debugId": "9EF728C8AF82F3D964756E2164756E21",
|
|
14
|
+
"names": []
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type GraphQLSchema, type OperationDefinitionNode } from 'graphql';
|
|
2
|
+
/** `{ first: "Int = 10", role: "Role" }`: each variable's type and default, as written. */
|
|
3
|
+
export declare function variableTypesCode(node: OperationDefinitionNode): string;
|
|
4
|
+
/**
|
|
5
|
+
* The `inputTypes` object's source: every type the operations' variables
|
|
6
|
+
* reach, input objects followed field by field, sorted by name so the file
|
|
7
|
+
* does not move when the documents are reordered; a scalar on one line, an
|
|
8
|
+
* input object's fields and an enum's values one per line.
|
|
9
|
+
*/
|
|
10
|
+
export declare function inputTypesCode(schema: GraphQLSchema, operations: readonly OperationDefinitionNode[]): string;
|
|
11
|
+
//# sourceMappingURL=input-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"input-types.d.ts","sourceRoot":"","sources":["../src/input-types.ts"],"names":[],"mappings":"AAAA,OAAO,EAGN,KAAK,aAAa,EAQlB,KAAK,uBAAuB,EAG5B,MAAM,SAAS,CAAC;AAOjB,2FAA2F;AAC3F,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,uBAAuB,GAAG,MAAM,CASvE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC7B,MAAM,EAAE,aAAa,EACrB,UAAU,EAAE,SAAS,uBAAuB,EAAE,GAC5C,MAAM,CAgBR"}
|
package/dist/naming.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { CodegenMswConfig } from './config.js';
|
|
2
|
+
/** The operation kinds a handler is written for. */
|
|
3
|
+
export type MockedKind = 'query' | 'mutation';
|
|
4
|
+
/**
|
|
5
|
+
* The names the generated file uses: each type as `typescript-operations`
|
|
6
|
+
* names it, each schema as `@nxgt/graphql-codegen-zod` names it (the type's
|
|
7
|
+
* name behind `schemaPrefix`), and each handler `mock` and the operation's
|
|
8
|
+
* converted name. Kept as codegen-zod's `naming.ts` (AGENTS.md lists the
|
|
9
|
+
* copy): the spec generates both files and imports one from the other.
|
|
10
|
+
*/
|
|
11
|
+
export declare class Naming {
|
|
12
|
+
#private;
|
|
13
|
+
constructor(config: CodegenMswConfig);
|
|
14
|
+
/** An operation's variables type name: `SignUpMutationVariables`. */
|
|
15
|
+
variables(operation: string, kind: MockedKind): string;
|
|
16
|
+
/** An operation's result type name: `SignUpMutation`. */
|
|
17
|
+
result(operation: string, kind: MockedKind): string;
|
|
18
|
+
/** The schema of the type named `type`: `zSignUpMutationVariables`. */
|
|
19
|
+
schema(type: string): string;
|
|
20
|
+
/** An operation's handler factory: `mockSignUpMutation`, no type prefix or suffix. */
|
|
21
|
+
handler(operation: string, kind: MockedKind): string;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=naming.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"naming.d.ts","sourceRoot":"","sources":["../src/naming.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjD,oDAAoD;AACpD,MAAM,MAAM,UAAU,GAAG,OAAO,GAAG,UAAU,CAAC;AAE9C;;;;;;GAMG;AACH,qBAAa,MAAM;;gBAIN,MAAM,EAAE,gBAAgB;IAKpC,qEAAqE;IACrE,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM;IAMtD,yDAAyD;IACzD,MAAM,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM;IAMnD,uEAAuE;IACvE,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAI5B,sFAAsF;IACtF,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,GAAG,MAAM;CAkBpD"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type OperationDefinitionNode } from 'graphql';
|
|
2
|
+
import type { DocumentFile } from './config.js';
|
|
3
|
+
import type { MockedKind } from './naming.js';
|
|
4
|
+
/** A named query or mutation of the documents. */
|
|
5
|
+
export interface MockedOperationNode {
|
|
6
|
+
readonly name: string;
|
|
7
|
+
readonly kind: MockedKind;
|
|
8
|
+
readonly node: OperationDefinitionNode;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Every named query and mutation, in document order. An anonymous
|
|
12
|
+
* operation has no name for msw to match, and a subscription is not an
|
|
13
|
+
* HTTP request msw's `query` or `mutation` handler answers: neither gets a
|
|
14
|
+
* handler.
|
|
15
|
+
*/
|
|
16
|
+
export declare function mockedOperations(documents: readonly DocumentFile[]): MockedOperationNode[];
|
|
17
|
+
//# sourceMappingURL=operations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"operations.d.ts","sourceRoot":"","sources":["../src/operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE3C,kDAAkD;AAClD,MAAM,WAAW,mBAAmB;IACnC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,uBAAuB,CAAC;CACvC;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAC/B,SAAS,EAAE,SAAS,YAAY,EAAE,GAChC,mBAAmB,EAAE,CAavB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { CodegenMswConfig } from './config.js';
|
|
2
|
+
/** How an invalid input is answered, as the config names it. */
|
|
3
|
+
export type InvalidInputChoice = {
|
|
4
|
+
readonly kind: 'invalid-input';
|
|
5
|
+
readonly translate?: ModuleExport;
|
|
6
|
+
} | {
|
|
7
|
+
readonly kind: 'bad-user-input';
|
|
8
|
+
} | {
|
|
9
|
+
readonly kind: 'own';
|
|
10
|
+
readonly fn: ModuleExport;
|
|
11
|
+
};
|
|
12
|
+
/** A `'<module>#<export>'` option, split. */
|
|
13
|
+
export interface ModuleExport {
|
|
14
|
+
readonly module: string;
|
|
15
|
+
readonly exported: string;
|
|
16
|
+
}
|
|
17
|
+
/** The options the plugin cannot write a file without, checked. */
|
|
18
|
+
export interface CheckedOptions {
|
|
19
|
+
readonly endpoint: string;
|
|
20
|
+
readonly schemasImport: string;
|
|
21
|
+
readonly typesImport: string;
|
|
22
|
+
readonly invalidInput: InvalidInputChoice;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* The config, checked before anything is written: each required option is
|
|
26
|
+
* set, and `invalidInput` and `translate` say something this plugin reads.
|
|
27
|
+
* Each message names the option and what to write; each has an entry in
|
|
28
|
+
* docs/troubleshooting.md, headed by it.
|
|
29
|
+
*/
|
|
30
|
+
export declare function checkedOptions(config: CodegenMswConfig): CheckedOptions;
|
|
31
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAKjD,gEAAgE;AAChE,MAAM,MAAM,kBAAkB,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,eAAe,CAAC;IAAC,QAAQ,CAAC,SAAS,CAAC,EAAE,YAAY,CAAA;CAAE,GACrE;IAAE,QAAQ,CAAC,IAAI,EAAE,gBAAgB,CAAA;CAAE,GACnC;IAAE,QAAQ,CAAC,IAAI,EAAE,KAAK,CAAC;IAAC,QAAQ,CAAC,EAAE,EAAE,YAAY,CAAA;CAAE,CAAC;AAEvD,6CAA6C;AAC7C,MAAM,WAAW,YAAY;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC1B;AAED,mEAAmE;AACnE,MAAM,WAAW,cAAc;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,aAAa,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,YAAY,EAAE,kBAAkB,CAAC;CAC1C;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,gBAAgB,GAAG,cAAc,CAsBvE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*!
|
|
2
|
+
* Ported from cross-inspect 1.0.1 (packages/inspect),
|
|
3
|
+
* https://github.com/ardatan/graphql-tools
|
|
4
|
+
* Copyright (c) 2020 The Guild, Inc.
|
|
5
|
+
* itself taken from graphql-js, https://github.com/graphql/graphql-js
|
|
6
|
+
* Copyright (c) GraphQL Contributors
|
|
7
|
+
* @license MIT
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* A value as @graphql-tools/executor prints it in the messages it words
|
|
11
|
+
* itself (the input objects' and the variable's prefix), through
|
|
12
|
+
* `cross-inspect`: a string quoted, `{ a: 1, b: "x" }`, `[1, 2]`, `{}` and
|
|
13
|
+
* `[]`, `[Object]` or `[Array]` beyond three levels, and every item of a
|
|
14
|
+
* list. The variables come from JSON, so no function, error or cycle
|
|
15
|
+
* reaches it: those branches of cross-inspect are left out. graphql's own
|
|
16
|
+
* messages print with graphql's `inspect` (`inspect.ts`).
|
|
17
|
+
*/
|
|
18
|
+
export declare function crossInspect(value: unknown): string;
|
|
19
|
+
//# sourceMappingURL=cross-inspect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cross-inspect.d.ts","sourceRoot":"","sources":["../../../src/runtime/coercion/cross-inspect.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH;;;;;;;;GAQG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAEnD"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { type VariableDefinitionNode } from 'graphql';
|
|
2
|
+
/**
|
|
3
|
+
* One GraphQL type the variables reach, as the generated file describes it
|
|
4
|
+
* from the schema: a built-in scalar (`String`, `Int`, `Float`, `Boolean`,
|
|
5
|
+
* `ID`), a custom scalar, an enum and its values, or an input object and
|
|
6
|
+
* the type of each field (`"[String!]"`, `"Int! = 1"` with a default).
|
|
7
|
+
*
|
|
8
|
+
* Internal: written by the plugin and read by the coercion answer only. Its
|
|
9
|
+
* form may change in any version, together with the generated file.
|
|
10
|
+
*/
|
|
11
|
+
export type InputType = {
|
|
12
|
+
readonly kind: 'builtin';
|
|
13
|
+
} | {
|
|
14
|
+
readonly kind: 'scalar';
|
|
15
|
+
} | {
|
|
16
|
+
readonly kind: 'enum';
|
|
17
|
+
readonly values: readonly string[];
|
|
18
|
+
} | {
|
|
19
|
+
readonly kind: 'input';
|
|
20
|
+
readonly fields: Readonly<Record<string, string>>;
|
|
21
|
+
readonly oneOf?: true;
|
|
22
|
+
};
|
|
23
|
+
/** The input types of one generated file, by name. Internal, as `InputType`. */
|
|
24
|
+
export type InputTypes = Readonly<Record<string, InputType>>;
|
|
25
|
+
/** A type as graphql-js walks it: non-null and list wrappers around a name. */
|
|
26
|
+
export type TypeRef = {
|
|
27
|
+
readonly kind: 'non-null';
|
|
28
|
+
readonly of: TypeRef;
|
|
29
|
+
} | {
|
|
30
|
+
readonly kind: 'list';
|
|
31
|
+
readonly of: TypeRef;
|
|
32
|
+
} | {
|
|
33
|
+
readonly kind: 'named';
|
|
34
|
+
readonly name: string;
|
|
35
|
+
};
|
|
36
|
+
/** A variable's or an input field's declaration: its type, and whether it has a default. */
|
|
37
|
+
export interface Declared {
|
|
38
|
+
readonly type: TypeRef;
|
|
39
|
+
readonly hasDefault: boolean;
|
|
40
|
+
}
|
|
41
|
+
/** `"[Int!]! = [1]"` read: the type before ` = `, a default after it. */
|
|
42
|
+
export declare function declared(source: string): Declared;
|
|
43
|
+
/** A type as graphql-js prints it in a message: `[Int!]!`. */
|
|
44
|
+
export declare function printType(type: TypeRef): string;
|
|
45
|
+
/**
|
|
46
|
+
* The variables' definitions of the operation named `name` in the query the
|
|
47
|
+
* client sent, by variable: where each error is located. Empty when the
|
|
48
|
+
* query does not parse.
|
|
49
|
+
*/
|
|
50
|
+
export declare function definitionsOf(query: string, name: string): ReadonlyMap<string, VariableDefinitionNode>;
|
|
51
|
+
//# sourceMappingURL=document.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document.d.ts","sourceRoot":"","sources":["../../../src/runtime/coercion/document.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,KAAK,sBAAsB,EAC3B,MAAM,SAAS,CAAC;AAEjB;;;;;;;;GAQG;AACH,MAAM,MAAM,SAAS,GAClB;IAAE,QAAQ,CAAC,IAAI,EAAE,SAAS,CAAA;CAAE,GAC5B;IAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAA;CAAE,GAC3B;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ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