graphile-utils 5.0.0-beta.9 → 5.0.0-rc.2
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/CHANGELOG.md +1096 -1
- package/README.md +87 -72
- package/dist/exportable.d.ts +4 -1
- package/dist/exportable.d.ts.map +1 -1
- package/dist/exportable.js +15 -4
- package/dist/exportable.js.map +1 -1
- package/dist/gql.js +1 -2
- package/dist/gql.js.map +1 -1
- package/dist/index.d.ts +42 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/makeAddInflectorsPlugin.js +2 -3
- package/dist/makeAddInflectorsPlugin.js.map +1 -1
- package/dist/makeAddPgTableConditionPlugin.d.ts +32 -6
- package/dist/makeAddPgTableConditionPlugin.d.ts.map +1 -1
- package/dist/makeAddPgTableConditionPlugin.js +28 -11
- package/dist/makeAddPgTableConditionPlugin.js.map +1 -1
- package/dist/makeAddPgTableOrderByPlugin.d.ts +15 -10
- package/dist/makeAddPgTableOrderByPlugin.d.ts.map +1 -1
- package/dist/makeAddPgTableOrderByPlugin.js +43 -35
- package/dist/makeAddPgTableOrderByPlugin.js.map +1 -1
- package/dist/makeChangeNullabilityPlugin.d.ts +3 -1
- package/dist/makeChangeNullabilityPlugin.d.ts.map +1 -1
- package/dist/makeChangeNullabilityPlugin.js +98 -18
- package/dist/makeChangeNullabilityPlugin.js.map +1 -1
- package/dist/makeExtendSchemaPlugin.d.ts +55 -26
- package/dist/makeExtendSchemaPlugin.d.ts.map +1 -1
- package/dist/makeExtendSchemaPlugin.js +417 -117
- package/dist/makeExtendSchemaPlugin.js.map +1 -1
- package/dist/makePgSmartTagsPlugin.d.ts +16 -3
- package/dist/makePgSmartTagsPlugin.d.ts.map +1 -1
- package/dist/makePgSmartTagsPlugin.js +24 -18
- package/dist/makePgSmartTagsPlugin.js.map +1 -1
- package/dist/makeProcessSchemaPlugin.d.ts +3 -1
- package/dist/makeProcessSchemaPlugin.d.ts.map +1 -1
- package/dist/makeProcessSchemaPlugin.js +4 -2
- package/dist/makeProcessSchemaPlugin.js.map +1 -1
- package/dist/makeWrapPlansPlugin.d.ts +6 -3
- package/dist/makeWrapPlansPlugin.d.ts.map +1 -1
- package/dist/makeWrapPlansPlugin.js +40 -18
- package/dist/makeWrapPlansPlugin.js.map +1 -1
- package/dist/parseIdentifierParts.js +1 -2
- package/dist/parseIdentifierParts.js.map +1 -1
- package/package.json +29 -23
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.makeExtendSchemaPlugin = void 0;
|
|
4
|
+
exports.extendSchema = extendSchema;
|
|
4
5
|
const exportable_js_1 = require("./exportable.js");
|
|
5
|
-
function
|
|
6
|
+
function extendSchema(generator, uniquePluginName = `ExtendSchemaPlugin_${String(Math.random()).slice(2)}`) {
|
|
6
7
|
let graphql;
|
|
7
8
|
if (typeof generator === "function" && generator.length >= 2) {
|
|
8
9
|
console.trace("[DEPRECATED] Your makeExtendSchemaPlugin generator callback accepts two arguments: `(build, options)`; instead you should just use the `build` argument since `options` is just `build.options`.");
|
|
@@ -10,6 +11,15 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
10
11
|
return {
|
|
11
12
|
name: uniquePluginName,
|
|
12
13
|
version: "0.0.0",
|
|
14
|
+
after: [
|
|
15
|
+
"QueryPlugin",
|
|
16
|
+
"MutationPlugin",
|
|
17
|
+
"SubscriptionPlugin",
|
|
18
|
+
"NodePlugin",
|
|
19
|
+
"RegisterQueryNodePlugin",
|
|
20
|
+
"PgRegistryPlugin",
|
|
21
|
+
"PgTableNodePlugin",
|
|
22
|
+
],
|
|
13
23
|
schema: {
|
|
14
24
|
hooks: {
|
|
15
25
|
build(build) {
|
|
@@ -21,32 +31,42 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
21
31
|
return build;
|
|
22
32
|
},
|
|
23
33
|
init(_, build, _context) {
|
|
24
|
-
const { GraphQLDirective, GraphQLEnumType, GraphQLError, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLObjectType, GraphQLScalarType, GraphQLUnionType, Kind, } = graphql;
|
|
25
|
-
const { typeDefs, resolvers = Object.create(null), plans
|
|
34
|
+
const { GraphQLDirective, GraphQLEnumType, GraphQLError, GraphQLInputObjectType, GraphQLInterfaceType, GraphQLObjectType, GraphQLScalarType, GraphQLUnionType, Kind, parse, } = graphql;
|
|
35
|
+
const { typeDefs, resolvers = Object.create(null), plans: rawPlans, enums, scalars, inputObjects, interfaces, unions, objects, } = typeof generator === "function"
|
|
26
36
|
? generator.length === 1
|
|
27
37
|
? generator(build)
|
|
28
38
|
: /* TODO: DELETE THIS! */
|
|
29
39
|
generator(build, build.options)
|
|
30
40
|
: generator;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
if (typeDefs == null) {
|
|
42
|
+
throw new Error("The first argument to makeExtendSchemaPlugin must be an object containing a `typeDefs` field.");
|
|
43
|
+
}
|
|
44
|
+
const document = typeof typeDefs === "string"
|
|
45
|
+
? parse(typeDefs)
|
|
46
|
+
: Array.isArray(typeDefs)
|
|
47
|
+
? {
|
|
48
|
+
kind: graphql.Kind.DOCUMENT,
|
|
49
|
+
definitions: typeDefs.flatMap((t) => {
|
|
50
|
+
if (!t || t.kind !== "Document") {
|
|
51
|
+
throw new Error('The first argument to makeExtendSchemaPlugin must be an object containing a `typeDefs` field; the value for this field must be generated by the `gql` helper (`import { gql, makeExtendSchemaPlugin } from "postgraphile/utils"`), or be an array of the same.');
|
|
52
|
+
}
|
|
53
|
+
return t.definitions;
|
|
54
|
+
}),
|
|
55
|
+
}
|
|
56
|
+
: typeDefs;
|
|
57
|
+
if (!document || document.kind !== "Document") {
|
|
58
|
+
throw new Error('The first argument to makeExtendSchemaPlugin must be an object containing a `typeDefs` field; the value for this field must be generated by the `gql` helper (`import { gql, makeExtendSchemaPlugin } from "postgraphile/utils"`), or be an array of the same.');
|
|
59
|
+
}
|
|
39
60
|
const typeExtensions = {
|
|
40
61
|
GraphQLSchema: {
|
|
41
62
|
directives: [],
|
|
42
|
-
types: [],
|
|
43
63
|
},
|
|
44
64
|
GraphQLInputObjectType: {},
|
|
45
65
|
GraphQLObjectType: {},
|
|
46
66
|
GraphQLInterfaceType: {},
|
|
47
67
|
};
|
|
48
68
|
const newTypes = [];
|
|
49
|
-
|
|
69
|
+
document.definitions.forEach((definition) => {
|
|
50
70
|
if (definition.kind === "EnumTypeDefinition") {
|
|
51
71
|
newTypes.push({
|
|
52
72
|
type: GraphQLEnumType,
|
|
@@ -117,6 +137,196 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
117
137
|
throw new Error(`Unexpected '${definition.kind}' definition; we were expecting 'GraphQLEnumType', 'ObjectTypeExtension', 'InputObjectTypeExtension', 'ObjectTypeDefinition' or 'InputObjectTypeDefinition', i.e. something like 'extend type Foo { ... }'`);
|
|
118
138
|
}
|
|
119
139
|
});
|
|
140
|
+
let plans;
|
|
141
|
+
if (rawPlans) {
|
|
142
|
+
if (objects ||
|
|
143
|
+
unions ||
|
|
144
|
+
interfaces ||
|
|
145
|
+
inputObjects ||
|
|
146
|
+
scalars ||
|
|
147
|
+
enums) {
|
|
148
|
+
throw new Error(`plans is deprecated and may not be specified alongside newer approaches`);
|
|
149
|
+
}
|
|
150
|
+
plans = rawPlans;
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
// Hackily convert the new format into the old format. We'll do away with
|
|
154
|
+
// this in future, but for now it's the easiest way to ensure compatibility
|
|
155
|
+
plans = {};
|
|
156
|
+
const definitionNodes = document.definitions.filter((d) => d.kind === Kind.OBJECT_TYPE_DEFINITION ||
|
|
157
|
+
d.kind === Kind.INTERFACE_TYPE_DEFINITION ||
|
|
158
|
+
d.kind === Kind.UNION_TYPE_DEFINITION ||
|
|
159
|
+
d.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION ||
|
|
160
|
+
d.kind === Kind.ENUM_TYPE_DEFINITION ||
|
|
161
|
+
d.kind === Kind.SCALAR_TYPE_DEFINITION ||
|
|
162
|
+
d.kind === Kind.OBJECT_TYPE_EXTENSION ||
|
|
163
|
+
d.kind === Kind.INTERFACE_TYPE_EXTENSION ||
|
|
164
|
+
d.kind === Kind.UNION_TYPE_EXTENSION ||
|
|
165
|
+
d.kind === Kind.INPUT_OBJECT_TYPE_EXTENSION ||
|
|
166
|
+
d.kind === Kind.ENUM_TYPE_EXTENSION ||
|
|
167
|
+
d.kind === Kind.SCALAR_TYPE_EXTENSION);
|
|
168
|
+
const assertLocation = (typeName, expectedLocation) => {
|
|
169
|
+
const nodes = definitionNodes.filter((n) => n.name.value === typeName);
|
|
170
|
+
const node = nodes[0];
|
|
171
|
+
if (!node) {
|
|
172
|
+
throw new Error(`You detailed '${expectedLocation}.${typeName}', but the '${typeName}' type is not defined or extended in your 'typeDefs'.`);
|
|
173
|
+
}
|
|
174
|
+
const [description, attr, names = []] = (() => {
|
|
175
|
+
if (node.kind === Kind.OBJECT_TYPE_EXTENSION ||
|
|
176
|
+
node.kind === Kind.OBJECT_TYPE_DEFINITION) {
|
|
177
|
+
return [
|
|
178
|
+
"an object type",
|
|
179
|
+
"objects",
|
|
180
|
+
nodes
|
|
181
|
+
.flatMap((n) => n.fields?.map((f) => f.name.value))
|
|
182
|
+
.filter(isNotNullish),
|
|
183
|
+
];
|
|
184
|
+
}
|
|
185
|
+
else if (node.kind === Kind.INTERFACE_TYPE_EXTENSION ||
|
|
186
|
+
node.kind === Kind.INTERFACE_TYPE_DEFINITION) {
|
|
187
|
+
return [
|
|
188
|
+
"an interface type",
|
|
189
|
+
"interfaces",
|
|
190
|
+
nodes
|
|
191
|
+
.flatMap((n) => n.fields?.map((f) => f.name.value))
|
|
192
|
+
.filter(isNotNullish),
|
|
193
|
+
];
|
|
194
|
+
}
|
|
195
|
+
else if (node.kind === Kind.UNION_TYPE_EXTENSION ||
|
|
196
|
+
node.kind === Kind.UNION_TYPE_DEFINITION) {
|
|
197
|
+
return ["a union type", "unions"];
|
|
198
|
+
}
|
|
199
|
+
else if (node.kind === Kind.INPUT_OBJECT_TYPE_EXTENSION ||
|
|
200
|
+
node.kind === Kind.INPUT_OBJECT_TYPE_DEFINITION) {
|
|
201
|
+
return [
|
|
202
|
+
"an input object type",
|
|
203
|
+
"inputObjects",
|
|
204
|
+
nodes
|
|
205
|
+
.flatMap((n) => n.fields?.map((f) => f.name.value))
|
|
206
|
+
.filter(isNotNullish),
|
|
207
|
+
];
|
|
208
|
+
}
|
|
209
|
+
else if (node.kind === Kind.SCALAR_TYPE_EXTENSION ||
|
|
210
|
+
node.kind === Kind.SCALAR_TYPE_DEFINITION) {
|
|
211
|
+
return ["a scalar type", "scalars"];
|
|
212
|
+
}
|
|
213
|
+
else if (node.kind === Kind.ENUM_TYPE_EXTENSION ||
|
|
214
|
+
node.kind === Kind.ENUM_TYPE_DEFINITION) {
|
|
215
|
+
return [
|
|
216
|
+
"an enum type",
|
|
217
|
+
"enums",
|
|
218
|
+
nodes
|
|
219
|
+
.flatMap((n) => n.values?.map((f) => f.name.value))
|
|
220
|
+
.filter(isNotNullish),
|
|
221
|
+
];
|
|
222
|
+
}
|
|
223
|
+
else {
|
|
224
|
+
throw new Error(`Type ${typeName} not understood`);
|
|
225
|
+
}
|
|
226
|
+
})();
|
|
227
|
+
if (expectedLocation !== attr) {
|
|
228
|
+
throw new Error(`You defined '${typeName}' under '${expectedLocation}', but it is ${description} so it should be defined under '${attr}'.`);
|
|
229
|
+
}
|
|
230
|
+
return names;
|
|
231
|
+
};
|
|
232
|
+
for (const [typeName, spec] of Object.entries(objects ?? {})) {
|
|
233
|
+
const fields = assertLocation(typeName, "objects");
|
|
234
|
+
const o = {};
|
|
235
|
+
plans[typeName] = o;
|
|
236
|
+
const { plans: planResolvers = {}, ...rest } = spec;
|
|
237
|
+
for (const [key, val] of Object.entries(rest)) {
|
|
238
|
+
assertNotDunder(`objects.${typeName}`, key);
|
|
239
|
+
o[`__${key}`] = val;
|
|
240
|
+
}
|
|
241
|
+
for (const [key, val] of Object.entries(planResolvers)) {
|
|
242
|
+
if (!fields.includes(key)) {
|
|
243
|
+
throw new Error(`Object type '${typeName}' field '${key}' was not defined in this plugin.`);
|
|
244
|
+
}
|
|
245
|
+
o[key] = val;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
for (const [typeName, spec] of Object.entries(inputObjects ?? {})) {
|
|
249
|
+
const fields = assertLocation(typeName, "inputObjects");
|
|
250
|
+
const o = {};
|
|
251
|
+
plans[typeName] = o;
|
|
252
|
+
const { plans: planResolvers = {}, ...rest } = spec;
|
|
253
|
+
for (const [key, val] of Object.entries(rest)) {
|
|
254
|
+
assertNotDunder(`inputObjects.${typeName}`, key);
|
|
255
|
+
o[`__${key}`] = val;
|
|
256
|
+
}
|
|
257
|
+
for (const [key, val] of Object.entries(planResolvers)) {
|
|
258
|
+
if (!fields.includes(key)) {
|
|
259
|
+
throw new Error(`Input object type '${typeName}' field '${key}' was not defined in this plugin.`);
|
|
260
|
+
}
|
|
261
|
+
o[key] = val;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
for (const [typeName, spec] of Object.entries(unions ?? {})) {
|
|
265
|
+
assertLocation(typeName, "unions");
|
|
266
|
+
const o = {};
|
|
267
|
+
plans[typeName] = o;
|
|
268
|
+
for (const [key, val] of Object.entries(spec)) {
|
|
269
|
+
assertNotDunder(`unions.${typeName}`, key);
|
|
270
|
+
o[`__${key}`] = val;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
for (const [typeName, spec] of Object.entries(interfaces ?? {})) {
|
|
274
|
+
const fields = assertLocation(typeName, "interfaces");
|
|
275
|
+
const o = {};
|
|
276
|
+
plans[typeName] = o;
|
|
277
|
+
const { fields: fieldConfigs = {}, ...rest } = spec;
|
|
278
|
+
for (const [key, val] of Object.entries(rest)) {
|
|
279
|
+
assertNotDunder(`interfaces.${typeName}`, key);
|
|
280
|
+
o[`__${key}`] = val;
|
|
281
|
+
}
|
|
282
|
+
for (const [key, val] of Object.entries(fieldConfigs)) {
|
|
283
|
+
if (!fields.includes(key)) {
|
|
284
|
+
throw new Error(`Interface type '${typeName}' field '${key}' was not defined in this plugin.`);
|
|
285
|
+
}
|
|
286
|
+
o[key] = val;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
for (const [typeName, spec] of Object.entries(scalars ?? {})) {
|
|
290
|
+
assertLocation(typeName, "scalars");
|
|
291
|
+
if (spec instanceof GraphQLScalarType) {
|
|
292
|
+
plans[typeName] = spec;
|
|
293
|
+
}
|
|
294
|
+
else {
|
|
295
|
+
const { plan, serialize, extensions, parseValue, parseLiteral, ...rest } = spec;
|
|
296
|
+
const o = {
|
|
297
|
+
plan,
|
|
298
|
+
serialize,
|
|
299
|
+
extensions,
|
|
300
|
+
parseValue,
|
|
301
|
+
parseLiteral,
|
|
302
|
+
};
|
|
303
|
+
plans[typeName] = o;
|
|
304
|
+
for (const [key, val] of Object.entries(rest)) {
|
|
305
|
+
assertNotDunder(`scalars.${typeName}`, key);
|
|
306
|
+
o[`__${key}`] = val;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
for (const [typeName, spec] of Object.entries(enums ?? {})) {
|
|
311
|
+
const enumValues = assertLocation(typeName, "enums");
|
|
312
|
+
const o = {};
|
|
313
|
+
plans[typeName] = o;
|
|
314
|
+
const { values = {}, ...rest } = spec;
|
|
315
|
+
if ("plans" in rest) {
|
|
316
|
+
throw new Error(`Enum type '${typeName}' cannot have field plans, please use 'values'.`);
|
|
317
|
+
}
|
|
318
|
+
for (const [key, val] of Object.entries(rest)) {
|
|
319
|
+
assertNotDunder(`enums.${typeName}`, key);
|
|
320
|
+
o[`__${key}`] = val;
|
|
321
|
+
}
|
|
322
|
+
for (const [key, val] of Object.entries(values)) {
|
|
323
|
+
if (!enumValues.includes(key)) {
|
|
324
|
+
throw new Error(`Enum type '${typeName}' value '${key}' was not defined in this plugin.`);
|
|
325
|
+
}
|
|
326
|
+
o[key] = val;
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
}
|
|
120
330
|
build.makeExtendSchemaPlugin[uniquePluginName] = {
|
|
121
331
|
typeExtensions,
|
|
122
332
|
newTypes,
|
|
@@ -130,7 +340,9 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
130
340
|
const name = getName(definition.name);
|
|
131
341
|
const description = getDescription(definition.description);
|
|
132
342
|
const directives = getDirectives(definition.directives);
|
|
133
|
-
const relevantResolver = plans[name]
|
|
343
|
+
const relevantResolver = (plans[name] ??
|
|
344
|
+
resolvers[name] ??
|
|
345
|
+
{});
|
|
134
346
|
const values = (definition.values ?? []).reduce((memo, value) => {
|
|
135
347
|
const valueName = getName(value.name);
|
|
136
348
|
const valueDescription = getDescription(value.description);
|
|
@@ -158,7 +370,12 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
158
370
|
},
|
|
159
371
|
};
|
|
160
372
|
}, Object.create(null));
|
|
161
|
-
const scope =
|
|
373
|
+
const scope = {
|
|
374
|
+
__origin: `makeExtendSchemaPlugin`,
|
|
375
|
+
directives,
|
|
376
|
+
...scopeFromDirectives(directives),
|
|
377
|
+
...plans[name]?.__scope,
|
|
378
|
+
};
|
|
162
379
|
build.registerEnumType(name, scope, () => ({ values, description }), uniquePluginName);
|
|
163
380
|
}
|
|
164
381
|
else if (def.type === GraphQLObjectType) {
|
|
@@ -166,19 +383,27 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
166
383
|
// https://graphql.org/graphql-js/type/#graphqlobjecttype
|
|
167
384
|
const name = getName(definition.name);
|
|
168
385
|
const description = getDescription(definition.description);
|
|
169
|
-
const interfaces = getInterfaces(definition.interfaces, build);
|
|
170
386
|
const directives = getDirectives(definition.directives);
|
|
387
|
+
const p = (plans[name] ?? {});
|
|
171
388
|
const scope = {
|
|
172
389
|
__origin: `makeExtendSchemaPlugin`,
|
|
173
390
|
directives,
|
|
174
391
|
...scopeFromDirectives(directives),
|
|
392
|
+
...p.__scope,
|
|
175
393
|
};
|
|
176
394
|
build.registerObjectType(name, scope, () => ({
|
|
177
|
-
interfaces,
|
|
178
|
-
fields: (fieldsContext) => getFields(fieldsContext.Self, definition.fields, resolvers, plans
|
|
179
|
-
...(description
|
|
395
|
+
interfaces: () => getInterfaces(definition.interfaces, build),
|
|
396
|
+
fields: (fieldsContext) => getFields(build, fieldsContext, fieldsContext.Self, definition.fields, resolvers, plans),
|
|
397
|
+
...(description ? { description } : null),
|
|
398
|
+
...(p.__isTypeOf ? { isTypeOf: p.__isTypeOf } : null),
|
|
399
|
+
...(p.__assertStep || p.__planType
|
|
180
400
|
? {
|
|
181
|
-
|
|
401
|
+
extensions: {
|
|
402
|
+
grafast: {
|
|
403
|
+
assertStep: p.__assertStep,
|
|
404
|
+
planType: p.__planType,
|
|
405
|
+
},
|
|
406
|
+
},
|
|
182
407
|
}
|
|
183
408
|
: null),
|
|
184
409
|
}), uniquePluginName);
|
|
@@ -193,14 +418,11 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
193
418
|
__origin: `makeExtendSchemaPlugin`,
|
|
194
419
|
directives,
|
|
195
420
|
...scopeFromDirectives(directives),
|
|
421
|
+
...plans[name]?.__scope,
|
|
196
422
|
};
|
|
197
423
|
build.registerInputObjectType(name, scope, () => ({
|
|
198
|
-
fields: (
|
|
199
|
-
...(description
|
|
200
|
-
? {
|
|
201
|
-
description,
|
|
202
|
-
}
|
|
203
|
-
: null),
|
|
424
|
+
fields: (context) => getInputFields(build, context, definition.fields, plans),
|
|
425
|
+
...(description ? { description } : null),
|
|
204
426
|
}), uniquePluginName);
|
|
205
427
|
}
|
|
206
428
|
else if (def.type === GraphQLUnionType) {
|
|
@@ -209,12 +431,21 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
209
431
|
const name = getName(definition.name);
|
|
210
432
|
const description = getDescription(definition.description);
|
|
211
433
|
const directives = getDirectives(definition.directives);
|
|
434
|
+
const tp = plans[name];
|
|
435
|
+
const tr = resolvers[name];
|
|
436
|
+
if (tp && tr) {
|
|
437
|
+
throw new Error(`You must set only plans.${name} or resolvers.${name} - not both!`);
|
|
438
|
+
}
|
|
439
|
+
const t = tp ?? tr;
|
|
212
440
|
const scope = {
|
|
213
441
|
__origin: `makeExtendSchemaPlugin`,
|
|
214
442
|
directives,
|
|
215
443
|
...scopeFromDirectives(directives),
|
|
444
|
+
...t?.__scope,
|
|
216
445
|
};
|
|
217
|
-
const resolveType =
|
|
446
|
+
const resolveType = t?.__resolveType;
|
|
447
|
+
const toSpecifier = t?.__toSpecifier;
|
|
448
|
+
const planType = t?.__planType;
|
|
218
449
|
build.registerUnionType(name, scope, () => ({
|
|
219
450
|
types: () => {
|
|
220
451
|
if (Array.isArray(definition.types)) {
|
|
@@ -230,6 +461,8 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
230
461
|
}
|
|
231
462
|
},
|
|
232
463
|
...(resolveType ? { resolveType } : null),
|
|
464
|
+
...(toSpecifier ? { toSpecifier } : null),
|
|
465
|
+
...(planType ? { planType } : null),
|
|
233
466
|
...(description ? { description } : null),
|
|
234
467
|
}), uniquePluginName);
|
|
235
468
|
}
|
|
@@ -239,18 +472,27 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
239
472
|
const name = getName(definition.name);
|
|
240
473
|
const description = getDescription(definition.description);
|
|
241
474
|
const directives = getDirectives(definition.directives);
|
|
475
|
+
const tp = plans[name];
|
|
476
|
+
const tr = resolvers[name];
|
|
477
|
+
if (tp && tr) {
|
|
478
|
+
throw new Error(`You must set only plans.${name} or resolvers.${name} - not both!`);
|
|
479
|
+
}
|
|
480
|
+
const t = tp ?? tr;
|
|
242
481
|
const scope = {
|
|
243
482
|
__origin: `makeExtendSchemaPlugin`,
|
|
244
483
|
directives,
|
|
245
484
|
...scopeFromDirectives(directives),
|
|
485
|
+
...t?.__scope,
|
|
246
486
|
};
|
|
247
|
-
const resolveType =
|
|
487
|
+
const resolveType = t?.__resolveType;
|
|
488
|
+
const toSpecifier = t?.__toSpecifier;
|
|
489
|
+
const planType = t?.__planType;
|
|
248
490
|
build.registerInterfaceType(name, scope, () => ({
|
|
249
491
|
...(resolveType ? { resolveType } : null),
|
|
492
|
+
...(toSpecifier ? { toSpecifier } : null),
|
|
493
|
+
...(planType ? { planType } : null),
|
|
250
494
|
...(description ? { description } : null),
|
|
251
|
-
fields: (fieldsContext) => getFields(fieldsContext.Self, definition.fields,
|
|
252
|
-
Object.create(null), // Interface doesn't need resolvers
|
|
253
|
-
fieldsContext, build),
|
|
495
|
+
fields: (fieldsContext) => getFields(build, fieldsContext, fieldsContext.Self, definition.fields, resolvers, plans),
|
|
254
496
|
...(description
|
|
255
497
|
? {
|
|
256
498
|
description,
|
|
@@ -267,34 +509,42 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
267
509
|
__origin: `makeExtendSchemaPlugin`,
|
|
268
510
|
directives,
|
|
269
511
|
...scopeFromDirectives(directives),
|
|
512
|
+
...plans[name]?.__scope,
|
|
270
513
|
};
|
|
514
|
+
const possiblePlan = plans[name];
|
|
515
|
+
const possibleResolver = resolvers[name];
|
|
516
|
+
if (possiblePlan && possibleResolver) {
|
|
517
|
+
throw new Error(`You must set only plans.${name} or resolvers.${name} - not both!`);
|
|
518
|
+
}
|
|
519
|
+
const rawConfig = possiblePlan ?? possibleResolver;
|
|
520
|
+
const config = rawConfig
|
|
521
|
+
? rawConfig instanceof GraphQLScalarType
|
|
522
|
+
? (0, exportable_js_1.EXPORTABLE)((rawConfig) => rawConfig.toConfig(), [rawConfig])
|
|
523
|
+
: rawConfig
|
|
524
|
+
: null;
|
|
271
525
|
build.registerScalarType(name, scope, () => ({
|
|
272
526
|
description,
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
527
|
+
astNode: definition,
|
|
528
|
+
extensions: config?.extensions,
|
|
529
|
+
specifiedByURL: config?.specifiedByURL,
|
|
530
|
+
serialize: config?.serialize
|
|
531
|
+
? (0, exportable_js_1.EXPORTABLE)((config) => config.serialize, [config])
|
|
532
|
+
: (0, exportable_js_1.EXPORTABLE)(() => (value) => String(value), []),
|
|
533
|
+
parseValue: config?.parseValue
|
|
534
|
+
? (0, exportable_js_1.EXPORTABLE)((config) => config.parseValue, [config])
|
|
535
|
+
: (0, exportable_js_1.EXPORTABLE)(() => (value) => String(value), []),
|
|
536
|
+
parseLiteral: config?.parseLiteral
|
|
537
|
+
? (0, exportable_js_1.EXPORTABLE)((config) => config.parseLiteral, [config])
|
|
538
|
+
: (0, exportable_js_1.EXPORTABLE)((GraphQLError, Kind, name) => (ast) => {
|
|
539
|
+
if (ast.kind !== Kind.STRING) {
|
|
540
|
+
throw new GraphQLError(`${name} can only parse string values`);
|
|
541
|
+
}
|
|
542
|
+
return ast.value;
|
|
543
|
+
}, [GraphQLError, Kind, name]),
|
|
281
544
|
}), uniquePluginName);
|
|
282
545
|
}
|
|
283
546
|
else if (def.type === GraphQLDirective) {
|
|
284
|
-
|
|
285
|
-
// https://github.com/graphql/graphql-js/blob/3c54315ab13c6b9d337fb7c33ad7e27b92ca4a40/src/type/directives.js#L106-L113
|
|
286
|
-
const name = getName(definition.name);
|
|
287
|
-
const description = getDescription(definition.description);
|
|
288
|
-
const locations = definition.locations.map(getName);
|
|
289
|
-
const args = getArguments(definition.arguments, build);
|
|
290
|
-
// Ignoring isRepeatable and astNode for now
|
|
291
|
-
const directive = new GraphQLDirective({
|
|
292
|
-
name,
|
|
293
|
-
locations,
|
|
294
|
-
args,
|
|
295
|
-
...(description ? { description } : null),
|
|
296
|
-
});
|
|
297
|
-
typeExtensions.GraphQLSchema.directives.push(directive);
|
|
547
|
+
typeExtensions.GraphQLSchema.directives.push(def.definition);
|
|
298
548
|
}
|
|
299
549
|
else {
|
|
300
550
|
throw new Error(`We have no code to build an object of type '${def.type}'; it should not have reached this area of the code.`);
|
|
@@ -303,16 +553,37 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
303
553
|
return _;
|
|
304
554
|
},
|
|
305
555
|
GraphQLSchema(schema, build, _context) {
|
|
306
|
-
const { makeExtendSchemaPlugin: { [uniquePluginName]: { typeExtensions }, }, } = build;
|
|
556
|
+
const { graphql: { GraphQLDirective }, inflection, makeExtendSchemaPlugin: { [uniquePluginName]: { typeExtensions, newTypes }, }, } = build;
|
|
557
|
+
const newDirectives = [];
|
|
558
|
+
for (const definition of typeExtensions.GraphQLSchema.directives) {
|
|
559
|
+
// https://github.com/graphql/graphql-js/blob/3c54315ab13c6b9d337fb7c33ad7e27b92ca4a40/src/type/directives.js#L106-L113
|
|
560
|
+
const name = getName(definition.name);
|
|
561
|
+
const description = getDescription(definition.description);
|
|
562
|
+
const locations = definition.locations.map(getName);
|
|
563
|
+
const args = getArguments(definition.arguments, build);
|
|
564
|
+
// Ignoring isRepeatable and astNode for now
|
|
565
|
+
const directive = new GraphQLDirective({
|
|
566
|
+
name,
|
|
567
|
+
locations,
|
|
568
|
+
args,
|
|
569
|
+
...(description ? { description } : null),
|
|
570
|
+
});
|
|
571
|
+
newDirectives.push(directive);
|
|
572
|
+
}
|
|
307
573
|
return {
|
|
308
574
|
...schema,
|
|
309
575
|
directives: [
|
|
310
|
-
...(schema.directives || build.graphql.specifiedDirectives
|
|
311
|
-
...
|
|
576
|
+
...(schema.directives || build.graphql.specifiedDirectives),
|
|
577
|
+
...newDirectives,
|
|
312
578
|
],
|
|
313
579
|
types: [
|
|
314
580
|
...(schema.types || []),
|
|
315
|
-
...
|
|
581
|
+
...[
|
|
582
|
+
build.getTypeByName(inflection.builtin("Query")),
|
|
583
|
+
build.getTypeByName(inflection.builtin("Mutation")),
|
|
584
|
+
build.getTypeByName(inflection.builtin("Subscription")),
|
|
585
|
+
...newTypes.map(({ definition }) => build.getTypeByName(definition.name.value)),
|
|
586
|
+
].filter((_) => _ != null),
|
|
316
587
|
],
|
|
317
588
|
};
|
|
318
589
|
},
|
|
@@ -321,7 +592,7 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
321
592
|
const { Self } = context;
|
|
322
593
|
if (typeExtensions.GraphQLObjectType[Self.name]) {
|
|
323
594
|
const newFields = typeExtensions.GraphQLObjectType[Self.name].reduce((memo, extension) => {
|
|
324
|
-
const moreFields = getFields(Self, extension.fields, resolvers, plans
|
|
595
|
+
const moreFields = getFields(build, context, Self, extension.fields, resolvers, plans);
|
|
325
596
|
return extend(memo, moreFields, `Adding fields from ${uniquePluginName}`);
|
|
326
597
|
}, Object.create(null));
|
|
327
598
|
return extend(fields, newFields, `Adding fields from ${uniquePluginName}`);
|
|
@@ -331,25 +602,22 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
331
602
|
}
|
|
332
603
|
},
|
|
333
604
|
GraphQLObjectType_interfaces(interfaces, build, context) {
|
|
334
|
-
const {
|
|
605
|
+
const { append, makeExtendSchemaPlugin: { [uniquePluginName]: { typeExtensions }, }, } = build;
|
|
335
606
|
const { Self } = context;
|
|
336
607
|
if (typeExtensions.GraphQLObjectType[Self.name]) {
|
|
337
|
-
const newInterfaces = typeExtensions.GraphQLObjectType[Self.name].
|
|
338
|
-
|
|
339
|
-
return extend(memo, moreInterfaces, `Adding interfaces from ${uniquePluginName}`);
|
|
340
|
-
}, Object.create(null));
|
|
341
|
-
return extend(interfaces, newInterfaces, `Adding interfaces from ${uniquePluginName}`);
|
|
608
|
+
const newInterfaces = typeExtensions.GraphQLObjectType[Self.name].flatMap((extension) => getInterfaces(extension.interfaces, build));
|
|
609
|
+
return append(interfaces, newInterfaces, "name", `Adding interfaces from ${uniquePluginName}`);
|
|
342
610
|
}
|
|
343
611
|
else {
|
|
344
612
|
return interfaces;
|
|
345
613
|
}
|
|
346
614
|
},
|
|
347
615
|
GraphQLInputObjectType_fields(fields, build, context) {
|
|
348
|
-
const { extend, makeExtendSchemaPlugin: { [uniquePluginName]: { typeExtensions }, }, } = build;
|
|
616
|
+
const { extend, makeExtendSchemaPlugin: { [uniquePluginName]: { typeExtensions, plans }, }, } = build;
|
|
349
617
|
const { Self } = context;
|
|
350
618
|
if (typeExtensions.GraphQLInputObjectType[Self.name]) {
|
|
351
619
|
const newFields = typeExtensions.GraphQLInputObjectType[Self.name].reduce((memo, extension) => {
|
|
352
|
-
const moreFields = getInputFields(
|
|
620
|
+
const moreFields = getInputFields(build, context, extension.fields, plans);
|
|
353
621
|
return extend(memo, moreFields, `Adding fields from ${uniquePluginName}`);
|
|
354
622
|
}, Object.create(null));
|
|
355
623
|
return extend(fields, newFields, `Adding fields from ${uniquePluginName}`);
|
|
@@ -359,13 +627,11 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
359
627
|
}
|
|
360
628
|
},
|
|
361
629
|
GraphQLInterfaceType_fields(fields, build, context) {
|
|
362
|
-
const { extend, makeExtendSchemaPlugin: { [uniquePluginName]: { typeExtensions }, }, } = build;
|
|
630
|
+
const { extend, makeExtendSchemaPlugin: { [uniquePluginName]: { typeExtensions, resolvers, plans }, }, } = build;
|
|
363
631
|
const { Self } = context;
|
|
364
632
|
if (typeExtensions.GraphQLInterfaceType[Self.name]) {
|
|
365
633
|
const newFields = typeExtensions.GraphQLInterfaceType[Self.name].reduce((memo, extension) => {
|
|
366
|
-
const moreFields = getFields(Self, extension.fields,
|
|
367
|
-
Object.create(null), // No resolvers for interfaces
|
|
368
|
-
context, build);
|
|
634
|
+
const moreFields = getFields(build, context, Self, extension.fields, resolvers, plans);
|
|
369
635
|
return extend(memo, moreFields, `Adding fields from ${uniquePluginName}`);
|
|
370
636
|
}, Object.create(null));
|
|
371
637
|
return extend(fields, newFields, `Adding fields from ${uniquePluginName}`);
|
|
@@ -375,14 +641,11 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
375
641
|
}
|
|
376
642
|
},
|
|
377
643
|
GraphQLInterfaceType_interfaces(interfaces, build, context) {
|
|
378
|
-
const {
|
|
644
|
+
const { append, makeExtendSchemaPlugin: { [uniquePluginName]: { typeExtensions }, }, } = build;
|
|
379
645
|
const { Self } = context;
|
|
380
646
|
if (typeExtensions.GraphQLInterfaceType[Self.name]) {
|
|
381
|
-
const newInterfaces = typeExtensions.GraphQLInterfaceType[Self.name].
|
|
382
|
-
|
|
383
|
-
return extend(memo, moreInterfaces, `Adding interfaces from ${uniquePluginName}`);
|
|
384
|
-
}, Object.create(null));
|
|
385
|
-
return extend(interfaces, newInterfaces, `Adding interfaces from ${uniquePluginName}`);
|
|
647
|
+
const newInterfaces = typeExtensions.GraphQLInterfaceType[Self.name].flatMap((extension) => getInterfaces(extension.interfaces, build));
|
|
648
|
+
return append(interfaces, newInterfaces, "name", `Adding interfaces from ${uniquePluginName}`);
|
|
386
649
|
}
|
|
387
650
|
else {
|
|
388
651
|
return interfaces;
|
|
@@ -412,7 +675,7 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
412
675
|
if (type.kind === "NamedType") {
|
|
413
676
|
const Type = build.getTypeByName(getName(type.name));
|
|
414
677
|
if (!Type) {
|
|
415
|
-
throw new Error(
|
|
678
|
+
throw new Error(`${uniquePluginName} could not find type named '${getName(type.name)}'.`);
|
|
416
679
|
}
|
|
417
680
|
return Type;
|
|
418
681
|
}
|
|
@@ -507,8 +770,12 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
507
770
|
if (arg.defaultValue) {
|
|
508
771
|
defaultValue = getValue(arg.defaultValue, type);
|
|
509
772
|
}
|
|
773
|
+
const argDirectives = getDirectives(arg.directives);
|
|
774
|
+
const deprecatedDirective = argDirectives.find((d) => d.directiveName === "deprecated");
|
|
775
|
+
const deprecationReason = deprecatedDirective?.args.reason;
|
|
510
776
|
memo[name] = {
|
|
511
777
|
type,
|
|
778
|
+
deprecationReason,
|
|
512
779
|
...(defaultValue != null ? { defaultValue } : null),
|
|
513
780
|
...(description ? { description } : null),
|
|
514
781
|
};
|
|
@@ -521,7 +788,8 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
521
788
|
}
|
|
522
789
|
return {};
|
|
523
790
|
}
|
|
524
|
-
function getFields(SelfGeneric, fields, resolvers, plans
|
|
791
|
+
function getFields(build, context, SelfGeneric, fields, resolvers, plans) {
|
|
792
|
+
const { graphql: { getNullableType, getNamedType }, } = build;
|
|
525
793
|
const { fieldWithHooks } = context;
|
|
526
794
|
const isRootSubscription = "isRootSubscription" in context.scope && context.scope.isRootSubscription;
|
|
527
795
|
if (!build.graphql.isNamedType(SelfGeneric)) {
|
|
@@ -536,25 +804,6 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
536
804
|
const args = getArguments(field.arguments, build);
|
|
537
805
|
const type = getType(field.type, build);
|
|
538
806
|
const directives = getDirectives(field.directives);
|
|
539
|
-
const scope = {
|
|
540
|
-
fieldName,
|
|
541
|
-
/*
|
|
542
|
-
...(typeScope.pgIntrospection &&
|
|
543
|
-
typeScope.pgIntrospection.kind === "class"
|
|
544
|
-
? {
|
|
545
|
-
pgFieldIntrospection: typeScope.pgIntrospection,
|
|
546
|
-
}
|
|
547
|
-
: null),
|
|
548
|
-
...(typeScope.isPgRowConnectionType && typeScope.pgIntrospection
|
|
549
|
-
? {
|
|
550
|
-
isPgFieldConnection: true,
|
|
551
|
-
pgFieldIntrospection: typeScope.pgIntrospection,
|
|
552
|
-
}
|
|
553
|
-
: null),
|
|
554
|
-
*/
|
|
555
|
-
fieldDirectives: directives,
|
|
556
|
-
...scopeFromDirectives(directives),
|
|
557
|
-
};
|
|
558
807
|
const deprecatedDirective = directives.find((d) => d.directiveName === "deprecated");
|
|
559
808
|
const deprecationReason = deprecatedDirective?.args.reason;
|
|
560
809
|
/*
|
|
@@ -563,24 +812,18 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
563
812
|
* other relevant methods.
|
|
564
813
|
*/
|
|
565
814
|
const possiblePlan = plans[Self.name]?.[fieldName];
|
|
815
|
+
build.exportNameHint(possiblePlan, `${Self.name}_${fieldName}_plan`);
|
|
566
816
|
const possibleResolver = resolvers[Self.name]?.[fieldName];
|
|
817
|
+
build.exportNameHint(possibleResolver, `${Self.name}_${fieldName}_resolver`);
|
|
567
818
|
if (possiblePlan && possibleResolver) {
|
|
568
819
|
throw new Error(`You must set only plans.${Self.name}.${fieldName} or resolvers.${Self.name}.${fieldName} - not both!`);
|
|
569
820
|
}
|
|
570
821
|
const spec = possiblePlan ?? possibleResolver;
|
|
571
822
|
const fieldSpecGenerator = () => {
|
|
572
823
|
return {
|
|
573
|
-
...(deprecationReason
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
}
|
|
577
|
-
: null),
|
|
578
|
-
...(description
|
|
579
|
-
? {
|
|
580
|
-
description,
|
|
581
|
-
}
|
|
582
|
-
: null),
|
|
583
|
-
...(typeof spec === "function"
|
|
824
|
+
...(deprecationReason ? { deprecationReason } : null),
|
|
825
|
+
...(description ? { description } : null),
|
|
826
|
+
...(build.graphql.isObjectType(Self) && typeof spec === "function"
|
|
584
827
|
? {
|
|
585
828
|
[possiblePlan
|
|
586
829
|
? isRootSubscription
|
|
@@ -595,6 +838,42 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
595
838
|
args,
|
|
596
839
|
};
|
|
597
840
|
};
|
|
841
|
+
const nullableType = getNullableType(type);
|
|
842
|
+
const namedType = getNamedType(type);
|
|
843
|
+
const typeScope = build.scopeByType.get(namedType);
|
|
844
|
+
const scope = {
|
|
845
|
+
fieldDirectives: directives,
|
|
846
|
+
// Guess a codec and resource
|
|
847
|
+
...(typeScope && "pgCodec" in typeScope && typeScope.pgCodec
|
|
848
|
+
? {
|
|
849
|
+
pgFieldCodec: typeScope.pgCodec,
|
|
850
|
+
// First guess at a resource; may be overwritten
|
|
851
|
+
pgFieldResource: Object.values(build.input.pgRegistry.pgResources).find((r) => r.codec === typeScope.pgCodec &&
|
|
852
|
+
!r.isUnique &&
|
|
853
|
+
!r.parameters &&
|
|
854
|
+
!r.isVirtual &&
|
|
855
|
+
!r.isList &&
|
|
856
|
+
!r.codec.polymorphism),
|
|
857
|
+
}
|
|
858
|
+
: null),
|
|
859
|
+
// Guess (more accurately) a resource
|
|
860
|
+
...(typeScope &&
|
|
861
|
+
"pgTypeResource" in typeScope &&
|
|
862
|
+
typeScope.pgTypeResource
|
|
863
|
+
? { pgFieldResource: typeScope.pgTypeResource }
|
|
864
|
+
: null),
|
|
865
|
+
// Guess if it's a connection
|
|
866
|
+
...(nullableType === namedType &&
|
|
867
|
+
typeScope &&
|
|
868
|
+
"isConnectionType" in typeScope
|
|
869
|
+
? { isPgFieldConnection: typeScope.isConnectionType }
|
|
870
|
+
: null),
|
|
871
|
+
// Allow user to overwrite
|
|
872
|
+
...scopeFromDirectives(directives),
|
|
873
|
+
...(typeof spec === "object" && spec !== null ? spec.scope : null),
|
|
874
|
+
// fieldName always wins
|
|
875
|
+
fieldName,
|
|
876
|
+
};
|
|
598
877
|
return build.extend(memo, {
|
|
599
878
|
[fieldName]: fieldWithHooks(scope, fieldSpecGenerator),
|
|
600
879
|
}, `Adding '${fieldName}' to '${Self.name}' from '${uniquePluginName}'`);
|
|
@@ -606,25 +885,37 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
606
885
|
}
|
|
607
886
|
return {};
|
|
608
887
|
}
|
|
609
|
-
function getInputFields(
|
|
888
|
+
function getInputFields(build, context, fields, plans) {
|
|
889
|
+
const { Self } = context;
|
|
610
890
|
if (fields && fields.length) {
|
|
611
891
|
return fields.reduce((memo, field) => {
|
|
612
892
|
if (field.kind === "InputValueDefinition") {
|
|
613
893
|
const description = getDescription(field.description);
|
|
614
894
|
const fieldName = getName(field.name);
|
|
615
895
|
const type = getType(field.type, build);
|
|
896
|
+
const directives = getDirectives(field.directives);
|
|
897
|
+
if (!build.graphql.isInputType(type)) {
|
|
898
|
+
throw new Error(`${Self.name}.${fieldName} must use an input type`);
|
|
899
|
+
}
|
|
616
900
|
const defaultValue = field.defaultValue
|
|
617
901
|
? getValue(field.defaultValue, type)
|
|
618
902
|
: undefined;
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
903
|
+
const spec = plans[Self.name]?.[fieldName];
|
|
904
|
+
const scope = {
|
|
905
|
+
fieldDirectives: directives,
|
|
906
|
+
// Allow user to overwrite
|
|
907
|
+
...scopeFromDirectives(directives),
|
|
908
|
+
...(typeof spec === "object" && spec !== null
|
|
909
|
+
? spec.scope
|
|
626
910
|
: null),
|
|
911
|
+
// fieldName always wins
|
|
912
|
+
fieldName,
|
|
627
913
|
};
|
|
914
|
+
memo[fieldName] = context.fieldWithHooks(scope, {
|
|
915
|
+
type,
|
|
916
|
+
defaultValue,
|
|
917
|
+
...(description ? { description } : null),
|
|
918
|
+
});
|
|
628
919
|
}
|
|
629
920
|
else {
|
|
630
921
|
throw new Error(`AST issue: expected 'FieldDefinition', instead received '${field.kind}'`);
|
|
@@ -635,7 +926,6 @@ function makeExtendSchemaPlugin(generator, uniquePluginName = `ExtendSchemaPlugi
|
|
|
635
926
|
return {};
|
|
636
927
|
}
|
|
637
928
|
}
|
|
638
|
-
exports.makeExtendSchemaPlugin = makeExtendSchemaPlugin;
|
|
639
929
|
function scopeFromDirectives(directives) {
|
|
640
930
|
return {
|
|
641
931
|
...directives
|
|
@@ -644,4 +934,14 @@ function scopeFromDirectives(directives) {
|
|
|
644
934
|
.reduce((memo, a) => Object.assign(memo, a), Object.create(null)),
|
|
645
935
|
};
|
|
646
936
|
}
|
|
937
|
+
function isNotNullish(v) {
|
|
938
|
+
return v != null;
|
|
939
|
+
}
|
|
940
|
+
/** @deprecated Renamed to 'extendSchema' */
|
|
941
|
+
exports.makeExtendSchemaPlugin = extendSchema;
|
|
942
|
+
function assertNotDunder(loc, key) {
|
|
943
|
+
if (key.startsWith("__")) {
|
|
944
|
+
throw new Error(`Key ${JSON.stringify(key)} defined at location ${loc} shouldn't start with __`);
|
|
945
|
+
}
|
|
946
|
+
}
|
|
647
947
|
//# sourceMappingURL=makeExtendSchemaPlugin.js.map
|