graphql-data-generator 0.4.0-alpha.3 → 0.4.0-alpha.5
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/esm/cli.js +2 -3
- package/esm/codegen.js +4 -2
- package/esm/index.js +1 -1
- package/esm/init.js +91 -7
- package/esm/jest.js +1 -1
- package/esm/plugin.cjs +1 -2
- package/esm/proxy.js +1 -1
- package/esm/util.js +0 -33
- package/package.json +1 -1
- package/script/cli.js +2 -3
- package/script/codegen.js +4 -2
- package/script/index.js +1 -2
- package/script/init.js +89 -5
- package/script/jest.js +1 -1
- package/script/plugin.cjs +1 -2
- package/script/proxy.js +16 -15
- package/script/util.js +1 -35
- package/types/index.d.ts +1 -1
- package/types/init.d.ts +1 -1
- package/types/proxy.d.ts +17 -1
- package/types/util.d.ts +0 -1
package/esm/cli.js
CHANGED
|
@@ -4,7 +4,6 @@ import { readFile } from "node:fs";
|
|
|
4
4
|
import fg from "fast-glob";
|
|
5
5
|
import { parseArgs } from "node:util";
|
|
6
6
|
import { codegen, loadFiles } from "./codegen.js";
|
|
7
|
-
import { formatCode } from "./util.js";
|
|
8
7
|
import process from "node:process";
|
|
9
8
|
(async () => {
|
|
10
9
|
const args = parseArgs({
|
|
@@ -80,14 +79,14 @@ import process from "node:process";
|
|
|
80
79
|
banner = args.banner;
|
|
81
80
|
}
|
|
82
81
|
try {
|
|
83
|
-
const file = banner +
|
|
82
|
+
const file = banner + codegen(schema, operations, {
|
|
84
83
|
enums: args.enums,
|
|
85
84
|
includeTypenames: !args.notypenames,
|
|
86
85
|
scalars,
|
|
87
86
|
exports,
|
|
88
87
|
typesFile: args.typesFile,
|
|
89
88
|
namingConvention: args.namingConvention,
|
|
90
|
-
})
|
|
89
|
+
});
|
|
91
90
|
if (args.outfile)
|
|
92
91
|
await dntShim.Deno.writeTextFile(args.outfile, file);
|
|
93
92
|
else
|
package/esm/codegen.js
CHANGED
|
@@ -547,7 +547,9 @@ ${includeTypenames ? ` __typename: "${name}";\n` : ""}${type.fields?.filter((f)
|
|
|
547
547
|
: usedTypes.filter(([, t]) => t.kind === Kind.OBJECT_TYPE_DEFINITION &&
|
|
548
548
|
t.interfaces?.some((i) => i.name.value === name)).map(([name]) => name).join(" | ")};`).filter(filterOutputTypes), `export type Types = {
|
|
549
549
|
${usedTypes.map(([name]) => ` ${name}: ${rename(name)};`).join("\n")}
|
|
550
|
-
};`, `export const types =
|
|
550
|
+
};`, `export const types = {\n${usedTypes.map(([name, type, usage]) => ` ${name.match(/^[$A-Za-z_][0-9A-Za-z_$]*$/) ? name : `"${name}"`}: ${type.kind === "ObjectTypeDefinition"
|
|
551
|
+
? `[${type.fields?.filter((f) => usage.has(f.name.value)).map((v) => `"${v.name.value}"`).join(", ")}]`
|
|
552
|
+
: "[]"}`).join(",\n")},\n} as const;`);
|
|
551
553
|
}
|
|
552
554
|
const usedReferences = Object.values(references).filter((r) => r[1]).map((r) => r[0]);
|
|
553
555
|
serializedTypes.unshift(...usedReferences.map((r) => {
|
|
@@ -602,6 +604,6 @@ export const loadFiles = async (schemaPath, operationDirs) => {
|
|
|
602
604
|
}
|
|
603
605
|
return [
|
|
604
606
|
await readFile(schemaPath, "utf-8"),
|
|
605
|
-
await Promise.all(operationPromises),
|
|
607
|
+
(await Promise.all(operationPromises)).sort((a, b) => a.path.localeCompare(b.path)),
|
|
606
608
|
];
|
|
607
609
|
};
|
package/esm/index.js
CHANGED
package/esm/init.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as dntShim from "./_dnt.shims.js";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { readFileSync } from "node:fs";
|
|
4
|
-
import { Kind, parse } from "graphql";
|
|
4
|
+
import { Kind, parse, } from "graphql";
|
|
5
5
|
import { gqlPluckFromCodeStringSync } from "@graphql-tools/graphql-tag-pluck";
|
|
6
|
-
import {
|
|
6
|
+
import { _proxy, operation, withGetDefaultPatch } from "./proxy.js";
|
|
7
7
|
import { toObject } from "./util.js";
|
|
8
8
|
import { dirname, resolve } from "node:path";
|
|
9
9
|
globalThis.require ??= createRequire(dntShim.Deno.cwd());
|
|
@@ -43,6 +43,10 @@ const getOperationContent = (path, operationName) => {
|
|
|
43
43
|
}
|
|
44
44
|
return getOperationContent(path, operationName);
|
|
45
45
|
};
|
|
46
|
+
// Helper: Unwraps non-null and list wrappers to get the named type.
|
|
47
|
+
const getNamedType = (type) => type.kind === Kind.NAMED_TYPE ? type.name.value : getNamedType(type.type);
|
|
48
|
+
// Helper: Find a type definition in the document by name.
|
|
49
|
+
const getTypeDef = (doc, typeName) => doc.definitions.find((def) => "name" in def && def.name?.value === typeName);
|
|
46
50
|
/**
|
|
47
51
|
* Initialize the data builder.
|
|
48
52
|
* @param schema The plain text of your schema.
|
|
@@ -72,7 +76,87 @@ export const init = (schema, queries, mutations, subscriptions, types, inputs, s
|
|
|
72
76
|
}])));
|
|
73
77
|
return obj;
|
|
74
78
|
};
|
|
75
|
-
const
|
|
79
|
+
const getSelectionSetMemory = new Map();
|
|
80
|
+
const getSelectionSet = (type) => {
|
|
81
|
+
if (getSelectionSetMemory.has(type)) {
|
|
82
|
+
return getSelectionSetMemory.get(type);
|
|
83
|
+
}
|
|
84
|
+
const fields = types[type];
|
|
85
|
+
if (!fields)
|
|
86
|
+
return;
|
|
87
|
+
const typeDef = getTypeDef(doc, type);
|
|
88
|
+
if (!typeDef || !("fields" in typeDef))
|
|
89
|
+
return;
|
|
90
|
+
const selectionSet = {
|
|
91
|
+
kind: Kind.SELECTION_SET,
|
|
92
|
+
selections: [],
|
|
93
|
+
};
|
|
94
|
+
getSelectionSetMemory.set(type, selectionSet);
|
|
95
|
+
// Build each field node.
|
|
96
|
+
selectionSet.selections = fields.map((fieldName) => {
|
|
97
|
+
const fieldNode = {
|
|
98
|
+
kind: Kind.FIELD,
|
|
99
|
+
name: { kind: Kind.NAME, value: fieldName },
|
|
100
|
+
};
|
|
101
|
+
// Look for the field definition in the type definition.
|
|
102
|
+
const fieldDef = typeDef.fields?.find((f) => f.name.value === fieldName);
|
|
103
|
+
if (fieldDef) {
|
|
104
|
+
// Get the inner (named) type of the field.
|
|
105
|
+
const fieldTypeName = getNamedType(fieldDef.type);
|
|
106
|
+
const fieldTypeDef = getTypeDef(doc, fieldTypeName);
|
|
107
|
+
// If the field is an Object, build its selection set recursively.
|
|
108
|
+
if (fieldTypeDef &&
|
|
109
|
+
fieldTypeDef.kind === Kind.OBJECT_TYPE_DEFINITION) {
|
|
110
|
+
const childSelection = getSelectionSet(fieldTypeName);
|
|
111
|
+
if (childSelection)
|
|
112
|
+
fieldNode.selectionSet = childSelection;
|
|
113
|
+
} // If the field is an Interface, treat it like a union:
|
|
114
|
+
// find all Object types that implement this interface and build inline fragments.
|
|
115
|
+
else if (fieldTypeDef?.kind === Kind.INTERFACE_TYPE_DEFINITION) {
|
|
116
|
+
const implementingTypes = doc.definitions.filter((def) => def.kind === Kind.OBJECT_TYPE_DEFINITION &&
|
|
117
|
+
(def.interfaces?.some((iface) => iface.name.value === fieldTypeName) ?? false));
|
|
118
|
+
const inlineFragments = implementingTypes.map((impl) => ({
|
|
119
|
+
kind: Kind.INLINE_FRAGMENT,
|
|
120
|
+
typeCondition: {
|
|
121
|
+
kind: Kind.NAMED_TYPE,
|
|
122
|
+
name: { kind: Kind.NAME, value: impl.name.value },
|
|
123
|
+
},
|
|
124
|
+
selectionSet: getSelectionSet(impl.name.value) ?? {
|
|
125
|
+
kind: Kind.SELECTION_SET,
|
|
126
|
+
selections: [],
|
|
127
|
+
},
|
|
128
|
+
}));
|
|
129
|
+
fieldNode.selectionSet = {
|
|
130
|
+
kind: Kind.SELECTION_SET,
|
|
131
|
+
selections: inlineFragments,
|
|
132
|
+
};
|
|
133
|
+
} // For Unions, build inline fragments for each member type.
|
|
134
|
+
else if (fieldTypeDef?.kind === Kind.UNION_TYPE_DEFINITION) {
|
|
135
|
+
const inlineFragments = fieldTypeDef.types?.map((member) => ({
|
|
136
|
+
kind: Kind.INLINE_FRAGMENT,
|
|
137
|
+
typeCondition: {
|
|
138
|
+
kind: Kind.NAMED_TYPE,
|
|
139
|
+
name: { kind: Kind.NAME, value: member.name.value },
|
|
140
|
+
},
|
|
141
|
+
selectionSet: getSelectionSet(member.name.value) ?? {
|
|
142
|
+
kind: Kind.SELECTION_SET,
|
|
143
|
+
selections: [],
|
|
144
|
+
},
|
|
145
|
+
})) ?? [];
|
|
146
|
+
fieldNode.selectionSet = {
|
|
147
|
+
kind: Kind.SELECTION_SET,
|
|
148
|
+
selections: inlineFragments,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
// Scalars and enums don't require a nested selection.
|
|
152
|
+
}
|
|
153
|
+
return fieldNode;
|
|
154
|
+
});
|
|
155
|
+
return selectionSet;
|
|
156
|
+
};
|
|
157
|
+
const wrap = (type, patches) => withGetDefaultPatch((type) => transforms[type]?.default, () => toObject(_proxy(doc.definitions, scalars, type, patches, {
|
|
158
|
+
selectionSet: getSelectionSet(type),
|
|
159
|
+
})));
|
|
76
160
|
const objectBuilder = (type) => addObjectTransforms(type, (...patches) => {
|
|
77
161
|
if (transforms[type] && "default" in transforms[type]) {
|
|
78
162
|
patches = [
|
|
@@ -82,7 +166,7 @@ export const init = (schema, queries, mutations, subscriptions, types, inputs, s
|
|
|
82
166
|
}
|
|
83
167
|
return addObjectTransforms(type, wrap(type, patches));
|
|
84
168
|
});
|
|
85
|
-
for (const type
|
|
169
|
+
for (const type in types) {
|
|
86
170
|
build[type] = objectBuilder(type);
|
|
87
171
|
}
|
|
88
172
|
for (const input of inputs) {
|
|
@@ -199,7 +283,7 @@ export const init = (schema, queries, mutations, subscriptions, types, inputs, s
|
|
|
199
283
|
const nonQueryNames = [
|
|
200
284
|
...Object.keys(mutations),
|
|
201
285
|
...Object.keys(subscriptions),
|
|
202
|
-
...types,
|
|
286
|
+
...Object.keys(types),
|
|
203
287
|
...inputs,
|
|
204
288
|
];
|
|
205
289
|
for (const query in queries) {
|
|
@@ -212,7 +296,7 @@ export const init = (schema, queries, mutations, subscriptions, types, inputs, s
|
|
|
212
296
|
const nonMutationNames = [
|
|
213
297
|
...Object.keys(queries),
|
|
214
298
|
...Object.keys(subscriptions),
|
|
215
|
-
...types,
|
|
299
|
+
...Object.keys(types),
|
|
216
300
|
...inputs,
|
|
217
301
|
];
|
|
218
302
|
for (const mutation in mutations) {
|
|
@@ -225,7 +309,7 @@ export const init = (schema, queries, mutations, subscriptions, types, inputs, s
|
|
|
225
309
|
const nonSubscriptionNames = [
|
|
226
310
|
...Object.keys(queries),
|
|
227
311
|
...Object.keys(mutations),
|
|
228
|
-
...types,
|
|
312
|
+
...Object.keys(types),
|
|
229
313
|
...inputs,
|
|
230
314
|
];
|
|
231
315
|
for (const subscription in subscriptions) {
|
package/esm/jest.js
CHANGED
|
@@ -207,8 +207,8 @@ export const MockedProvider = ({ mocks, stack: renderStack, children, link: pass
|
|
|
207
207
|
});
|
|
208
208
|
return ApolloLink.from([
|
|
209
209
|
errorLoggingLink,
|
|
210
|
-
mockLink,
|
|
211
210
|
...(passedLink ? [passedLink] : []),
|
|
211
|
+
mockLink,
|
|
212
212
|
]);
|
|
213
213
|
}, [observableMocks, renderStack]);
|
|
214
214
|
if (_failRefetchWarnings) {
|
package/esm/plugin.cjs
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
module.exports = {
|
|
3
3
|
async plugin(schema, documents, config) {
|
|
4
4
|
const { codegen } = await import("./codegen.js");
|
|
5
|
-
|
|
6
|
-
return (config.banner ?? "") + await formatCode(codegen(schema, documents.map((d) => ({ path: d.location, content: d.rawSDL })), { namingConvention: "change-case-all#pascalCase", ...config }));
|
|
5
|
+
return (config.banner ?? "") + codegen(schema, documents.map((d) => ({ path: d.location, content: d.rawSDL })), { namingConvention: "change-case-all#pascalCase", ...config });
|
|
7
6
|
},
|
|
8
7
|
};
|
package/esm/proxy.js
CHANGED
|
@@ -267,7 +267,7 @@ const getField = (definitions, definition, name) => {
|
|
|
267
267
|
return field;
|
|
268
268
|
}
|
|
269
269
|
};
|
|
270
|
-
const _proxy = (definitions, scalars, path, patches, { prev, resolvedType = resolveType(definitions, path), selectionSet, nonNull, } = {}) => {
|
|
270
|
+
export const _proxy = (definitions, scalars, path, patches, { prev, resolvedType = resolveType(definitions, path), selectionSet, nonNull, } = {}) => {
|
|
271
271
|
const { parent = path, definition } = resolvedType;
|
|
272
272
|
let type = resolvedType.type;
|
|
273
273
|
if (!prev) {
|
package/esm/util.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { spawn } from "node:child_process";
|
|
2
1
|
export const raise = (error) => {
|
|
3
2
|
if (typeof error === "string") {
|
|
4
3
|
const err = new Error(error);
|
|
@@ -7,38 +6,6 @@ export const raise = (error) => {
|
|
|
7
6
|
}
|
|
8
7
|
throw error;
|
|
9
8
|
};
|
|
10
|
-
export const formatCode = async (input) => {
|
|
11
|
-
try {
|
|
12
|
-
return await new Promise((resolve, reject) => {
|
|
13
|
-
const process = spawn("deno", ["fmt", "-"], {
|
|
14
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
15
|
-
});
|
|
16
|
-
let output = "";
|
|
17
|
-
let errorOutput = "";
|
|
18
|
-
process.stdout.on("data", (data) => {
|
|
19
|
-
output += data.toString();
|
|
20
|
-
});
|
|
21
|
-
process.stderr.on("data", (data) => {
|
|
22
|
-
errorOutput += data.toString();
|
|
23
|
-
});
|
|
24
|
-
process.on("close", (code) => {
|
|
25
|
-
if (code !== 0 || errorOutput) {
|
|
26
|
-
reject(new Error(errorOutput || `Process exited with code ${code}`));
|
|
27
|
-
}
|
|
28
|
-
else
|
|
29
|
-
resolve(output);
|
|
30
|
-
});
|
|
31
|
-
process.on("error", (error) => {
|
|
32
|
-
reject(error);
|
|
33
|
-
});
|
|
34
|
-
process.stdin.write(input);
|
|
35
|
-
process.stdin?.end();
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
catch {
|
|
39
|
-
return input;
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
9
|
export const absurd = (v) => {
|
|
43
10
|
const error = new Error(`Unexpected value: ${v}`);
|
|
44
11
|
Error.captureStackTrace(error, absurd);
|
package/package.json
CHANGED
package/script/cli.js
CHANGED
|
@@ -32,7 +32,6 @@ const node_fs_1 = require("node:fs");
|
|
|
32
32
|
const fast_glob_1 = __importDefault(require("fast-glob"));
|
|
33
33
|
const node_util_1 = require("node:util");
|
|
34
34
|
const codegen_js_1 = require("./codegen.js");
|
|
35
|
-
const util_js_1 = require("./util.js");
|
|
36
35
|
const node_process_1 = __importDefault(require("node:process"));
|
|
37
36
|
(async () => {
|
|
38
37
|
const args = (0, node_util_1.parseArgs)({
|
|
@@ -108,14 +107,14 @@ const node_process_1 = __importDefault(require("node:process"));
|
|
|
108
107
|
banner = args.banner;
|
|
109
108
|
}
|
|
110
109
|
try {
|
|
111
|
-
const file = banner +
|
|
110
|
+
const file = banner + (0, codegen_js_1.codegen)(schema, operations, {
|
|
112
111
|
enums: args.enums,
|
|
113
112
|
includeTypenames: !args.notypenames,
|
|
114
113
|
scalars,
|
|
115
114
|
exports,
|
|
116
115
|
typesFile: args.typesFile,
|
|
117
116
|
namingConvention: args.namingConvention,
|
|
118
|
-
})
|
|
117
|
+
});
|
|
119
118
|
if (args.outfile)
|
|
120
119
|
await dntShim.Deno.writeTextFile(args.outfile, file);
|
|
121
120
|
else
|
package/script/codegen.js
CHANGED
|
@@ -553,7 +553,9 @@ ${includeTypenames ? ` __typename: "${name}";\n` : ""}${type.fields?.filter((f)
|
|
|
553
553
|
: usedTypes.filter(([, t]) => t.kind === graphql_1.Kind.OBJECT_TYPE_DEFINITION &&
|
|
554
554
|
t.interfaces?.some((i) => i.name.value === name)).map(([name]) => name).join(" | ")};`).filter(filterOutputTypes), `export type Types = {
|
|
555
555
|
${usedTypes.map(([name]) => ` ${name}: ${rename(name)};`).join("\n")}
|
|
556
|
-
};`, `export const types =
|
|
556
|
+
};`, `export const types = {\n${usedTypes.map(([name, type, usage]) => ` ${name.match(/^[$A-Za-z_][0-9A-Za-z_$]*$/) ? name : `"${name}"`}: ${type.kind === "ObjectTypeDefinition"
|
|
557
|
+
? `[${type.fields?.filter((f) => usage.has(f.name.value)).map((v) => `"${v.name.value}"`).join(", ")}]`
|
|
558
|
+
: "[]"}`).join(",\n")},\n} as const;`);
|
|
557
559
|
}
|
|
558
560
|
const usedReferences = Object.values(references).filter((r) => r[1]).map((r) => r[0]);
|
|
559
561
|
serializedTypes.unshift(...usedReferences.map((r) => {
|
|
@@ -609,7 +611,7 @@ const loadFiles = async (schemaPath, operationDirs) => {
|
|
|
609
611
|
}
|
|
610
612
|
return [
|
|
611
613
|
await (0, promises_1.readFile)(schemaPath, "utf-8"),
|
|
612
|
-
await Promise.all(operationPromises),
|
|
614
|
+
(await Promise.all(operationPromises)).sort((a, b) => a.path.localeCompare(b.path)),
|
|
613
615
|
];
|
|
614
616
|
};
|
|
615
617
|
exports.loadFiles = loadFiles;
|
package/script/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toObject = exports.
|
|
3
|
+
exports.toObject = exports.proxy = exports.operation = exports.clear = exports.codegen = exports.init = void 0;
|
|
4
4
|
var init_js_1 = require("./init.js");
|
|
5
5
|
Object.defineProperty(exports, "init", { enumerable: true, get: function () { return init_js_1.init; } });
|
|
6
6
|
var codegen_js_1 = require("./codegen.js");
|
|
@@ -10,5 +10,4 @@ Object.defineProperty(exports, "clear", { enumerable: true, get: function () { r
|
|
|
10
10
|
Object.defineProperty(exports, "operation", { enumerable: true, get: function () { return proxy_js_1.operation; } });
|
|
11
11
|
Object.defineProperty(exports, "proxy", { enumerable: true, get: function () { return proxy_js_1.proxy; } });
|
|
12
12
|
var util_js_1 = require("./util.js");
|
|
13
|
-
Object.defineProperty(exports, "formatCode", { enumerable: true, get: function () { return util_js_1.formatCode; } });
|
|
14
13
|
Object.defineProperty(exports, "toObject", { enumerable: true, get: function () { return util_js_1.toObject; } });
|
package/script/init.js
CHANGED
|
@@ -69,6 +69,10 @@ const getOperationContent = (path, operationName) => {
|
|
|
69
69
|
}
|
|
70
70
|
return getOperationContent(path, operationName);
|
|
71
71
|
};
|
|
72
|
+
// Helper: Unwraps non-null and list wrappers to get the named type.
|
|
73
|
+
const getNamedType = (type) => type.kind === graphql_1.Kind.NAMED_TYPE ? type.name.value : getNamedType(type.type);
|
|
74
|
+
// Helper: Find a type definition in the document by name.
|
|
75
|
+
const getTypeDef = (doc, typeName) => doc.definitions.find((def) => "name" in def && def.name?.value === typeName);
|
|
72
76
|
/**
|
|
73
77
|
* Initialize the data builder.
|
|
74
78
|
* @param schema The plain text of your schema.
|
|
@@ -98,7 +102,87 @@ const init = (schema, queries, mutations, subscriptions, types, inputs, scalars,
|
|
|
98
102
|
}])));
|
|
99
103
|
return obj;
|
|
100
104
|
};
|
|
101
|
-
const
|
|
105
|
+
const getSelectionSetMemory = new Map();
|
|
106
|
+
const getSelectionSet = (type) => {
|
|
107
|
+
if (getSelectionSetMemory.has(type)) {
|
|
108
|
+
return getSelectionSetMemory.get(type);
|
|
109
|
+
}
|
|
110
|
+
const fields = types[type];
|
|
111
|
+
if (!fields)
|
|
112
|
+
return;
|
|
113
|
+
const typeDef = getTypeDef(doc, type);
|
|
114
|
+
if (!typeDef || !("fields" in typeDef))
|
|
115
|
+
return;
|
|
116
|
+
const selectionSet = {
|
|
117
|
+
kind: graphql_1.Kind.SELECTION_SET,
|
|
118
|
+
selections: [],
|
|
119
|
+
};
|
|
120
|
+
getSelectionSetMemory.set(type, selectionSet);
|
|
121
|
+
// Build each field node.
|
|
122
|
+
selectionSet.selections = fields.map((fieldName) => {
|
|
123
|
+
const fieldNode = {
|
|
124
|
+
kind: graphql_1.Kind.FIELD,
|
|
125
|
+
name: { kind: graphql_1.Kind.NAME, value: fieldName },
|
|
126
|
+
};
|
|
127
|
+
// Look for the field definition in the type definition.
|
|
128
|
+
const fieldDef = typeDef.fields?.find((f) => f.name.value === fieldName);
|
|
129
|
+
if (fieldDef) {
|
|
130
|
+
// Get the inner (named) type of the field.
|
|
131
|
+
const fieldTypeName = getNamedType(fieldDef.type);
|
|
132
|
+
const fieldTypeDef = getTypeDef(doc, fieldTypeName);
|
|
133
|
+
// If the field is an Object, build its selection set recursively.
|
|
134
|
+
if (fieldTypeDef &&
|
|
135
|
+
fieldTypeDef.kind === graphql_1.Kind.OBJECT_TYPE_DEFINITION) {
|
|
136
|
+
const childSelection = getSelectionSet(fieldTypeName);
|
|
137
|
+
if (childSelection)
|
|
138
|
+
fieldNode.selectionSet = childSelection;
|
|
139
|
+
} // If the field is an Interface, treat it like a union:
|
|
140
|
+
// find all Object types that implement this interface and build inline fragments.
|
|
141
|
+
else if (fieldTypeDef?.kind === graphql_1.Kind.INTERFACE_TYPE_DEFINITION) {
|
|
142
|
+
const implementingTypes = doc.definitions.filter((def) => def.kind === graphql_1.Kind.OBJECT_TYPE_DEFINITION &&
|
|
143
|
+
(def.interfaces?.some((iface) => iface.name.value === fieldTypeName) ?? false));
|
|
144
|
+
const inlineFragments = implementingTypes.map((impl) => ({
|
|
145
|
+
kind: graphql_1.Kind.INLINE_FRAGMENT,
|
|
146
|
+
typeCondition: {
|
|
147
|
+
kind: graphql_1.Kind.NAMED_TYPE,
|
|
148
|
+
name: { kind: graphql_1.Kind.NAME, value: impl.name.value },
|
|
149
|
+
},
|
|
150
|
+
selectionSet: getSelectionSet(impl.name.value) ?? {
|
|
151
|
+
kind: graphql_1.Kind.SELECTION_SET,
|
|
152
|
+
selections: [],
|
|
153
|
+
},
|
|
154
|
+
}));
|
|
155
|
+
fieldNode.selectionSet = {
|
|
156
|
+
kind: graphql_1.Kind.SELECTION_SET,
|
|
157
|
+
selections: inlineFragments,
|
|
158
|
+
};
|
|
159
|
+
} // For Unions, build inline fragments for each member type.
|
|
160
|
+
else if (fieldTypeDef?.kind === graphql_1.Kind.UNION_TYPE_DEFINITION) {
|
|
161
|
+
const inlineFragments = fieldTypeDef.types?.map((member) => ({
|
|
162
|
+
kind: graphql_1.Kind.INLINE_FRAGMENT,
|
|
163
|
+
typeCondition: {
|
|
164
|
+
kind: graphql_1.Kind.NAMED_TYPE,
|
|
165
|
+
name: { kind: graphql_1.Kind.NAME, value: member.name.value },
|
|
166
|
+
},
|
|
167
|
+
selectionSet: getSelectionSet(member.name.value) ?? {
|
|
168
|
+
kind: graphql_1.Kind.SELECTION_SET,
|
|
169
|
+
selections: [],
|
|
170
|
+
},
|
|
171
|
+
})) ?? [];
|
|
172
|
+
fieldNode.selectionSet = {
|
|
173
|
+
kind: graphql_1.Kind.SELECTION_SET,
|
|
174
|
+
selections: inlineFragments,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
// Scalars and enums don't require a nested selection.
|
|
178
|
+
}
|
|
179
|
+
return fieldNode;
|
|
180
|
+
});
|
|
181
|
+
return selectionSet;
|
|
182
|
+
};
|
|
183
|
+
const wrap = (type, patches) => (0, proxy_js_1.withGetDefaultPatch)((type) => transforms[type]?.default, () => (0, util_js_1.toObject)((0, proxy_js_1._proxy)(doc.definitions, scalars, type, patches, {
|
|
184
|
+
selectionSet: getSelectionSet(type),
|
|
185
|
+
})));
|
|
102
186
|
const objectBuilder = (type) => addObjectTransforms(type, (...patches) => {
|
|
103
187
|
if (transforms[type] && "default" in transforms[type]) {
|
|
104
188
|
patches = [
|
|
@@ -108,7 +192,7 @@ const init = (schema, queries, mutations, subscriptions, types, inputs, scalars,
|
|
|
108
192
|
}
|
|
109
193
|
return addObjectTransforms(type, wrap(type, patches));
|
|
110
194
|
});
|
|
111
|
-
for (const type
|
|
195
|
+
for (const type in types) {
|
|
112
196
|
build[type] = objectBuilder(type);
|
|
113
197
|
}
|
|
114
198
|
for (const input of inputs) {
|
|
@@ -225,7 +309,7 @@ const init = (schema, queries, mutations, subscriptions, types, inputs, scalars,
|
|
|
225
309
|
const nonQueryNames = [
|
|
226
310
|
...Object.keys(mutations),
|
|
227
311
|
...Object.keys(subscriptions),
|
|
228
|
-
...types,
|
|
312
|
+
...Object.keys(types),
|
|
229
313
|
...inputs,
|
|
230
314
|
];
|
|
231
315
|
for (const query in queries) {
|
|
@@ -238,7 +322,7 @@ const init = (schema, queries, mutations, subscriptions, types, inputs, scalars,
|
|
|
238
322
|
const nonMutationNames = [
|
|
239
323
|
...Object.keys(queries),
|
|
240
324
|
...Object.keys(subscriptions),
|
|
241
|
-
...types,
|
|
325
|
+
...Object.keys(types),
|
|
242
326
|
...inputs,
|
|
243
327
|
];
|
|
244
328
|
for (const mutation in mutations) {
|
|
@@ -251,7 +335,7 @@ const init = (schema, queries, mutations, subscriptions, types, inputs, scalars,
|
|
|
251
335
|
const nonSubscriptionNames = [
|
|
252
336
|
...Object.keys(queries),
|
|
253
337
|
...Object.keys(mutations),
|
|
254
|
-
...types,
|
|
338
|
+
...Object.keys(types),
|
|
255
339
|
...inputs,
|
|
256
340
|
];
|
|
257
341
|
for (const subscription in subscriptions) {
|
package/script/jest.js
CHANGED
|
@@ -237,8 +237,8 @@ const MockedProvider = ({ mocks, stack: renderStack, children, link: passedLink,
|
|
|
237
237
|
});
|
|
238
238
|
return client_1.ApolloLink.from([
|
|
239
239
|
errorLoggingLink,
|
|
240
|
-
mockLink,
|
|
241
240
|
...(passedLink ? [passedLink] : []),
|
|
241
|
+
mockLink,
|
|
242
242
|
]);
|
|
243
243
|
}, [observableMocks, renderStack]);
|
|
244
244
|
if (_failRefetchWarnings) {
|
package/script/plugin.cjs
CHANGED
|
@@ -25,7 +25,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
module.exports = {
|
|
26
26
|
async plugin(schema, documents, config) {
|
|
27
27
|
const { codegen } = await Promise.resolve().then(() => __importStar(require("./codegen.js")));
|
|
28
|
-
|
|
29
|
-
return (config.banner ?? "") + await formatCode(codegen(schema, documents.map((d) => ({ path: d.location, content: d.rawSDL })), { namingConvention: "change-case-all#pascalCase", ...config }));
|
|
28
|
+
return (config.banner ?? "") + codegen(schema, documents.map((d) => ({ path: d.location, content: d.rawSDL })), { namingConvention: "change-case-all#pascalCase", ...config });
|
|
30
29
|
},
|
|
31
30
|
};
|
package/script/proxy.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.operation = exports.proxy = exports.withGetDefaultPatch = exports.clear = void 0;
|
|
3
|
+
exports.operation = exports.proxy = exports._proxy = exports.withGetDefaultPatch = exports.clear = void 0;
|
|
4
4
|
const graphql_1 = require("graphql");
|
|
5
5
|
const util_js_1 = require("./util.js");
|
|
6
6
|
/**
|
|
@@ -171,7 +171,7 @@ const resolveValue = (definitions, scalars, type, ctx) => {
|
|
|
171
171
|
(fieldTypeDefinitions[0].kind === graphql_1.Kind.OBJECT_TYPE_DEFINITION ||
|
|
172
172
|
fieldTypeDefinitions[0].kind === graphql_1.Kind.INTERFACE_TYPE_DEFINITION ||
|
|
173
173
|
fieldTypeDefinitions[0].kind === graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION)) {
|
|
174
|
-
return _proxy(definitions, scalars, ctx.path ? `${ctx.path}.${ctx.prop}` : fieldTypeDefinitions[0].name.value, [], { selectionSet: ctx.selectionSet, nonNull: true });
|
|
174
|
+
return (0, exports._proxy)(definitions, scalars, ctx.path ? `${ctx.path}.${ctx.prop}` : fieldTypeDefinitions[0].name.value, [], { selectionSet: ctx.selectionSet, nonNull: true });
|
|
175
175
|
}
|
|
176
176
|
throw new Error(`Unhandled default kind ${fieldTypeDefinitions.map((d) => d.kind)}`);
|
|
177
177
|
};
|
|
@@ -288,7 +288,7 @@ const _proxy = (definitions, scalars, path, patches, { prev, resolvedType = reso
|
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
290
|
if (patches.length) {
|
|
291
|
-
prev = _proxy(definitions, scalars, path, patches.slice(0, -1), {
|
|
291
|
+
prev = (0, exports._proxy)(definitions, scalars, path, patches.slice(0, -1), {
|
|
292
292
|
selectionSet,
|
|
293
293
|
});
|
|
294
294
|
}
|
|
@@ -298,7 +298,7 @@ const _proxy = (definitions, scalars, path, patches, { prev, resolvedType = reso
|
|
|
298
298
|
? prev ? rawPatch(prev) : undefined
|
|
299
299
|
: rawPatch;
|
|
300
300
|
if (patch === exports.clear) {
|
|
301
|
-
return _proxy(definitions, scalars, path, [], { selectionSet });
|
|
301
|
+
return (0, exports._proxy)(definitions, scalars, path, [], { selectionSet });
|
|
302
302
|
}
|
|
303
303
|
if (type.kind !== graphql_1.Kind.NON_NULL_TYPE) {
|
|
304
304
|
if (!patches.length && !nonNull) {
|
|
@@ -319,7 +319,7 @@ const _proxy = (definitions, scalars, path, patches, { prev, resolvedType = reso
|
|
|
319
319
|
return (prev ?? []);
|
|
320
320
|
const value = (patches.at(-1) ?? []);
|
|
321
321
|
if (value === exports.clear) {
|
|
322
|
-
return _proxy(definitions, scalars, path, [], { selectionSet });
|
|
322
|
+
return (0, exports._proxy)(definitions, scalars, path, [], { selectionSet });
|
|
323
323
|
}
|
|
324
324
|
const previousArray = (prev ?? []);
|
|
325
325
|
const lastIndex = Math.max(previousArray.length - 1, 0);
|
|
@@ -344,7 +344,7 @@ const _proxy = (definitions, scalars, path, patches, { prev, resolvedType = reso
|
|
|
344
344
|
type.type.type.kind === graphql_1.Kind.NAMED_TYPE
|
|
345
345
|
? type.type.type.name.value
|
|
346
346
|
: undefined;
|
|
347
|
-
arr[i] = _proxy(definitions, scalars, `${path}.${i}`, [
|
|
347
|
+
arr[i] = (0, exports._proxy)(definitions, scalars, `${path}.${i}`, [
|
|
348
348
|
// TODO: should be handled in _proxy
|
|
349
349
|
nestType && !previousArray[i] ? getDefaultPatch(nestType) : undefined,
|
|
350
350
|
value[i],
|
|
@@ -385,14 +385,14 @@ const _proxy = (definitions, scalars, path, patches, { prev, resolvedType = reso
|
|
|
385
385
|
? rawValue(prev)
|
|
386
386
|
: rawValue;
|
|
387
387
|
if (value === exports.clear) {
|
|
388
|
-
return target[prop] = _proxy(definitions, scalars, `${path}.${unaliased}`, [], { selectionSet });
|
|
388
|
+
return target[prop] = (0, exports._proxy)(definitions, scalars, `${path}.${unaliased}`, [], { selectionSet });
|
|
389
389
|
}
|
|
390
390
|
if (value && typeof value === "object") {
|
|
391
391
|
const nonNullFieldType = field.type.kind === graphql_1.Kind.NON_NULL_TYPE
|
|
392
392
|
? field.type.type
|
|
393
393
|
: field.type;
|
|
394
394
|
if (nonNullFieldType.kind === graphql_1.Kind.LIST_TYPE) {
|
|
395
|
-
return target[prop] = _proxy(definitions, scalars, `${path}.${unaliased}`, [value], {
|
|
395
|
+
return target[prop] = (0, exports._proxy)(definitions, scalars, `${path}.${unaliased}`, [value], {
|
|
396
396
|
prev: prev?.[prop],
|
|
397
397
|
selectionSet: selectionSet
|
|
398
398
|
? getSelectionSetSelection(definitions, selectionSet, unaliased)
|
|
@@ -400,7 +400,7 @@ const _proxy = (definitions, scalars, path, patches, { prev, resolvedType = reso
|
|
|
400
400
|
});
|
|
401
401
|
}
|
|
402
402
|
const childPatches = patches.map((p) => p[prop]).filter((v) => !!v && typeof v === "object");
|
|
403
|
-
return target[prop] = _proxy(definitions, scalars, `${path}.${unaliased}`, childPatches, {
|
|
403
|
+
return target[prop] = (0, exports._proxy)(definitions, scalars, `${path}.${unaliased}`, childPatches, {
|
|
404
404
|
prev: prev?.[prop],
|
|
405
405
|
selectionSet: selectionSet
|
|
406
406
|
? getSelectionSetSelection(definitions, selectionSet, unaliased)
|
|
@@ -461,7 +461,7 @@ const _proxy = (definitions, scalars, path, patches, { prev, resolvedType = reso
|
|
|
461
461
|
case graphql_1.Kind.INTERFACE_TYPE_DEFINITION: {
|
|
462
462
|
// When creating prev, we need hint the desired type...
|
|
463
463
|
const concreteType = resolveConcreteType(definitions, definition, patch, prev, selectionSet);
|
|
464
|
-
return _proxy(definitions, scalars, concreteType.name.value, patches, {
|
|
464
|
+
return (0, exports._proxy)(definitions, scalars, concreteType.name.value, patches, {
|
|
465
465
|
prev,
|
|
466
466
|
selectionSet,
|
|
467
467
|
});
|
|
@@ -491,7 +491,7 @@ const _proxy = (definitions, scalars, path, patches, { prev, resolvedType = reso
|
|
|
491
491
|
}
|
|
492
492
|
if (!mock.variables)
|
|
493
493
|
mock.variables = {};
|
|
494
|
-
mock.variables[name] = _proxy(definitions, scalars, `${path}.$${name}`, [value], {
|
|
494
|
+
mock.variables[name] = (0, exports._proxy)(definitions, scalars, `${path}.$${name}`, [value], {
|
|
495
495
|
prev: mockPrev?.variables?.[name],
|
|
496
496
|
resolvedType: {
|
|
497
497
|
parent: `${path}Variables`,
|
|
@@ -545,10 +545,10 @@ const _proxy = (definitions, scalars, path, patches, { prev, resolvedType = reso
|
|
|
545
545
|
const operationKey = definition.operation[0].toUpperCase() +
|
|
546
546
|
definition.operation.slice(1);
|
|
547
547
|
if (value === exports.clear) {
|
|
548
|
-
mock.data[prop] = _proxy(definitions, scalars, `${operationKey}.${selection.name.value}`, [], { selectionSet: selection.selectionSet });
|
|
548
|
+
mock.data[prop] = (0, exports._proxy)(definitions, scalars, `${operationKey}.${selection.name.value}`, [], { selectionSet: selection.selectionSet });
|
|
549
549
|
continue;
|
|
550
550
|
}
|
|
551
|
-
mock.data[prop] = _proxy(definitions, scalars, `${operationKey}.${selection.name.value}`, value !== undefined ? [value] : [], {
|
|
551
|
+
mock.data[prop] = (0, exports._proxy)(definitions, scalars, `${operationKey}.${selection.name.value}`, value !== undefined ? [value] : [], {
|
|
552
552
|
prev: mockPrev?.data?.[prop],
|
|
553
553
|
selectionSet: selection.selectionSet,
|
|
554
554
|
});
|
|
@@ -605,7 +605,8 @@ const _proxy = (definitions, scalars, path, patches, { prev, resolvedType = reso
|
|
|
605
605
|
throw new Error(`Unhandled definition kind '${definition.kind}'`);
|
|
606
606
|
}
|
|
607
607
|
};
|
|
608
|
-
|
|
608
|
+
exports._proxy = _proxy;
|
|
609
|
+
const proxy = (definitions, scalars, type, ...patches) => (0, exports._proxy)(definitions, scalars, type, patches);
|
|
609
610
|
exports.proxy = proxy;
|
|
610
611
|
const constToValue = (value) => {
|
|
611
612
|
switch (value.kind) {
|
|
@@ -638,7 +639,7 @@ const operation = (definitions, scalars, query, ...patches) => {
|
|
|
638
639
|
const operation = operations[0];
|
|
639
640
|
if (!operation.name?.value)
|
|
640
641
|
throw new Error("Expected operation to be named");
|
|
641
|
-
const { variables, data, error, errors, ...extra } = _proxy([...definitions, ...document.definitions], scalars, operation.name.value, patches);
|
|
642
|
+
const { variables, data, error, errors, ...extra } = (0, exports._proxy)([...definitions, ...document.definitions], scalars, operation.name.value, patches);
|
|
642
643
|
const mock = {
|
|
643
644
|
request: { query: document },
|
|
644
645
|
result: {},
|
package/script/util.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.toObject = exports.absurd = exports.
|
|
4
|
-
const node_child_process_1 = require("node:child_process");
|
|
3
|
+
exports.toObject = exports.absurd = exports.raise = void 0;
|
|
5
4
|
const raise = (error) => {
|
|
6
5
|
if (typeof error === "string") {
|
|
7
6
|
const err = new Error(error);
|
|
@@ -11,39 +10,6 @@ const raise = (error) => {
|
|
|
11
10
|
throw error;
|
|
12
11
|
};
|
|
13
12
|
exports.raise = raise;
|
|
14
|
-
const formatCode = async (input) => {
|
|
15
|
-
try {
|
|
16
|
-
return await new Promise((resolve, reject) => {
|
|
17
|
-
const process = (0, node_child_process_1.spawn)("deno", ["fmt", "-"], {
|
|
18
|
-
stdio: ["pipe", "pipe", "pipe"],
|
|
19
|
-
});
|
|
20
|
-
let output = "";
|
|
21
|
-
let errorOutput = "";
|
|
22
|
-
process.stdout.on("data", (data) => {
|
|
23
|
-
output += data.toString();
|
|
24
|
-
});
|
|
25
|
-
process.stderr.on("data", (data) => {
|
|
26
|
-
errorOutput += data.toString();
|
|
27
|
-
});
|
|
28
|
-
process.on("close", (code) => {
|
|
29
|
-
if (code !== 0 || errorOutput) {
|
|
30
|
-
reject(new Error(errorOutput || `Process exited with code ${code}`));
|
|
31
|
-
}
|
|
32
|
-
else
|
|
33
|
-
resolve(output);
|
|
34
|
-
});
|
|
35
|
-
process.on("error", (error) => {
|
|
36
|
-
reject(error);
|
|
37
|
-
});
|
|
38
|
-
process.stdin.write(input);
|
|
39
|
-
process.stdin?.end();
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
catch {
|
|
43
|
-
return input;
|
|
44
|
-
}
|
|
45
|
-
};
|
|
46
|
-
exports.formatCode = formatCode;
|
|
47
13
|
const absurd = (v) => {
|
|
48
14
|
const error = new Error(`Unexpected value: ${v}`);
|
|
49
15
|
Error.captureStackTrace(error, exports.absurd);
|
package/types/index.d.ts
CHANGED
|
@@ -2,4 +2,4 @@ export { init } from "./init.js";
|
|
|
2
2
|
export type { DeepPartial, OperationMock, Patch } from "./types.js";
|
|
3
3
|
export { codegen } from "./codegen.js";
|
|
4
4
|
export { clear, operation, proxy } from "./proxy.js";
|
|
5
|
-
export {
|
|
5
|
+
export { toObject } from "./util.js";
|
package/types/init.d.ts
CHANGED
|
@@ -19,7 +19,7 @@ export declare const init: <Query extends Record<string, {
|
|
|
19
19
|
}>, Subscription extends Record<string, {
|
|
20
20
|
data: Record<string, unknown>;
|
|
21
21
|
variables?: Record<string, unknown>;
|
|
22
|
-
}>, Types extends Record<string, Record<string, unknown>>, Inputs extends Record<string, Record<string, unknown>>, Extra = object>(schema: string, queries: { [operation in keyof Query]: string; }, mutations: { [operation in keyof Mutation]: string; }, subscriptions: { [operation in keyof Subscription]: string; }, types: readonly
|
|
22
|
+
}>, Types extends Record<string, Record<string, unknown>>, Inputs extends Record<string, Record<string, unknown>>, Extra = object>(schema: string, queries: { [operation in keyof Query]: string; }, mutations: { [operation in keyof Mutation]: string; }, subscriptions: { [operation in keyof Subscription]: string; }, types: { readonly [type in keyof Types]: readonly string[]; }, inputs: readonly (keyof Inputs & string)[], scalars: {
|
|
23
23
|
[name: string]: ((typeName: string, fieldName: string) => unknown) | string | number | boolean | null;
|
|
24
24
|
}, options?: {
|
|
25
25
|
finalizeOperation?: <T extends OperationMock & Partial<Extra>>(operation: T) => T;
|
package/types/proxy.d.ts
CHANGED
|
@@ -1,13 +1,29 @@
|
|
|
1
|
-
import type { DefinitionNode, DocumentNode, GraphQLError } from "graphql";
|
|
1
|
+
import type { DefinitionNode, DocumentNode, GraphQLError, NameNode, SelectionSetNode, TypeNode } from "graphql";
|
|
2
2
|
import type { OperationMock, Patch, SimpleOperationMock } from "./types.js";
|
|
3
3
|
/**
|
|
4
4
|
* Updates the value to the base value, bypassing default transformations.
|
|
5
5
|
* Useful to clear optional inputs, resulting in `undefined` rather than `null`.
|
|
6
6
|
*/
|
|
7
7
|
export declare const clear: undefined;
|
|
8
|
+
type NamedDefinitionNode = DefinitionNode & {
|
|
9
|
+
name: NameNode;
|
|
10
|
+
};
|
|
8
11
|
export declare const withGetDefaultPatch: <T>(newGetDefaultPatch: <U>(__typename: string) => Patch<U> | ((prev: U) => Patch<U> | undefined) | undefined, fn: () => T) => T;
|
|
12
|
+
declare const resolveType: (definitions: readonly DefinitionNode[], path: string) => {
|
|
13
|
+
parent: string | undefined;
|
|
14
|
+
definition: NamedDefinitionNode | undefined;
|
|
15
|
+
type: TypeNode;
|
|
16
|
+
};
|
|
17
|
+
export declare const _proxy: <T>(definitions: readonly DefinitionNode[], scalars: Record<string, unknown | ((typename: string) => unknown)>, path: string, patches: readonly (Patch<T> | ((prev: T) => Patch<T> | undefined))[], { prev, resolvedType, selectionSet, nonNull, }?: {
|
|
18
|
+
prev?: T;
|
|
19
|
+
/** Used to handle lists */
|
|
20
|
+
resolvedType?: ReturnType<typeof resolveType>;
|
|
21
|
+
selectionSet?: SelectionSetNode;
|
|
22
|
+
nonNull?: boolean;
|
|
23
|
+
}) => T;
|
|
9
24
|
export declare const proxy: <T>(definitions: readonly DefinitionNode[], scalars: Record<string, unknown | ((typename: string) => unknown)>, type: string, ...patches: (Patch<T> | ((prev: T) => Patch<T>))[]) => T;
|
|
10
25
|
export declare const operation: <O extends SimpleOperationMock, Extra = object>(definitions: readonly DefinitionNode[], scalars: Record<string, unknown | ((typename: string) => unknown)>, query: string | DocumentNode, ...patches: (Patch<Omit<O, "error" | "errors">> & {
|
|
11
26
|
error?: Error;
|
|
12
27
|
errors?: GraphQLError[];
|
|
13
28
|
} & Partial<Extra>)[]) => OperationMock<O["data"], O["variables"]> & Partial<Extra>;
|
|
29
|
+
export {};
|
package/types/util.d.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
export declare const raise: (error: Error | string) => never;
|
|
2
|
-
export declare const formatCode: (input: string) => Promise<string>;
|
|
3
2
|
export declare const absurd: (v: never) => never;
|
|
4
3
|
type StripFunctions<T> = {
|
|
5
4
|
[K in keyof T]: T[K] extends (...args: any[]) => any ? never : T[K] extends object ? StripFunctions<T[K]> : T[K];
|