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.
Files changed (157) hide show
  1. package/README.md +2 -3
  2. package/dist/args.d.ts +4 -7
  3. package/dist/args.js +53 -38
  4. package/dist/assert.js +2 -3
  5. package/dist/bucket.d.ts +1 -89
  6. package/dist/config.d.ts +0 -17
  7. package/dist/config.js +1 -95
  8. package/dist/constraints.d.ts +15 -1
  9. package/dist/constraints.js +41 -3
  10. package/dist/deferred.js +1 -2
  11. package/dist/dev.d.ts +1 -4
  12. package/dist/dev.js +18 -3
  13. package/dist/engine/LayerPlan.d.ts +21 -111
  14. package/dist/engine/LayerPlan.js +196 -78
  15. package/dist/engine/OperationPlan.d.ts +30 -104
  16. package/dist/engine/OperationPlan.js +763 -471
  17. package/dist/engine/OutputPlan.d.ts +9 -20
  18. package/dist/engine/OutputPlan.js +432 -444
  19. package/dist/engine/StepTracker.d.ts +1 -95
  20. package/dist/engine/StepTracker.js +94 -20
  21. package/dist/engine/executeBucket.d.ts +5 -7
  22. package/dist/engine/executeBucket.js +646 -244
  23. package/dist/engine/executeOutputPlan.d.ts +0 -53
  24. package/dist/engine/executeOutputPlan.js +7 -2
  25. package/dist/engine/lib/defaultPlanResolver.d.ts +6 -0
  26. package/dist/engine/lib/defaultPlanResolver.js +11 -0
  27. package/dist/engine/lib/withGlobalLayerPlan.d.ts +2 -0
  28. package/dist/engine/lib/withGlobalLayerPlan.js +7 -4
  29. package/dist/engine/lock.d.ts +4 -0
  30. package/dist/engine/lock.js +82 -0
  31. package/dist/envelop.js +5 -4
  32. package/dist/error.d.ts +18 -49
  33. package/dist/error.js +50 -39
  34. package/dist/establishOperationPlan.js +57 -42
  35. package/dist/execute.d.ts +5 -4
  36. package/dist/execute.js +31 -15
  37. package/dist/exportAs.d.ts +1 -18
  38. package/dist/exportAs.js +2 -3
  39. package/dist/global.js +2 -3
  40. package/dist/grafastGraphql.d.ts +6 -1
  41. package/dist/grafastGraphql.js +35 -16
  42. package/dist/grafastPrint.d.ts +3 -0
  43. package/dist/grafastPrint.js +67 -6
  44. package/dist/graphqlCollectFields.d.ts +7 -34
  45. package/dist/graphqlCollectFields.js +24 -13
  46. package/dist/graphqlMergeSelectionSets.js +1 -2
  47. package/dist/index.d.ts +44 -29
  48. package/dist/index.js +91 -18
  49. package/dist/input.d.ts +1 -9
  50. package/dist/input.js +75 -28
  51. package/dist/inspect.d.ts +9 -3
  52. package/dist/inspect.js +3 -3
  53. package/dist/interfaces.d.ts +238 -93
  54. package/dist/interfaces.js +20 -3
  55. package/dist/makeGrafastSchema.d.ts +21 -9
  56. package/dist/makeGrafastSchema.js +353 -133
  57. package/dist/mermaid.d.ts +0 -17
  58. package/dist/mermaid.js +131 -19
  59. package/dist/middleware.d.ts +7 -0
  60. package/dist/middleware.js +24 -0
  61. package/dist/multistep.d.ts +19 -0
  62. package/dist/multistep.js +54 -0
  63. package/dist/operationPlan-input.d.ts +5 -4
  64. package/dist/operationPlan-input.js +140 -368
  65. package/dist/planJSONInterfaces.d.ts +12 -2
  66. package/dist/polymorphic.js +4 -5
  67. package/dist/prepare.d.ts +1 -7
  68. package/dist/prepare.js +100 -74
  69. package/dist/step.d.ts +118 -172
  70. package/dist/step.js +262 -183
  71. package/dist/steps/__flag.d.ts +65 -0
  72. package/dist/steps/__flag.js +261 -0
  73. package/dist/steps/__inputDefault.d.ts +14 -0
  74. package/dist/steps/__inputDefault.js +48 -0
  75. package/dist/steps/__inputDynamicScalar.d.ts +4 -6
  76. package/dist/steps/__inputDynamicScalar.js +4 -2
  77. package/dist/steps/__inputList.d.ts +5 -9
  78. package/dist/steps/__inputList.js +4 -1
  79. package/dist/steps/__inputObject.d.ts +7 -11
  80. package/dist/steps/__inputObject.js +49 -3
  81. package/dist/steps/__inputStaticLeaf.d.ts +2 -4
  82. package/dist/steps/__inputStaticLeaf.js +3 -1
  83. package/dist/steps/__item.d.ts +10 -12
  84. package/dist/steps/__item.js +8 -2
  85. package/dist/steps/__trackedValue.d.ts +7 -55
  86. package/dist/steps/__trackedValue.js +69 -8
  87. package/dist/steps/__value.d.ts +5 -4
  88. package/dist/steps/__value.js +5 -4
  89. package/dist/steps/access.d.ts +10 -10
  90. package/dist/steps/access.js +50 -17
  91. package/dist/steps/applyInput.d.ts +44 -0
  92. package/dist/steps/applyInput.js +206 -0
  93. package/dist/steps/applyTransforms.d.ts +2 -25
  94. package/dist/steps/applyTransforms.js +53 -31
  95. package/dist/steps/bakedInput.d.ts +23 -0
  96. package/dist/steps/bakedInput.js +90 -0
  97. package/dist/steps/condition.d.ts +31 -0
  98. package/dist/steps/condition.js +94 -0
  99. package/dist/steps/connection.d.ts +56 -42
  100. package/dist/steps/connection.js +97 -44
  101. package/dist/steps/constant.d.ts +7 -7
  102. package/dist/steps/constant.js +86 -7
  103. package/dist/steps/each.d.ts +3 -3
  104. package/dist/steps/each.js +2 -3
  105. package/dist/steps/error.d.ts +4 -4
  106. package/dist/steps/error.js +7 -6
  107. package/dist/steps/filter.d.ts +3 -2
  108. package/dist/steps/filter.js +1 -2
  109. package/dist/steps/first.d.ts +10 -9
  110. package/dist/steps/first.js +9 -13
  111. package/dist/steps/graphqlResolver.d.ts +3 -76
  112. package/dist/steps/graphqlResolver.js +89 -72
  113. package/dist/steps/groupBy.d.ts +3 -2
  114. package/dist/steps/groupBy.js +1 -2
  115. package/dist/steps/index.d.ts +12 -3
  116. package/dist/steps/index.js +48 -6
  117. package/dist/steps/lambda.d.ts +9 -9
  118. package/dist/steps/lambda.js +18 -9
  119. package/dist/steps/last.d.ts +9 -8
  120. package/dist/steps/last.js +7 -6
  121. package/dist/steps/list.d.ts +20 -9
  122. package/dist/steps/list.js +56 -13
  123. package/dist/steps/listTransform.d.ts +18 -22
  124. package/dist/steps/listTransform.js +58 -27
  125. package/dist/steps/listen.d.ts +6 -11
  126. package/dist/steps/listen.js +14 -16
  127. package/dist/steps/load.d.ts +42 -33
  128. package/dist/steps/load.js +60 -27
  129. package/dist/steps/node.d.ts +17 -10
  130. package/dist/steps/node.js +18 -6
  131. package/dist/steps/object.d.ts +33 -27
  132. package/dist/steps/object.js +53 -32
  133. package/dist/steps/partitionByIndex.d.ts +3 -2
  134. package/dist/steps/partitionByIndex.js +1 -2
  135. package/dist/steps/polymorphicBranch.d.ts +27 -0
  136. package/dist/steps/polymorphicBranch.js +62 -0
  137. package/dist/steps/proxy.d.ts +11 -12
  138. package/dist/steps/proxy.js +8 -5
  139. package/dist/steps/remapKeys.d.ts +10 -10
  140. package/dist/steps/remapKeys.js +14 -7
  141. package/dist/steps/reverse.d.ts +8 -8
  142. package/dist/steps/reverse.js +10 -7
  143. package/dist/steps/setter.d.ts +9 -18
  144. package/dist/steps/setter.js +24 -14
  145. package/dist/steps/sideEffect.d.ts +28 -0
  146. package/dist/steps/sideEffect.js +44 -0
  147. package/dist/stringifyPayload.js +1 -2
  148. package/dist/stripAnsi.js +2 -2
  149. package/dist/subscribe.d.ts +7 -1
  150. package/dist/subscribe.js +24 -9
  151. package/dist/thereCanBeOnlyOne.js +1 -1
  152. package/dist/timeSource.d.ts +0 -1
  153. package/dist/utils.d.ts +56 -55
  154. package/dist/utils.js +179 -59
  155. package/dist/version.d.ts +1 -1
  156. package/dist/version.js +1 -1
  157. package/package.json +5 -8
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeGrafastSchema = void 0;
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 schema = buildASTSchema(parse(typeDefs), {
15
+ const astSchema = buildASTSchema(parse(typeDefs), {
14
16
  enableDeferStream,
15
17
  });
16
- // Now add the plans/etc to the schema
17
- for (const [typeName, spec] of Object.entries(plans)) {
18
- const type = schema.getType(typeName);
19
- if (!type) {
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
- if (isObjectType(type)) {
24
- if (typeof spec !== "object" || !spec) {
25
- throw new Error(`Invalid object config for '${typeName}'`);
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
- const objSpec = spec;
28
- const fields = type.getFields();
29
- for (const [fieldName, fieldSpec] of Object.entries(objSpec)) {
30
- if (fieldName === "__assertStep") {
31
- type.extensions.grafast = { assertStep: fieldSpec };
32
- continue;
33
- }
34
- const field = fields[fieldName];
35
- if (!field) {
36
- console.warn(`'plans' specified configuration for object type '${typeName}' field '${fieldName}', but that field was not present in the type`);
37
- continue;
38
- }
39
- if (typeof fieldSpec === "function") {
40
- // it's a plan
41
- field.extensions.grafast = {
42
- plan: fieldSpec,
43
- };
44
- }
45
- else {
46
- // it's a spec
47
- const grafastExtensions = Object.create(null);
48
- field.extensions.grafast = grafastExtensions;
49
- if (typeof fieldSpec.resolve === "function") {
50
- field.resolve = fieldSpec.resolve;
51
- }
52
- if (typeof fieldSpec.subscribe === "function") {
53
- field.subscribe = fieldSpec.subscribe;
54
- }
55
- if (typeof fieldSpec.plan === "function") {
56
- grafastExtensions.plan = fieldSpec.plan;
57
- }
58
- if (typeof fieldSpec.subscribePlan === "function") {
59
- grafastExtensions.subscribePlan = fieldSpec.subscribePlan;
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
- if (typeof fieldSpec.args === "object" && fieldSpec.args != null) {
62
- for (const [argName, argSpec] of Object.entries(fieldSpec.args)) {
63
- const arg = field.args.find((arg) => arg.name === argName);
64
- if (!arg) {
65
- console.warn(`'plans' specified configuration for object type '${typeName}' field '${fieldName}' arg '${argName}', but that arg was not present in the type`);
66
- continue;
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
- if (typeof argSpec === "function") {
69
- // Invalid
70
- throw new Error(`Invalid configuration for plans.${typeName}.${fieldName}.args.${argName} - saw a function, but expected an object with 'inputPlan' (optional) and 'applyPlan' (optional) plans`);
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
- arg.extensions.grafast = grafastExtensions;
75
- Object.assign(grafastExtensions, argSpec);
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
- else if (isInputObjectType(type)) {
83
- if (typeof spec !== "object" || !spec) {
84
- throw new Error(`Invalid input object config for '${typeName}'`);
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
- const inputSpec = spec;
87
- const fields = type.getFields();
88
- for (const [fieldName, fieldSpec] of Object.entries(inputSpec)) {
89
- const field = fields[fieldName];
90
- if (!field) {
91
- console.warn(`'plans' specified configuration for input object type '${typeName}' field '${fieldName}', but that field was not present in the type`);
92
- continue;
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
- if (typeof fieldSpec === "function") {
95
- throw new Error(`Expected input object type '${typeName}' field '${fieldName}' to be an object, but found a function. We don't know if this should be the 'inputPlan' or 'applyPlan' - please supply an object.`);
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
- else {
98
- // it's a spec
99
- const grafastExtensions = Object.create(null);
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
- else if (isInterfaceType(type) || isUnionType(type)) {
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 enumValueSpec === "function") {
144
- // It's a plan
145
- enumValue.extensions.grafast = {
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
- else if (typeof enumValueSpec === "object" && enumValueSpec != null) {
150
- // It's a full spec
151
- if (enumValueSpec.applyPlan) {
152
- enumValue.extensions.grafast = {
153
- applyPlan: enumValueSpec.applyPlan,
154
- };
155
- }
156
- if ("value" in enumValueSpec) {
157
- enumValue.value = enumValueSpec.value;
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
- else {
161
- // It must be the value
162
- enumValue.value = enumValueSpec;
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;