grafast 0.1.1-beta.2 → 0.1.1-beta.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -3
- package/dist/args.d.ts +4 -7
- package/dist/args.js +53 -38
- package/dist/assert.js +2 -3
- package/dist/bucket.d.ts +1 -89
- package/dist/config.d.ts +0 -17
- package/dist/config.js +1 -95
- package/dist/constraints.d.ts +15 -1
- package/dist/constraints.js +41 -3
- package/dist/deferred.js +1 -2
- package/dist/dev.d.ts +1 -4
- package/dist/dev.js +18 -3
- package/dist/engine/LayerPlan.d.ts +21 -111
- package/dist/engine/LayerPlan.js +196 -78
- package/dist/engine/OperationPlan.d.ts +30 -104
- package/dist/engine/OperationPlan.js +763 -471
- package/dist/engine/OutputPlan.d.ts +9 -20
- package/dist/engine/OutputPlan.js +432 -444
- package/dist/engine/StepTracker.d.ts +1 -95
- package/dist/engine/StepTracker.js +94 -20
- package/dist/engine/executeBucket.d.ts +5 -7
- package/dist/engine/executeBucket.js +646 -244
- package/dist/engine/executeOutputPlan.d.ts +0 -53
- package/dist/engine/executeOutputPlan.js +7 -2
- package/dist/engine/lib/defaultPlanResolver.d.ts +6 -0
- package/dist/engine/lib/defaultPlanResolver.js +11 -0
- package/dist/engine/lib/withGlobalLayerPlan.d.ts +2 -0
- package/dist/engine/lib/withGlobalLayerPlan.js +7 -4
- package/dist/engine/lock.d.ts +4 -0
- package/dist/engine/lock.js +82 -0
- package/dist/envelop.js +5 -4
- package/dist/error.d.ts +18 -49
- package/dist/error.js +50 -39
- package/dist/establishOperationPlan.js +57 -42
- package/dist/execute.d.ts +5 -4
- package/dist/execute.js +31 -15
- package/dist/exportAs.d.ts +1 -18
- package/dist/exportAs.js +2 -3
- package/dist/global.js +2 -3
- package/dist/grafastGraphql.d.ts +6 -1
- package/dist/grafastGraphql.js +35 -16
- package/dist/grafastPrint.d.ts +3 -0
- package/dist/grafastPrint.js +67 -6
- package/dist/graphqlCollectFields.d.ts +7 -34
- package/dist/graphqlCollectFields.js +24 -13
- package/dist/graphqlMergeSelectionSets.js +1 -2
- package/dist/index.d.ts +44 -29
- package/dist/index.js +91 -18
- package/dist/input.d.ts +1 -9
- package/dist/input.js +75 -28
- package/dist/inspect.d.ts +9 -3
- package/dist/inspect.js +3 -3
- package/dist/interfaces.d.ts +238 -93
- package/dist/interfaces.js +20 -3
- package/dist/makeGrafastSchema.d.ts +21 -9
- package/dist/makeGrafastSchema.js +353 -133
- package/dist/mermaid.d.ts +0 -17
- package/dist/mermaid.js +131 -19
- package/dist/middleware.d.ts +7 -0
- package/dist/middleware.js +24 -0
- package/dist/multistep.d.ts +19 -0
- package/dist/multistep.js +54 -0
- package/dist/operationPlan-input.d.ts +5 -4
- package/dist/operationPlan-input.js +140 -368
- package/dist/planJSONInterfaces.d.ts +12 -2
- package/dist/polymorphic.js +4 -5
- package/dist/prepare.d.ts +1 -7
- package/dist/prepare.js +100 -74
- package/dist/step.d.ts +118 -172
- package/dist/step.js +262 -183
- package/dist/steps/__flag.d.ts +65 -0
- package/dist/steps/__flag.js +261 -0
- package/dist/steps/__inputDefault.d.ts +14 -0
- package/dist/steps/__inputDefault.js +48 -0
- package/dist/steps/__inputDynamicScalar.d.ts +4 -6
- package/dist/steps/__inputDynamicScalar.js +4 -2
- package/dist/steps/__inputList.d.ts +5 -9
- package/dist/steps/__inputList.js +4 -1
- package/dist/steps/__inputObject.d.ts +7 -11
- package/dist/steps/__inputObject.js +49 -3
- package/dist/steps/__inputStaticLeaf.d.ts +2 -4
- package/dist/steps/__inputStaticLeaf.js +3 -1
- package/dist/steps/__item.d.ts +10 -12
- package/dist/steps/__item.js +8 -2
- package/dist/steps/__trackedValue.d.ts +7 -55
- package/dist/steps/__trackedValue.js +69 -8
- package/dist/steps/__value.d.ts +5 -4
- package/dist/steps/__value.js +5 -4
- package/dist/steps/access.d.ts +10 -10
- package/dist/steps/access.js +50 -17
- package/dist/steps/applyInput.d.ts +44 -0
- package/dist/steps/applyInput.js +206 -0
- package/dist/steps/applyTransforms.d.ts +2 -25
- package/dist/steps/applyTransforms.js +53 -31
- package/dist/steps/bakedInput.d.ts +23 -0
- package/dist/steps/bakedInput.js +90 -0
- package/dist/steps/condition.d.ts +31 -0
- package/dist/steps/condition.js +94 -0
- package/dist/steps/connection.d.ts +56 -42
- package/dist/steps/connection.js +97 -44
- package/dist/steps/constant.d.ts +7 -7
- package/dist/steps/constant.js +86 -7
- package/dist/steps/each.d.ts +3 -3
- package/dist/steps/each.js +2 -3
- package/dist/steps/error.d.ts +4 -4
- package/dist/steps/error.js +7 -6
- package/dist/steps/filter.d.ts +3 -2
- package/dist/steps/filter.js +1 -2
- package/dist/steps/first.d.ts +10 -9
- package/dist/steps/first.js +9 -13
- package/dist/steps/graphqlResolver.d.ts +3 -76
- package/dist/steps/graphqlResolver.js +89 -72
- package/dist/steps/groupBy.d.ts +3 -2
- package/dist/steps/groupBy.js +1 -2
- package/dist/steps/index.d.ts +12 -3
- package/dist/steps/index.js +48 -6
- package/dist/steps/lambda.d.ts +9 -9
- package/dist/steps/lambda.js +18 -9
- package/dist/steps/last.d.ts +9 -8
- package/dist/steps/last.js +7 -6
- package/dist/steps/list.d.ts +20 -9
- package/dist/steps/list.js +56 -13
- package/dist/steps/listTransform.d.ts +18 -22
- package/dist/steps/listTransform.js +58 -27
- package/dist/steps/listen.d.ts +6 -11
- package/dist/steps/listen.js +14 -16
- package/dist/steps/load.d.ts +42 -33
- package/dist/steps/load.js +60 -27
- package/dist/steps/node.d.ts +17 -10
- package/dist/steps/node.js +18 -6
- package/dist/steps/object.d.ts +33 -27
- package/dist/steps/object.js +53 -32
- package/dist/steps/partitionByIndex.d.ts +3 -2
- package/dist/steps/partitionByIndex.js +1 -2
- package/dist/steps/polymorphicBranch.d.ts +27 -0
- package/dist/steps/polymorphicBranch.js +62 -0
- package/dist/steps/proxy.d.ts +11 -12
- package/dist/steps/proxy.js +8 -5
- package/dist/steps/remapKeys.d.ts +10 -10
- package/dist/steps/remapKeys.js +14 -7
- package/dist/steps/reverse.d.ts +8 -8
- package/dist/steps/reverse.js +10 -7
- package/dist/steps/setter.d.ts +9 -18
- package/dist/steps/setter.js +24 -14
- package/dist/steps/sideEffect.d.ts +28 -0
- package/dist/steps/sideEffect.js +44 -0
- package/dist/stringifyPayload.js +1 -2
- package/dist/stripAnsi.js +2 -2
- package/dist/subscribe.d.ts +7 -1
- package/dist/subscribe.js +24 -9
- package/dist/thereCanBeOnlyOne.js +1 -1
- package/dist/timeSource.d.ts +0 -1
- package/dist/utils.d.ts +56 -55
- package/dist/utils.js +179 -59
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +5 -8
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeGrafastSchema =
|
|
3
|
+
exports.makeGrafastSchema = makeGrafastSchema;
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
|
+
const graphql_1 = require("graphql");
|
|
5
6
|
const graphql = tslib_1.__importStar(require("graphql"));
|
|
7
|
+
const utils_js_1 = require("./utils.js");
|
|
6
8
|
const { buildASTSchema, isEnumType, isInputObjectType, isInterfaceType, isObjectType, isScalarType, isUnionType, parse, } = graphql;
|
|
7
9
|
/**
|
|
8
10
|
* Takes a GraphQL schema definition in Interface Definition Language (IDL/SDL)
|
|
@@ -10,165 +12,383 @@ const { buildASTSchema, isEnumType, isInputObjectType, isInterfaceType, isObject
|
|
|
10
12
|
*/
|
|
11
13
|
function makeGrafastSchema(details) {
|
|
12
14
|
const { typeDefs, plans, enableDeferStream = false } = details;
|
|
13
|
-
const
|
|
15
|
+
const astSchema = buildASTSchema(parse(typeDefs), {
|
|
14
16
|
enableDeferStream,
|
|
15
17
|
});
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
if (
|
|
18
|
+
const schemaConfig = astSchema.toConfig();
|
|
19
|
+
const typeByName = new Map();
|
|
20
|
+
function mapType(type) {
|
|
21
|
+
if (graphql.isNonNullType(type)) {
|
|
22
|
+
return new graphql.GraphQLNonNull(mapType(type.ofType));
|
|
23
|
+
}
|
|
24
|
+
else if (graphql.isListType(type)) {
|
|
25
|
+
return new graphql.GraphQLList(mapType(type.ofType));
|
|
26
|
+
}
|
|
27
|
+
else {
|
|
28
|
+
const replacementType = typeByName.get(type.name);
|
|
29
|
+
if (!replacementType) {
|
|
30
|
+
throw new Error(`Failed to find replaced type '${type.name}'`);
|
|
31
|
+
}
|
|
32
|
+
return replacementType;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
for (const [typeName, _spec] of Object.entries(plans)) {
|
|
36
|
+
const astTypeIndex = schemaConfig.types.findIndex((t) => t.name === typeName);
|
|
37
|
+
const astType = schemaConfig.types[astTypeIndex];
|
|
38
|
+
if (!astType) {
|
|
20
39
|
console.warn(`'plans' specified configuration for type '${typeName}', but that type was not present in the schema`);
|
|
21
40
|
continue;
|
|
22
41
|
}
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
42
|
+
}
|
|
43
|
+
const BUILT_IN_TYPE_NAMES = ["String", "Int", "Float", "Boolean", "ID"];
|
|
44
|
+
// Now mod the types
|
|
45
|
+
const rawTypes = schemaConfig.types;
|
|
46
|
+
schemaConfig.types = rawTypes.map((astType) => {
|
|
47
|
+
const typeName = astType.name;
|
|
48
|
+
const replacementType = (() => {
|
|
49
|
+
if (typeName.startsWith("__") || BUILT_IN_TYPE_NAMES.includes(typeName)) {
|
|
50
|
+
return astType;
|
|
26
51
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
field
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
52
|
+
if (isObjectType(astType)) {
|
|
53
|
+
const rawConfig = astType.toConfig();
|
|
54
|
+
const objectPlans = plans[astType.name];
|
|
55
|
+
const rawFields = rawConfig.fields;
|
|
56
|
+
const rawInterfaces = rawConfig.interfaces;
|
|
57
|
+
const config = {
|
|
58
|
+
...rawConfig,
|
|
59
|
+
extensions: {
|
|
60
|
+
...rawConfig.extensions,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
if (objectPlans) {
|
|
64
|
+
for (const [fieldName, rawFieldSpec] of Object.entries(objectPlans)) {
|
|
65
|
+
if (fieldName === "__assertStep") {
|
|
66
|
+
(0, utils_js_1.exportNameHint)(rawFieldSpec, `${typeName}_assertStep`);
|
|
67
|
+
config.extensions.grafast = { assertStep: rawFieldSpec };
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
else if (fieldName.startsWith("__")) {
|
|
71
|
+
throw new Error(`Unsupported field name '${fieldName}'; perhaps you meant '__assertStep'?`);
|
|
72
|
+
}
|
|
73
|
+
const fieldSpec = rawFieldSpec;
|
|
74
|
+
const field = rawFields[fieldName];
|
|
75
|
+
if (!field) {
|
|
76
|
+
console.warn(`'plans' specified configuration for object type '${typeName}' field '${fieldName}', but that field was not present in the type`);
|
|
77
|
+
continue;
|
|
78
|
+
}
|
|
79
|
+
if ("args" in fieldSpec &&
|
|
80
|
+
typeof fieldSpec.args === "object" &&
|
|
81
|
+
fieldSpec.args != null) {
|
|
82
|
+
for (const [argName, _argSpec] of Object.entries(fieldSpec.args)) {
|
|
83
|
+
const arg = field.args?.[argName];
|
|
84
|
+
if (!arg) {
|
|
85
|
+
console.warn(`'plans' specified configuration for object type '${typeName}' field '${fieldName}' arg '${argName}', but that arg was not present on the field`);
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
60
90
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
91
|
+
}
|
|
92
|
+
config.interfaces = function () {
|
|
93
|
+
return rawInterfaces.map((t) => mapType(t));
|
|
94
|
+
};
|
|
95
|
+
config.fields = function () {
|
|
96
|
+
const fields = Object.create(null);
|
|
97
|
+
for (const [fieldName, rawFieldSpec] of Object.entries(rawFields)) {
|
|
98
|
+
if (fieldName.startsWith("__")) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const fieldSpec = objectPlans && Object.hasOwn(objectPlans, fieldName)
|
|
102
|
+
? objectPlans[fieldName]
|
|
103
|
+
: undefined;
|
|
104
|
+
const fieldConfig = {
|
|
105
|
+
...rawFieldSpec,
|
|
106
|
+
type: mapType(rawFieldSpec.type),
|
|
107
|
+
};
|
|
108
|
+
fields[fieldName] = fieldConfig;
|
|
109
|
+
if (fieldConfig.args) {
|
|
110
|
+
for (const [_argName, arg] of Object.entries(fieldConfig.args)) {
|
|
111
|
+
arg.type = mapType(arg.type);
|
|
67
112
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
113
|
+
}
|
|
114
|
+
if (fieldSpec) {
|
|
115
|
+
if (typeof fieldSpec === "function") {
|
|
116
|
+
(0, utils_js_1.exportNameHint)(fieldSpec, `${typeName}_${fieldName}_plan`);
|
|
117
|
+
// it's a plan
|
|
118
|
+
fieldConfig.extensions.grafast = {
|
|
119
|
+
plan: fieldSpec,
|
|
120
|
+
};
|
|
71
121
|
}
|
|
72
122
|
else {
|
|
123
|
+
// it's a spec
|
|
73
124
|
const grafastExtensions = Object.create(null);
|
|
74
|
-
|
|
75
|
-
|
|
125
|
+
fieldConfig.extensions.grafast = grafastExtensions;
|
|
126
|
+
if (typeof fieldSpec.resolve === "function") {
|
|
127
|
+
(0, utils_js_1.exportNameHint)(fieldSpec.resolve, `${typeName}_${fieldName}_resolve`);
|
|
128
|
+
fieldConfig.resolve = fieldSpec.resolve;
|
|
129
|
+
}
|
|
130
|
+
if (typeof fieldSpec.subscribe === "function") {
|
|
131
|
+
(0, utils_js_1.exportNameHint)(fieldSpec.subscribe, `${typeName}_${fieldName}_subscribe`);
|
|
132
|
+
fieldConfig.subscribe = fieldSpec.subscribe;
|
|
133
|
+
}
|
|
134
|
+
if (typeof fieldSpec.plan === "function") {
|
|
135
|
+
(0, utils_js_1.exportNameHint)(fieldSpec.plan, `${typeName}_${fieldName}_plan`);
|
|
136
|
+
grafastExtensions.plan = fieldSpec.plan;
|
|
137
|
+
}
|
|
138
|
+
if (typeof fieldSpec.subscribePlan === "function") {
|
|
139
|
+
(0, utils_js_1.exportNameHint)(fieldSpec.subscribePlan, `${typeName}_${fieldName}_subscribePlan`);
|
|
140
|
+
grafastExtensions.subscribePlan = fieldSpec.subscribePlan;
|
|
141
|
+
}
|
|
142
|
+
if (fieldConfig.args) {
|
|
143
|
+
for (const [argName, arg] of Object.entries(fieldConfig.args)) {
|
|
144
|
+
const argSpec = fieldSpec.args?.[argName];
|
|
145
|
+
if (typeof argSpec === "function") {
|
|
146
|
+
const applyPlan = argSpec;
|
|
147
|
+
(0, utils_js_1.exportNameHint)(applyPlan, `${typeName}_${fieldName}_${argName}_applyPlan`);
|
|
148
|
+
Object.assign(arg.extensions, {
|
|
149
|
+
grafast: { applyPlan },
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
else if (typeof argSpec === "object" &&
|
|
153
|
+
argSpec !== null) {
|
|
154
|
+
const { extensions, applyPlan, applySubscribePlan } = argSpec;
|
|
155
|
+
if (extensions) {
|
|
156
|
+
Object.assign(arg.extensions, extensions);
|
|
157
|
+
}
|
|
158
|
+
if (applyPlan || applySubscribePlan) {
|
|
159
|
+
(0, utils_js_1.exportNameHint)(applyPlan, `${typeName}_${fieldName}_${argName}_applyPlan`);
|
|
160
|
+
(0, utils_js_1.exportNameHint)(applySubscribePlan, `${typeName}_${fieldName}_${argName}_applySubscribePlan`);
|
|
161
|
+
Object.assign(arg.extensions, {
|
|
162
|
+
grafast: {
|
|
163
|
+
applyPlan,
|
|
164
|
+
applySubscribePlan,
|
|
165
|
+
},
|
|
166
|
+
});
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
76
171
|
}
|
|
77
172
|
}
|
|
78
173
|
}
|
|
174
|
+
return fields;
|
|
175
|
+
};
|
|
176
|
+
return new graphql.GraphQLObjectType(config);
|
|
177
|
+
}
|
|
178
|
+
else if (isInputObjectType(astType)) {
|
|
179
|
+
const rawConfig = astType.toConfig();
|
|
180
|
+
const config = {
|
|
181
|
+
...rawConfig,
|
|
182
|
+
extensions: {
|
|
183
|
+
...rawConfig.extensions,
|
|
184
|
+
grafast: {
|
|
185
|
+
...rawConfig.extensions?.grafast,
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
const inputObjectPlans = plans[astType.name];
|
|
190
|
+
if (inputObjectPlans) {
|
|
191
|
+
for (const [fieldName, fieldSpec] of Object.entries(inputObjectPlans)) {
|
|
192
|
+
if (fieldName === "__baked") {
|
|
193
|
+
config.extensions.grafast.baked =
|
|
194
|
+
fieldSpec;
|
|
195
|
+
continue;
|
|
196
|
+
}
|
|
197
|
+
if (config.extensions?.grafast?.baked) {
|
|
198
|
+
(0, utils_js_1.exportNameHint)(config.extensions.grafast.baked, `${typeName}__baked`);
|
|
199
|
+
}
|
|
200
|
+
const field = rawConfig.fields[fieldName];
|
|
201
|
+
if (!field) {
|
|
202
|
+
console.warn(`'plans' specified configuration for input object type '${typeName}' field '${fieldName}', but that field was not present in the type`);
|
|
203
|
+
continue;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
79
206
|
}
|
|
207
|
+
const rawFields = rawConfig.fields;
|
|
208
|
+
config.fields = function () {
|
|
209
|
+
const fields = Object.create(null);
|
|
210
|
+
for (const [fieldName, rawFieldConfig] of Object.entries(rawFields)) {
|
|
211
|
+
const fieldSpec = inputObjectPlans && Object.hasOwn(inputObjectPlans, fieldName)
|
|
212
|
+
? inputObjectPlans[fieldName]
|
|
213
|
+
: undefined;
|
|
214
|
+
const fieldConfig = {
|
|
215
|
+
...rawFieldConfig,
|
|
216
|
+
type: mapType(rawFieldConfig.type),
|
|
217
|
+
};
|
|
218
|
+
fields[fieldName] = fieldConfig;
|
|
219
|
+
if (fieldSpec) {
|
|
220
|
+
const grafastExtensions = Object.create(null);
|
|
221
|
+
fieldConfig.extensions.grafast = grafastExtensions;
|
|
222
|
+
if (typeof fieldSpec === "function") {
|
|
223
|
+
(0, utils_js_1.exportNameHint)(fieldSpec, `${typeName}_${fieldName}_apply`);
|
|
224
|
+
grafastExtensions.apply = fieldSpec;
|
|
225
|
+
}
|
|
226
|
+
else {
|
|
227
|
+
const { apply, extensions } = fieldSpec;
|
|
228
|
+
if (extensions) {
|
|
229
|
+
Object.assign(fieldConfig.extensions, extensions);
|
|
230
|
+
}
|
|
231
|
+
if (apply) {
|
|
232
|
+
(0, utils_js_1.exportNameHint)(fieldSpec.apply, `${typeName}_${fieldName}_apply`);
|
|
233
|
+
Object.assign(grafastExtensions, { apply });
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return fields;
|
|
239
|
+
};
|
|
240
|
+
return new graphql.GraphQLInputObjectType(config);
|
|
80
241
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
242
|
+
else if (isInterfaceType(astType)) {
|
|
243
|
+
const rawConfig = astType.toConfig();
|
|
244
|
+
const config = {
|
|
245
|
+
...rawConfig,
|
|
246
|
+
};
|
|
247
|
+
const rawFields = rawConfig.fields;
|
|
248
|
+
config.fields = function () {
|
|
249
|
+
const fields = Object.create(null);
|
|
250
|
+
for (const [fieldName, rawFieldSpec] of Object.entries(rawFields)) {
|
|
251
|
+
const fieldConfig = {
|
|
252
|
+
...rawFieldSpec,
|
|
253
|
+
type: mapType(rawFieldSpec.type),
|
|
254
|
+
};
|
|
255
|
+
fields[fieldName] = fieldConfig;
|
|
256
|
+
if (fieldConfig.args) {
|
|
257
|
+
for (const [_argName, arg] of Object.entries(fieldConfig.args)) {
|
|
258
|
+
arg.type = mapType(arg.type);
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
return fields;
|
|
263
|
+
};
|
|
264
|
+
const rawInterfaces = rawConfig.interfaces;
|
|
265
|
+
config.interfaces = function () {
|
|
266
|
+
return rawInterfaces.map((t) => mapType(t));
|
|
267
|
+
};
|
|
268
|
+
const polyPlans = plans[astType.name];
|
|
269
|
+
if (polyPlans?.__resolveType) {
|
|
270
|
+
(0, utils_js_1.exportNameHint)(polyPlans.__resolveType, `${typeName}_resolveType`);
|
|
271
|
+
config.resolveType = polyPlans.__resolveType;
|
|
272
|
+
}
|
|
273
|
+
return new graphql.GraphQLInterfaceType(config);
|
|
85
274
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
275
|
+
else if (isUnionType(astType)) {
|
|
276
|
+
const rawConfig = astType.toConfig();
|
|
277
|
+
const config = {
|
|
278
|
+
...rawConfig,
|
|
279
|
+
};
|
|
280
|
+
const rawTypes = rawConfig.types;
|
|
281
|
+
config.types = function () {
|
|
282
|
+
return rawTypes.map((t) => mapType(t));
|
|
283
|
+
};
|
|
284
|
+
const polyPlans = plans[astType.name];
|
|
285
|
+
if (polyPlans?.__resolveType) {
|
|
286
|
+
(0, utils_js_1.exportNameHint)(polyPlans.__resolveType, `${typeName}_resolveType`);
|
|
287
|
+
config.resolveType = polyPlans.__resolveType;
|
|
93
288
|
}
|
|
94
|
-
|
|
95
|
-
|
|
289
|
+
return new graphql.GraphQLUnionType(config);
|
|
290
|
+
}
|
|
291
|
+
else if (isScalarType(astType)) {
|
|
292
|
+
const rawConfig = astType.toConfig();
|
|
293
|
+
const config = {
|
|
294
|
+
...rawConfig,
|
|
295
|
+
extensions: {
|
|
296
|
+
...rawConfig.extensions,
|
|
297
|
+
},
|
|
298
|
+
};
|
|
299
|
+
const scalarPlans = plans[astType.name];
|
|
300
|
+
if (typeof scalarPlans?.serialize === "function") {
|
|
301
|
+
(0, utils_js_1.exportNameHint)(scalarPlans.serialize, `${typeName}_serialize`);
|
|
302
|
+
config.serialize = scalarPlans.serialize;
|
|
96
303
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
field.extensions.grafast = grafastExtensions;
|
|
101
|
-
Object.assign(grafastExtensions, fieldSpec);
|
|
304
|
+
if (typeof scalarPlans?.parseValue === "function") {
|
|
305
|
+
(0, utils_js_1.exportNameHint)(scalarPlans.parseValue, `${typeName}_parseValue`);
|
|
306
|
+
config.parseValue = scalarPlans.parseValue;
|
|
102
307
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
if (typeof spec !== "object" || !spec) {
|
|
107
|
-
throw new Error(`Invalid interface/union config for '${typeName}'`);
|
|
108
|
-
}
|
|
109
|
-
const polySpec = spec;
|
|
110
|
-
if (polySpec.__resolveType) {
|
|
111
|
-
type.resolveType = polySpec.__resolveType;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
else if (isScalarType(type)) {
|
|
115
|
-
if (typeof spec !== "object" || !spec) {
|
|
116
|
-
throw new Error(`Invalid scalar config for '${typeName}'`);
|
|
117
|
-
}
|
|
118
|
-
const scalarSpec = spec;
|
|
119
|
-
if (typeof scalarSpec.serialize === "function") {
|
|
120
|
-
type.serialize = scalarSpec.serialize;
|
|
121
|
-
}
|
|
122
|
-
if (typeof scalarSpec.parseValue === "function") {
|
|
123
|
-
type.parseValue = scalarSpec.parseValue;
|
|
124
|
-
}
|
|
125
|
-
if (typeof scalarSpec.parseLiteral === "function") {
|
|
126
|
-
type.parseLiteral = scalarSpec.parseLiteral;
|
|
127
|
-
}
|
|
128
|
-
if (typeof scalarSpec.plan === "function") {
|
|
129
|
-
type.extensions.grafast = { plan: scalarSpec.plan };
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
else if (isEnumType(type)) {
|
|
133
|
-
if (typeof spec !== "object" || !spec) {
|
|
134
|
-
throw new Error(`Invalid enum config for '${typeName}'`);
|
|
135
|
-
}
|
|
136
|
-
const enumValues = type.getValues();
|
|
137
|
-
for (const [enumValueName, enumValueSpec] of Object.entries(spec)) {
|
|
138
|
-
const enumValue = enumValues.find((val) => val.name === enumValueName);
|
|
139
|
-
if (!enumValue) {
|
|
140
|
-
console.warn(`'plans' specified configuration for enum type '${typeName}' value '${enumValueName}', but that value was not present in the type`);
|
|
141
|
-
continue;
|
|
308
|
+
if (typeof scalarPlans?.parseLiteral === "function") {
|
|
309
|
+
(0, utils_js_1.exportNameHint)(scalarPlans.parseLiteral, `${typeName}_parseLiteral`);
|
|
310
|
+
config.parseLiteral = scalarPlans.parseLiteral;
|
|
142
311
|
}
|
|
143
|
-
if (typeof
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
applyPlan: enumValueSpec,
|
|
147
|
-
};
|
|
312
|
+
if (typeof scalarPlans?.plan === "function") {
|
|
313
|
+
(0, utils_js_1.exportNameHint)(scalarPlans.plan, `${typeName}_plan`);
|
|
314
|
+
config.extensions.grafast = { plan: scalarPlans.plan };
|
|
148
315
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
316
|
+
return new graphql.GraphQLScalarType(config);
|
|
317
|
+
}
|
|
318
|
+
else if (isEnumType(astType)) {
|
|
319
|
+
const rawConfig = astType.toConfig();
|
|
320
|
+
const config = {
|
|
321
|
+
...rawConfig,
|
|
322
|
+
};
|
|
323
|
+
const enumPlans = plans[astType.name];
|
|
324
|
+
const enumValues = config.values;
|
|
325
|
+
if (enumPlans) {
|
|
326
|
+
for (const [enumValueName, enumValueSpec] of Object.entries(enumPlans)) {
|
|
327
|
+
const enumValue = enumValues[enumValueName];
|
|
328
|
+
if (!enumValue) {
|
|
329
|
+
console.warn(`'plans' specified configuration for enum type '${typeName}' value '${enumValueName}', but that value was not present in the type`);
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
if (typeof enumValueSpec === "function") {
|
|
333
|
+
(0, utils_js_1.exportNameHint)(enumValueSpec, `${typeName}_${enumValueName}_apply`);
|
|
334
|
+
// It's a plan
|
|
335
|
+
if (!enumValue.extensions) {
|
|
336
|
+
enumValue.extensions = Object.create(null);
|
|
337
|
+
}
|
|
338
|
+
enumValue.extensions.grafast = {
|
|
339
|
+
apply: enumValueSpec,
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
else if (typeof enumValueSpec === "object" &&
|
|
343
|
+
enumValueSpec != null) {
|
|
344
|
+
// It's a full spec
|
|
345
|
+
if (enumValueSpec.extensions) {
|
|
346
|
+
(0, utils_js_1.exportNameHint)(enumValueSpec.extensions, `${typeName}_${enumValueName}_extensions`);
|
|
347
|
+
Object.assign(enumValue.extensions, enumValueSpec.extensions);
|
|
348
|
+
}
|
|
349
|
+
if (enumValueSpec.apply) {
|
|
350
|
+
(0, utils_js_1.exportNameHint)(enumValueSpec.apply, `${typeName}_${enumValueName}_apply`);
|
|
351
|
+
enumValue.extensions.grafast = {
|
|
352
|
+
apply: enumValueSpec.apply,
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
if ("value" in enumValueSpec) {
|
|
356
|
+
enumValue.value = enumValueSpec.value;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
else {
|
|
360
|
+
// It must be the value
|
|
361
|
+
enumValue.value = enumValueSpec;
|
|
362
|
+
}
|
|
158
363
|
}
|
|
159
364
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
365
|
+
return new graphql.GraphQLEnumType(config);
|
|
366
|
+
}
|
|
367
|
+
else {
|
|
368
|
+
const never = astType;
|
|
369
|
+
throw new Error(`Unhandled type ${never}`);
|
|
370
|
+
}
|
|
371
|
+
})();
|
|
372
|
+
typeByName.set(typeName, replacementType);
|
|
373
|
+
return replacementType;
|
|
374
|
+
});
|
|
375
|
+
if (schemaConfig.query) {
|
|
376
|
+
schemaConfig.query = mapType(schemaConfig.query);
|
|
377
|
+
}
|
|
378
|
+
if (schemaConfig.mutation) {
|
|
379
|
+
schemaConfig.mutation = mapType(schemaConfig.mutation);
|
|
380
|
+
}
|
|
381
|
+
if (schemaConfig.subscription) {
|
|
382
|
+
schemaConfig.subscription = mapType(schemaConfig.subscription);
|
|
383
|
+
}
|
|
384
|
+
if (schemaConfig.directives) {
|
|
385
|
+
for (const directiveConfig of schemaConfig.directives) {
|
|
386
|
+
for (const argConfig of directiveConfig.args) {
|
|
387
|
+
argConfig.type = mapType(argConfig.type);
|
|
164
388
|
}
|
|
165
|
-
}
|
|
166
|
-
else {
|
|
167
|
-
const never = type;
|
|
168
|
-
console.error(`Unhandled type ${never}`);
|
|
169
389
|
}
|
|
170
390
|
}
|
|
391
|
+
const schema = new graphql_1.GraphQLSchema(schemaConfig);
|
|
171
392
|
return schema;
|
|
172
393
|
}
|
|
173
|
-
exports.makeGrafastSchema = makeGrafastSchema;
|
|
174
394
|
//# sourceMappingURL=makeGrafastSchema.js.map
|
package/dist/mermaid.d.ts
CHANGED
|
@@ -6,23 +6,6 @@ import type { GrafastPlanJSON } from "./interfaces";
|
|
|
6
6
|
* Generated by mokole.com/palette.html; re-ordered by Jem
|
|
7
7
|
*/
|
|
8
8
|
export declare const COLORS: string[];
|
|
9
|
-
/**
|
|
10
|
-
* Given a string, escapes the string so that it can be embedded as the description of a node in a mermaid chart.
|
|
11
|
-
*
|
|
12
|
-
* 1. If it's already safe, returns it verbatim
|
|
13
|
-
* 2. If it contains disallowed characters, escape them by replacing them with similar-looking characters,
|
|
14
|
-
* 3. Wrap the string in quote marks.
|
|
15
|
-
*
|
|
16
|
-
* @remarks
|
|
17
|
-
*
|
|
18
|
-
* NOTE: rather than doing literal escapes, we replace with lookalike characters because:
|
|
19
|
-
*
|
|
20
|
-
* 1. Mermaid has a bug when calculating the width of the node that doesn't respect escapes,
|
|
21
|
-
* 2. It's easier to read the raw mermaid markup with substitutes rather than messy escapes.
|
|
22
|
-
*
|
|
23
|
-
* @internal
|
|
24
|
-
*/
|
|
25
|
-
export declare const mermaidEscape: (str: string) => string;
|
|
26
9
|
export interface PrintPlanGraphOptions {
|
|
27
10
|
printPathRelations?: boolean;
|
|
28
11
|
includePaths?: boolean;
|