@omnigraph/json-schema 0.97.0 → 0.98.0-alpha-20231115135952-ce851df6a
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/cjs/addExecutionLogicToComposer.js +16 -3
- package/cjs/directives.js +54 -1
- package/cjs/getComposerFromJSONSchema.js +41 -1
- package/cjs/getGraphQLSchemaFromDereferencedJSONSchema.js +3 -3
- package/cjs/getUnionTypeComposers.js +7 -3
- package/esm/addExecutionLogicToComposer.js +16 -3
- package/esm/directives.js +54 -1
- package/esm/getComposerFromJSONSchema.js +41 -1
- package/esm/getGraphQLSchemaFromDereferencedJSONSchema.js +3 -3
- package/esm/getUnionTypeComposers.js +7 -3
- package/package.json +1 -1
- package/typings/addExecutionLogicToComposer.d.cts +1 -1
- package/typings/addExecutionLogicToComposer.d.ts +1 -1
- package/typings/getComposerFromJSONSchema.d.cts +1 -1
- package/typings/getComposerFromJSONSchema.d.ts +1 -1
- package/typings/getGraphQLSchemaFromDereferencedJSONSchema.d.cts +1 -1
- package/typings/getGraphQLSchemaFromDereferencedJSONSchema.d.ts +1 -1
- package/typings/getUnionTypeComposers.d.cts +3 -2
- package/typings/getUnionTypeComposers.d.ts +3 -2
|
@@ -17,10 +17,10 @@ const responseMetadataType = new graphql_1.GraphQLObjectType({
|
|
|
17
17
|
body: { type: graphql_compose_1.GraphQLJSON },
|
|
18
18
|
},
|
|
19
19
|
});
|
|
20
|
-
async function addExecutionDirectivesToComposer(
|
|
20
|
+
async function addExecutionDirectivesToComposer(subgraphName, { schemaComposer, logger, operations, operationHeaders, endpoint, queryParams, queryStringOptions, }) {
|
|
21
21
|
schemaComposer.addDirective(directives_js_1.GlobalOptionsDirective);
|
|
22
22
|
schemaComposer.Query.setDirectiveByName('globalOptions', JSON.parse(JSON.stringify({
|
|
23
|
-
|
|
23
|
+
subgraph: subgraphName,
|
|
24
24
|
endpoint,
|
|
25
25
|
operationHeaders,
|
|
26
26
|
queryStringOptions,
|
|
@@ -39,6 +39,7 @@ async function addExecutionDirectivesToComposer(name, { schemaComposer, logger,
|
|
|
39
39
|
field.directives.push({
|
|
40
40
|
name: 'pubsubOperation',
|
|
41
41
|
args: {
|
|
42
|
+
subgraph: subgraphName,
|
|
42
43
|
pubsubTopic: operationConfig.pubsubTopic,
|
|
43
44
|
},
|
|
44
45
|
});
|
|
@@ -60,6 +61,7 @@ ${operationConfig.description || ''}
|
|
|
60
61
|
field.directives.push({
|
|
61
62
|
name: 'httpOperation',
|
|
62
63
|
args: JSON.parse(JSON.stringify({
|
|
64
|
+
subgraph: subgraphName,
|
|
63
65
|
path: operationConfig.path,
|
|
64
66
|
operationSpecificHeaders: operationConfig.headers,
|
|
65
67
|
httpMethod,
|
|
@@ -81,6 +83,7 @@ ${operationConfig.description || ''}
|
|
|
81
83
|
linkResolverMapDirective = {
|
|
82
84
|
name: 'linkResolver',
|
|
83
85
|
args: {
|
|
86
|
+
subgraph: subgraphName,
|
|
84
87
|
linkResolverMap: {},
|
|
85
88
|
},
|
|
86
89
|
};
|
|
@@ -101,7 +104,7 @@ ${operationConfig.description || ''}
|
|
|
101
104
|
catch { }
|
|
102
105
|
}
|
|
103
106
|
if (!targetField) {
|
|
104
|
-
logger.debug(`Field ${linkObj.fieldName} not found in ${
|
|
107
|
+
logger.debug(`Field ${linkObj.fieldName} not found in ${subgraphName} for link ${linkName}`);
|
|
105
108
|
}
|
|
106
109
|
linkResolverFieldMap[linkName] = {
|
|
107
110
|
linkObjArgs: linkObj.args,
|
|
@@ -115,6 +118,7 @@ ${operationConfig.description || ''}
|
|
|
115
118
|
{
|
|
116
119
|
name: 'link',
|
|
117
120
|
args: {
|
|
121
|
+
subgraph: subgraphName,
|
|
118
122
|
defaultRootType: rootTypeName,
|
|
119
123
|
defaultField: operationConfig.field,
|
|
120
124
|
},
|
|
@@ -140,6 +144,9 @@ ${operationConfig.description || ''}
|
|
|
140
144
|
directives: [
|
|
141
145
|
{
|
|
142
146
|
name: 'responseMetadata',
|
|
147
|
+
args: {
|
|
148
|
+
subgraph: subgraphName,
|
|
149
|
+
},
|
|
143
150
|
},
|
|
144
151
|
],
|
|
145
152
|
},
|
|
@@ -172,6 +179,9 @@ ${operationConfig.description || ''}
|
|
|
172
179
|
directives: [
|
|
173
180
|
{
|
|
174
181
|
name: 'resolveRoot',
|
|
182
|
+
args: {
|
|
183
|
+
subgraph: subgraphName,
|
|
184
|
+
},
|
|
175
185
|
},
|
|
176
186
|
],
|
|
177
187
|
},
|
|
@@ -189,6 +199,9 @@ ${operationConfig.description || ''}
|
|
|
189
199
|
directives: [
|
|
190
200
|
{
|
|
191
201
|
name: 'responseMetadata',
|
|
202
|
+
args: {
|
|
203
|
+
subgraph: subgraphName,
|
|
204
|
+
},
|
|
192
205
|
},
|
|
193
206
|
],
|
|
194
207
|
},
|
package/cjs/directives.js
CHANGED
|
@@ -13,6 +13,9 @@ exports.LengthDirective = new graphql_1.GraphQLDirective({
|
|
|
13
13
|
name: 'length',
|
|
14
14
|
locations: [graphql_1.DirectiveLocation.SCALAR],
|
|
15
15
|
args: {
|
|
16
|
+
subgraph: {
|
|
17
|
+
type: graphql_1.GraphQLString,
|
|
18
|
+
},
|
|
16
19
|
min: {
|
|
17
20
|
type: graphql_1.GraphQLInt,
|
|
18
21
|
},
|
|
@@ -48,6 +51,9 @@ exports.DiscriminatorDirective = new graphql_1.GraphQLDirective({
|
|
|
48
51
|
name: 'discriminator',
|
|
49
52
|
locations: [graphql_1.DirectiveLocation.INTERFACE, graphql_1.DirectiveLocation.UNION],
|
|
50
53
|
args: {
|
|
54
|
+
subgraph: {
|
|
55
|
+
type: graphql_1.GraphQLString,
|
|
56
|
+
},
|
|
51
57
|
field: {
|
|
52
58
|
type: graphql_1.GraphQLString,
|
|
53
59
|
},
|
|
@@ -63,6 +69,11 @@ exports.processDiscriminatorAnnotations = processDiscriminatorAnnotations;
|
|
|
63
69
|
exports.ResolveRootDirective = new graphql_1.GraphQLDirective({
|
|
64
70
|
name: 'resolveRoot',
|
|
65
71
|
locations: [graphql_1.DirectiveLocation.FIELD_DEFINITION],
|
|
72
|
+
args: {
|
|
73
|
+
subgraph: {
|
|
74
|
+
type: graphql_1.GraphQLString,
|
|
75
|
+
},
|
|
76
|
+
},
|
|
66
77
|
});
|
|
67
78
|
function rootResolver(root) {
|
|
68
79
|
return root;
|
|
@@ -79,6 +90,9 @@ exports.ResolveRootFieldDirective = new graphql_1.GraphQLDirective({
|
|
|
79
90
|
graphql_1.DirectiveLocation.INPUT_FIELD_DEFINITION,
|
|
80
91
|
],
|
|
81
92
|
args: {
|
|
93
|
+
subgraph: {
|
|
94
|
+
type: graphql_1.GraphQLString,
|
|
95
|
+
},
|
|
82
96
|
field: {
|
|
83
97
|
type: graphql_1.GraphQLString,
|
|
84
98
|
},
|
|
@@ -113,6 +127,9 @@ exports.RegExpDirective = new graphql_1.GraphQLDirective({
|
|
|
113
127
|
name: 'regexp',
|
|
114
128
|
locations: [graphql_1.DirectiveLocation.SCALAR],
|
|
115
129
|
args: {
|
|
130
|
+
subgraph: {
|
|
131
|
+
type: graphql_1.GraphQLString,
|
|
132
|
+
},
|
|
116
133
|
pattern: {
|
|
117
134
|
type: graphql_1.GraphQLString,
|
|
118
135
|
},
|
|
@@ -143,6 +160,9 @@ exports.PubSubOperationDirective = new graphql_1.GraphQLDirective({
|
|
|
143
160
|
name: 'pubsubOperation',
|
|
144
161
|
locations: [graphql_1.DirectiveLocation.FIELD_DEFINITION],
|
|
145
162
|
args: {
|
|
163
|
+
subgraph: {
|
|
164
|
+
type: graphql_1.GraphQLString,
|
|
165
|
+
},
|
|
146
166
|
pubsubTopic: {
|
|
147
167
|
type: graphql_1.GraphQLString,
|
|
148
168
|
},
|
|
@@ -176,6 +196,9 @@ exports.TypeScriptDirective = new graphql_1.GraphQLDirective({
|
|
|
176
196
|
name: 'typescript',
|
|
177
197
|
locations: [graphql_1.DirectiveLocation.SCALAR, graphql_1.DirectiveLocation.ENUM],
|
|
178
198
|
args: {
|
|
199
|
+
subgraph: {
|
|
200
|
+
type: graphql_1.GraphQLString,
|
|
201
|
+
},
|
|
179
202
|
type: {
|
|
180
203
|
type: graphql_1.GraphQLString,
|
|
181
204
|
},
|
|
@@ -233,6 +256,9 @@ exports.HTTPOperationDirective = new graphql_1.GraphQLDirective({
|
|
|
233
256
|
name: 'httpOperation',
|
|
234
257
|
locations: [graphql_1.DirectiveLocation.FIELD_DEFINITION],
|
|
235
258
|
args: {
|
|
259
|
+
subgraph: {
|
|
260
|
+
type: graphql_1.GraphQLString,
|
|
261
|
+
},
|
|
236
262
|
path: {
|
|
237
263
|
type: graphql_1.GraphQLString,
|
|
238
264
|
},
|
|
@@ -273,7 +299,7 @@ exports.GlobalOptionsDirective = new graphql_1.GraphQLDirective({
|
|
|
273
299
|
name: 'globalOptions',
|
|
274
300
|
locations: [graphql_1.DirectiveLocation.OBJECT],
|
|
275
301
|
args: {
|
|
276
|
-
|
|
302
|
+
subgraph: {
|
|
277
303
|
type: graphql_1.GraphQLString,
|
|
278
304
|
},
|
|
279
305
|
endpoint: {
|
|
@@ -293,6 +319,11 @@ exports.GlobalOptionsDirective = new graphql_1.GraphQLDirective({
|
|
|
293
319
|
exports.ResponseMetadataDirective = new graphql_1.GraphQLDirective({
|
|
294
320
|
name: 'responseMetadata',
|
|
295
321
|
locations: [graphql_1.DirectiveLocation.FIELD_DEFINITION],
|
|
322
|
+
args: {
|
|
323
|
+
subgraph: {
|
|
324
|
+
type: graphql_1.GraphQLString,
|
|
325
|
+
},
|
|
326
|
+
},
|
|
296
327
|
});
|
|
297
328
|
function processResponseMetadataAnnotations(field) {
|
|
298
329
|
field.resolve = function responseMetadataResolver(root) {
|
|
@@ -323,6 +354,9 @@ exports.LinkResolverDirective = new graphql_1.GraphQLDirective({
|
|
|
323
354
|
name: 'linkResolver',
|
|
324
355
|
locations: [graphql_1.DirectiveLocation.FIELD_DEFINITION],
|
|
325
356
|
args: {
|
|
357
|
+
subgraph: {
|
|
358
|
+
type: graphql_1.GraphQLString,
|
|
359
|
+
},
|
|
326
360
|
linkResolverMap: {
|
|
327
361
|
type: scalars_js_1.ObjMapScalar,
|
|
328
362
|
},
|
|
@@ -392,6 +426,11 @@ exports.processLinkFieldAnnotations = processLinkFieldAnnotations;
|
|
|
392
426
|
exports.DictionaryDirective = new graphql_1.GraphQLDirective({
|
|
393
427
|
name: 'dictionary',
|
|
394
428
|
locations: [graphql_1.DirectiveLocation.FIELD_DEFINITION],
|
|
429
|
+
args: {
|
|
430
|
+
subgraph: {
|
|
431
|
+
type: graphql_1.GraphQLString,
|
|
432
|
+
},
|
|
433
|
+
},
|
|
395
434
|
});
|
|
396
435
|
function processDictionaryDirective(fieldMap, field) {
|
|
397
436
|
field.resolve = root => {
|
|
@@ -412,6 +451,11 @@ exports.processDictionaryDirective = processDictionaryDirective;
|
|
|
412
451
|
exports.FlattenDirective = new graphql_1.GraphQLDirective({
|
|
413
452
|
name: 'flatten',
|
|
414
453
|
locations: [graphql_1.DirectiveLocation.FIELD_DEFINITION],
|
|
454
|
+
args: {
|
|
455
|
+
subgraph: {
|
|
456
|
+
type: graphql_1.GraphQLString,
|
|
457
|
+
},
|
|
458
|
+
},
|
|
415
459
|
});
|
|
416
460
|
function processFlattenAnnotations(field) {
|
|
417
461
|
if (!field.resolve || field.resolve.name === 'defaultFieldResolver') {
|
|
@@ -564,6 +608,9 @@ exports.StatusCodeTypeNameDirective = new graphql_1.GraphQLDirective({
|
|
|
564
608
|
locations: [graphql_1.DirectiveLocation.UNION],
|
|
565
609
|
isRepeatable: true,
|
|
566
610
|
args: {
|
|
611
|
+
subgraph: {
|
|
612
|
+
type: graphql_1.GraphQLString,
|
|
613
|
+
},
|
|
567
614
|
typeName: {
|
|
568
615
|
type: graphql_1.GraphQLString,
|
|
569
616
|
},
|
|
@@ -576,6 +623,9 @@ exports.EnumDirective = new graphql_1.GraphQLDirective({
|
|
|
576
623
|
name: 'enum',
|
|
577
624
|
locations: [graphql_1.DirectiveLocation.ENUM_VALUE],
|
|
578
625
|
args: {
|
|
626
|
+
subgraph: {
|
|
627
|
+
type: graphql_1.GraphQLString,
|
|
628
|
+
},
|
|
579
629
|
value: {
|
|
580
630
|
type: graphql_1.GraphQLString,
|
|
581
631
|
},
|
|
@@ -599,6 +649,9 @@ exports.ExampleDirective = new graphql_1.GraphQLDirective({
|
|
|
599
649
|
graphql_1.DirectiveLocation.SCALAR,
|
|
600
650
|
],
|
|
601
651
|
args: {
|
|
652
|
+
subgraph: {
|
|
653
|
+
type: graphql_1.GraphQLString,
|
|
654
|
+
},
|
|
602
655
|
value: {
|
|
603
656
|
type: scalars_js_1.ObjMapScalar,
|
|
604
657
|
},
|
|
@@ -12,7 +12,7 @@ const getJSONSchemaStringFormatScalarMap_js_1 = require("./getJSONSchemaStringFo
|
|
|
12
12
|
const getUnionTypeComposers_js_1 = require("./getUnionTypeComposers.js");
|
|
13
13
|
const getValidTypeName_js_1 = require("./getValidTypeName.js");
|
|
14
14
|
const scalars_js_1 = require("./scalars.js");
|
|
15
|
-
function getComposerFromJSONSchema(schema, logger) {
|
|
15
|
+
function getComposerFromJSONSchema(subgraphName, schema, logger) {
|
|
16
16
|
const schemaComposer = new graphql_compose_1.SchemaComposer();
|
|
17
17
|
const formatScalarMap = (0, getJSONSchemaStringFormatScalarMap_js_1.getJSONSchemaStringFormatScalarMap)();
|
|
18
18
|
const rootInputTypeNameComposerMap = {
|
|
@@ -115,12 +115,14 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
115
115
|
{
|
|
116
116
|
name: 'regexp',
|
|
117
117
|
args: {
|
|
118
|
+
subgraph: subgraphName,
|
|
118
119
|
pattern: subSchema.pattern,
|
|
119
120
|
},
|
|
120
121
|
},
|
|
121
122
|
{
|
|
122
123
|
name: 'typescript',
|
|
123
124
|
args: {
|
|
125
|
+
subgraph: subgraphName,
|
|
124
126
|
type: typeScriptType,
|
|
125
127
|
},
|
|
126
128
|
},
|
|
@@ -152,6 +154,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
152
154
|
{
|
|
153
155
|
name: 'enum',
|
|
154
156
|
args: {
|
|
157
|
+
subgraph: subgraphName,
|
|
155
158
|
value: JSON.stringify(subSchema.const),
|
|
156
159
|
},
|
|
157
160
|
},
|
|
@@ -162,12 +165,14 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
162
165
|
{
|
|
163
166
|
name: 'typescript',
|
|
164
167
|
args: {
|
|
168
|
+
subgraph: subgraphName,
|
|
165
169
|
type: JSON.stringify(subSchema.const),
|
|
166
170
|
},
|
|
167
171
|
},
|
|
168
172
|
{
|
|
169
173
|
name: 'example',
|
|
170
174
|
args: {
|
|
175
|
+
subgraph: subgraphName,
|
|
171
176
|
value: subSchema.const,
|
|
172
177
|
},
|
|
173
178
|
},
|
|
@@ -204,6 +209,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
204
209
|
directives.push({
|
|
205
210
|
name: 'enum',
|
|
206
211
|
args: {
|
|
212
|
+
subgraph: subgraphName,
|
|
207
213
|
value: JSON.stringify(enumValue),
|
|
208
214
|
},
|
|
209
215
|
});
|
|
@@ -220,6 +226,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
220
226
|
directives.push({
|
|
221
227
|
name: 'example',
|
|
222
228
|
args: {
|
|
229
|
+
subgraph: subgraphName,
|
|
223
230
|
value: example,
|
|
224
231
|
},
|
|
225
232
|
});
|
|
@@ -599,6 +606,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
599
606
|
{
|
|
600
607
|
name: 'length',
|
|
601
608
|
args: {
|
|
609
|
+
subgraph: subgraphName,
|
|
602
610
|
min: subSchema.minLength,
|
|
603
611
|
max: subSchema.maxLength,
|
|
604
612
|
},
|
|
@@ -670,6 +678,9 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
670
678
|
directives: [
|
|
671
679
|
{
|
|
672
680
|
name: 'oneOf',
|
|
681
|
+
args: {
|
|
682
|
+
subgraph: subgraphName,
|
|
683
|
+
},
|
|
673
684
|
},
|
|
674
685
|
],
|
|
675
686
|
});
|
|
@@ -733,6 +744,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
733
744
|
config.directives.push({
|
|
734
745
|
name: 'example',
|
|
735
746
|
args: {
|
|
747
|
+
subgraph: subgraphName,
|
|
736
748
|
value: example,
|
|
737
749
|
},
|
|
738
750
|
});
|
|
@@ -748,6 +760,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
748
760
|
directives.push({
|
|
749
761
|
name: 'example',
|
|
750
762
|
args: {
|
|
763
|
+
subgraph: subgraphName,
|
|
751
764
|
value: example,
|
|
752
765
|
},
|
|
753
766
|
});
|
|
@@ -797,6 +810,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
797
810
|
if (subSchemaOnly.discriminator?.propertyName) {
|
|
798
811
|
schemaComposer.addDirective(directives_js_1.DiscriminatorDirective);
|
|
799
812
|
const discriminatorArgs = {
|
|
813
|
+
subgraph: subgraphName,
|
|
800
814
|
field: subSchemaOnly.discriminator.propertyName,
|
|
801
815
|
};
|
|
802
816
|
if (subSchemaOnly.discriminator.mapping) {
|
|
@@ -813,6 +827,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
813
827
|
const isPlural = subSchemaAndTypeComposers.oneOf.some(({ output }) => output instanceof graphql_compose_1.ListComposer);
|
|
814
828
|
if (isPlural) {
|
|
815
829
|
const { input, output, flatten } = (0, getUnionTypeComposers_js_1.getUnionTypeComposers)({
|
|
830
|
+
subgraphName,
|
|
816
831
|
schemaComposer,
|
|
817
832
|
typeComposersList: subSchemaAndTypeComposers.oneOf.map(({ input, output }) => ({
|
|
818
833
|
input: input.ofType || input,
|
|
@@ -835,6 +850,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
835
850
|
};
|
|
836
851
|
}
|
|
837
852
|
return (0, getUnionTypeComposers_js_1.getUnionTypeComposers)({
|
|
853
|
+
subgraphName,
|
|
838
854
|
schemaComposer,
|
|
839
855
|
typeComposersList: subSchemaAndTypeComposers.oneOf,
|
|
840
856
|
subSchemaAndTypeComposers,
|
|
@@ -898,6 +914,9 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
898
914
|
directives: [
|
|
899
915
|
{
|
|
900
916
|
name: 'resolveRoot',
|
|
917
|
+
args: {
|
|
918
|
+
subgraph: subgraphName,
|
|
919
|
+
},
|
|
901
920
|
},
|
|
902
921
|
],
|
|
903
922
|
};
|
|
@@ -955,6 +974,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
955
974
|
directives.push({
|
|
956
975
|
name: 'example',
|
|
957
976
|
args: {
|
|
977
|
+
subgraph: subgraphName,
|
|
958
978
|
value: example,
|
|
959
979
|
},
|
|
960
980
|
});
|
|
@@ -975,6 +995,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
975
995
|
directives.push({
|
|
976
996
|
name: 'example',
|
|
977
997
|
args: {
|
|
998
|
+
subgraph: subgraphName,
|
|
978
999
|
value: example,
|
|
979
1000
|
},
|
|
980
1001
|
});
|
|
@@ -1061,6 +1082,9 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
1061
1082
|
directives: [
|
|
1062
1083
|
{
|
|
1063
1084
|
name: 'resolveRoot',
|
|
1085
|
+
args: {
|
|
1086
|
+
subgraph: subgraphName,
|
|
1087
|
+
},
|
|
1064
1088
|
},
|
|
1065
1089
|
],
|
|
1066
1090
|
};
|
|
@@ -1078,6 +1102,9 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
1078
1102
|
directives: [
|
|
1079
1103
|
{
|
|
1080
1104
|
name: 'resolveRoot',
|
|
1105
|
+
args: {
|
|
1106
|
+
subgraph: subgraphName,
|
|
1107
|
+
},
|
|
1081
1108
|
},
|
|
1082
1109
|
],
|
|
1083
1110
|
};
|
|
@@ -1125,6 +1152,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
1125
1152
|
directives.push({
|
|
1126
1153
|
name: 'example',
|
|
1127
1154
|
args: {
|
|
1155
|
+
subgraph: subgraphName,
|
|
1128
1156
|
value: example,
|
|
1129
1157
|
},
|
|
1130
1158
|
});
|
|
@@ -1148,6 +1176,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
1148
1176
|
directives.push({
|
|
1149
1177
|
name: 'example',
|
|
1150
1178
|
args: {
|
|
1179
|
+
subgraph: subgraphName,
|
|
1151
1180
|
value: example,
|
|
1152
1181
|
},
|
|
1153
1182
|
});
|
|
@@ -1177,6 +1206,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
1177
1206
|
fieldDirectives.push({
|
|
1178
1207
|
name: 'resolveRootField',
|
|
1179
1208
|
args: {
|
|
1209
|
+
subgraph: subgraphName,
|
|
1180
1210
|
field: propertyName,
|
|
1181
1211
|
},
|
|
1182
1212
|
});
|
|
@@ -1185,6 +1215,9 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
1185
1215
|
schemaComposer.addDirective(directives_js_1.FlattenDirective);
|
|
1186
1216
|
fieldDirectives.push({
|
|
1187
1217
|
name: 'flatten',
|
|
1218
|
+
args: {
|
|
1219
|
+
subgraph: subgraphName,
|
|
1220
|
+
},
|
|
1188
1221
|
});
|
|
1189
1222
|
}
|
|
1190
1223
|
fieldMap[fieldName] = {
|
|
@@ -1220,6 +1253,7 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
1220
1253
|
directives.push({
|
|
1221
1254
|
name: 'resolveRootField',
|
|
1222
1255
|
args: {
|
|
1256
|
+
subgraph: subgraphName,
|
|
1223
1257
|
field: propertyName,
|
|
1224
1258
|
},
|
|
1225
1259
|
});
|
|
@@ -1274,6 +1308,9 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
1274
1308
|
directives: [
|
|
1275
1309
|
{
|
|
1276
1310
|
name: 'dictionary',
|
|
1311
|
+
args: {
|
|
1312
|
+
subgraph: subgraphName,
|
|
1313
|
+
},
|
|
1277
1314
|
},
|
|
1278
1315
|
],
|
|
1279
1316
|
};
|
|
@@ -1285,6 +1322,9 @@ function getComposerFromJSONSchema(schema, logger) {
|
|
|
1285
1322
|
directives: [
|
|
1286
1323
|
{
|
|
1287
1324
|
name: 'resolveRoot',
|
|
1325
|
+
args: {
|
|
1326
|
+
subgraph: subgraphName,
|
|
1327
|
+
},
|
|
1288
1328
|
},
|
|
1289
1329
|
],
|
|
1290
1330
|
};
|
|
@@ -5,10 +5,10 @@ const graphql_1 = require("graphql");
|
|
|
5
5
|
const graphql_compose_1 = require("graphql-compose");
|
|
6
6
|
const addExecutionLogicToComposer_js_1 = require("./addExecutionLogicToComposer.js");
|
|
7
7
|
const getComposerFromJSONSchema_js_1 = require("./getComposerFromJSONSchema.js");
|
|
8
|
-
async function getGraphQLSchemaFromDereferencedJSONSchema(
|
|
8
|
+
async function getGraphQLSchemaFromDereferencedJSONSchema(subgraphName, opts) {
|
|
9
9
|
const { fullyDeferencedSchema, logger, operations, operationHeaders, endpoint, queryParams, queryStringOptions, } = opts;
|
|
10
10
|
logger.debug(`Generating GraphQL Schema from the bundled JSON Schema`);
|
|
11
|
-
const visitorResult = await (0, getComposerFromJSONSchema_js_1.getComposerFromJSONSchema)(fullyDeferencedSchema, logger.child('getComposerFromJSONSchema'));
|
|
11
|
+
const visitorResult = await (0, getComposerFromJSONSchema_js_1.getComposerFromJSONSchema)(subgraphName, fullyDeferencedSchema, logger.child('getComposerFromJSONSchema'));
|
|
12
12
|
const schemaComposerWithoutExecutionLogic = visitorResult.output;
|
|
13
13
|
if (!(schemaComposerWithoutExecutionLogic instanceof graphql_compose_1.SchemaComposer)) {
|
|
14
14
|
throw new Error('The visitor result should be a SchemaComposer instance.');
|
|
@@ -17,7 +17,7 @@ async function getGraphQLSchemaFromDereferencedJSONSchema(name, opts) {
|
|
|
17
17
|
for (const directive of graphql_1.specifiedDirectives) {
|
|
18
18
|
schemaComposerWithoutExecutionLogic.addDirective(directive);
|
|
19
19
|
}
|
|
20
|
-
const schemaComposerWithExecutionLogic = await (0, addExecutionLogicToComposer_js_1.addExecutionDirectivesToComposer)(
|
|
20
|
+
const schemaComposerWithExecutionLogic = await (0, addExecutionLogicToComposer_js_1.addExecutionDirectivesToComposer)(subgraphName, {
|
|
21
21
|
schemaComposer: schemaComposerWithoutExecutionLogic,
|
|
22
22
|
logger,
|
|
23
23
|
operations,
|
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.getUnionTypeComposers = exports.getContainerTC = void 0;
|
|
4
4
|
const graphql_compose_1 = require("graphql-compose");
|
|
5
5
|
const directives_js_1 = require("./directives.js");
|
|
6
|
-
function getContainerTC(schemaComposer, output) {
|
|
6
|
+
function getContainerTC(subgraphName, schemaComposer, output) {
|
|
7
7
|
const containerTypeName = `${output.getTypeName()}_container`;
|
|
8
8
|
schemaComposer.addDirective(directives_js_1.ResolveRootDirective);
|
|
9
9
|
return schemaComposer.getOrCreateOTC(containerTypeName, otc => otc.addFields({
|
|
@@ -12,13 +12,16 @@ function getContainerTC(schemaComposer, output) {
|
|
|
12
12
|
directives: [
|
|
13
13
|
{
|
|
14
14
|
name: 'resolveRoot',
|
|
15
|
+
args: {
|
|
16
|
+
subgraph: subgraphName,
|
|
17
|
+
},
|
|
15
18
|
},
|
|
16
19
|
],
|
|
17
20
|
},
|
|
18
21
|
}));
|
|
19
22
|
}
|
|
20
23
|
exports.getContainerTC = getContainerTC;
|
|
21
|
-
function getUnionTypeComposers({ schemaComposer, typeComposersList, subSchemaAndTypeComposers, logger, }) {
|
|
24
|
+
function getUnionTypeComposers({ subgraphName, schemaComposer, typeComposersList, subSchemaAndTypeComposers, logger, }) {
|
|
22
25
|
if (new Set(typeComposersList).size === 1) {
|
|
23
26
|
return typeComposersList[0];
|
|
24
27
|
}
|
|
@@ -32,7 +35,7 @@ function getUnionTypeComposers({ schemaComposer, typeComposersList, subSchemaAnd
|
|
|
32
35
|
isOutputPlural = true;
|
|
33
36
|
}
|
|
34
37
|
if ((0, graphql_compose_1.isSomeInputTypeComposer)(output)) {
|
|
35
|
-
outputTypeComposers.push(getContainerTC(schemaComposer, output));
|
|
38
|
+
outputTypeComposers.push(getContainerTC(subgraphName, schemaComposer, output));
|
|
36
39
|
}
|
|
37
40
|
else {
|
|
38
41
|
outputTypeComposers.push(output);
|
|
@@ -71,6 +74,7 @@ function getUnionTypeComposers({ schemaComposer, typeComposersList, subSchemaAnd
|
|
|
71
74
|
directives.push({
|
|
72
75
|
name: 'statusCodeTypeName',
|
|
73
76
|
args: {
|
|
77
|
+
subgraph: subgraphName,
|
|
74
78
|
statusCode,
|
|
75
79
|
typeName: outputTypeComposer.getTypeName(),
|
|
76
80
|
},
|
|
@@ -14,10 +14,10 @@ const responseMetadataType = new GraphQLObjectType({
|
|
|
14
14
|
body: { type: GraphQLJSON },
|
|
15
15
|
},
|
|
16
16
|
});
|
|
17
|
-
export async function addExecutionDirectivesToComposer(
|
|
17
|
+
export async function addExecutionDirectivesToComposer(subgraphName, { schemaComposer, logger, operations, operationHeaders, endpoint, queryParams, queryStringOptions, }) {
|
|
18
18
|
schemaComposer.addDirective(GlobalOptionsDirective);
|
|
19
19
|
schemaComposer.Query.setDirectiveByName('globalOptions', JSON.parse(JSON.stringify({
|
|
20
|
-
|
|
20
|
+
subgraph: subgraphName,
|
|
21
21
|
endpoint,
|
|
22
22
|
operationHeaders,
|
|
23
23
|
queryStringOptions,
|
|
@@ -36,6 +36,7 @@ export async function addExecutionDirectivesToComposer(name, { schemaComposer, l
|
|
|
36
36
|
field.directives.push({
|
|
37
37
|
name: 'pubsubOperation',
|
|
38
38
|
args: {
|
|
39
|
+
subgraph: subgraphName,
|
|
39
40
|
pubsubTopic: operationConfig.pubsubTopic,
|
|
40
41
|
},
|
|
41
42
|
});
|
|
@@ -57,6 +58,7 @@ ${operationConfig.description || ''}
|
|
|
57
58
|
field.directives.push({
|
|
58
59
|
name: 'httpOperation',
|
|
59
60
|
args: JSON.parse(JSON.stringify({
|
|
61
|
+
subgraph: subgraphName,
|
|
60
62
|
path: operationConfig.path,
|
|
61
63
|
operationSpecificHeaders: operationConfig.headers,
|
|
62
64
|
httpMethod,
|
|
@@ -78,6 +80,7 @@ ${operationConfig.description || ''}
|
|
|
78
80
|
linkResolverMapDirective = {
|
|
79
81
|
name: 'linkResolver',
|
|
80
82
|
args: {
|
|
83
|
+
subgraph: subgraphName,
|
|
81
84
|
linkResolverMap: {},
|
|
82
85
|
},
|
|
83
86
|
};
|
|
@@ -98,7 +101,7 @@ ${operationConfig.description || ''}
|
|
|
98
101
|
catch { }
|
|
99
102
|
}
|
|
100
103
|
if (!targetField) {
|
|
101
|
-
logger.debug(`Field ${linkObj.fieldName} not found in ${
|
|
104
|
+
logger.debug(`Field ${linkObj.fieldName} not found in ${subgraphName} for link ${linkName}`);
|
|
102
105
|
}
|
|
103
106
|
linkResolverFieldMap[linkName] = {
|
|
104
107
|
linkObjArgs: linkObj.args,
|
|
@@ -112,6 +115,7 @@ ${operationConfig.description || ''}
|
|
|
112
115
|
{
|
|
113
116
|
name: 'link',
|
|
114
117
|
args: {
|
|
118
|
+
subgraph: subgraphName,
|
|
115
119
|
defaultRootType: rootTypeName,
|
|
116
120
|
defaultField: operationConfig.field,
|
|
117
121
|
},
|
|
@@ -137,6 +141,9 @@ ${operationConfig.description || ''}
|
|
|
137
141
|
directives: [
|
|
138
142
|
{
|
|
139
143
|
name: 'responseMetadata',
|
|
144
|
+
args: {
|
|
145
|
+
subgraph: subgraphName,
|
|
146
|
+
},
|
|
140
147
|
},
|
|
141
148
|
],
|
|
142
149
|
},
|
|
@@ -169,6 +176,9 @@ ${operationConfig.description || ''}
|
|
|
169
176
|
directives: [
|
|
170
177
|
{
|
|
171
178
|
name: 'resolveRoot',
|
|
179
|
+
args: {
|
|
180
|
+
subgraph: subgraphName,
|
|
181
|
+
},
|
|
172
182
|
},
|
|
173
183
|
],
|
|
174
184
|
},
|
|
@@ -186,6 +196,9 @@ ${operationConfig.description || ''}
|
|
|
186
196
|
directives: [
|
|
187
197
|
{
|
|
188
198
|
name: 'responseMetadata',
|
|
199
|
+
args: {
|
|
200
|
+
subgraph: subgraphName,
|
|
201
|
+
},
|
|
189
202
|
},
|
|
190
203
|
],
|
|
191
204
|
},
|
package/esm/directives.js
CHANGED
|
@@ -10,6 +10,9 @@ export const LengthDirective = new GraphQLDirective({
|
|
|
10
10
|
name: 'length',
|
|
11
11
|
locations: [DirectiveLocation.SCALAR],
|
|
12
12
|
args: {
|
|
13
|
+
subgraph: {
|
|
14
|
+
type: GraphQLString,
|
|
15
|
+
},
|
|
13
16
|
min: {
|
|
14
17
|
type: GraphQLInt,
|
|
15
18
|
},
|
|
@@ -44,6 +47,9 @@ export const DiscriminatorDirective = new GraphQLDirective({
|
|
|
44
47
|
name: 'discriminator',
|
|
45
48
|
locations: [DirectiveLocation.INTERFACE, DirectiveLocation.UNION],
|
|
46
49
|
args: {
|
|
50
|
+
subgraph: {
|
|
51
|
+
type: GraphQLString,
|
|
52
|
+
},
|
|
47
53
|
field: {
|
|
48
54
|
type: GraphQLString,
|
|
49
55
|
},
|
|
@@ -58,6 +64,11 @@ export function processDiscriminatorAnnotations({ interfaceType, discriminatorFi
|
|
|
58
64
|
export const ResolveRootDirective = new GraphQLDirective({
|
|
59
65
|
name: 'resolveRoot',
|
|
60
66
|
locations: [DirectiveLocation.FIELD_DEFINITION],
|
|
67
|
+
args: {
|
|
68
|
+
subgraph: {
|
|
69
|
+
type: GraphQLString,
|
|
70
|
+
},
|
|
71
|
+
},
|
|
61
72
|
});
|
|
62
73
|
function rootResolver(root) {
|
|
63
74
|
return root;
|
|
@@ -73,6 +84,9 @@ export const ResolveRootFieldDirective = new GraphQLDirective({
|
|
|
73
84
|
DirectiveLocation.INPUT_FIELD_DEFINITION,
|
|
74
85
|
],
|
|
75
86
|
args: {
|
|
87
|
+
subgraph: {
|
|
88
|
+
type: GraphQLString,
|
|
89
|
+
},
|
|
76
90
|
field: {
|
|
77
91
|
type: GraphQLString,
|
|
78
92
|
},
|
|
@@ -106,6 +120,9 @@ export const RegExpDirective = new GraphQLDirective({
|
|
|
106
120
|
name: 'regexp',
|
|
107
121
|
locations: [DirectiveLocation.SCALAR],
|
|
108
122
|
args: {
|
|
123
|
+
subgraph: {
|
|
124
|
+
type: GraphQLString,
|
|
125
|
+
},
|
|
109
126
|
pattern: {
|
|
110
127
|
type: GraphQLString,
|
|
111
128
|
},
|
|
@@ -135,6 +152,9 @@ export const PubSubOperationDirective = new GraphQLDirective({
|
|
|
135
152
|
name: 'pubsubOperation',
|
|
136
153
|
locations: [DirectiveLocation.FIELD_DEFINITION],
|
|
137
154
|
args: {
|
|
155
|
+
subgraph: {
|
|
156
|
+
type: GraphQLString,
|
|
157
|
+
},
|
|
138
158
|
pubsubTopic: {
|
|
139
159
|
type: GraphQLString,
|
|
140
160
|
},
|
|
@@ -167,6 +187,9 @@ export const TypeScriptDirective = new GraphQLDirective({
|
|
|
167
187
|
name: 'typescript',
|
|
168
188
|
locations: [DirectiveLocation.SCALAR, DirectiveLocation.ENUM],
|
|
169
189
|
args: {
|
|
190
|
+
subgraph: {
|
|
191
|
+
type: GraphQLString,
|
|
192
|
+
},
|
|
170
193
|
type: {
|
|
171
194
|
type: GraphQLString,
|
|
172
195
|
},
|
|
@@ -222,6 +245,9 @@ export const HTTPOperationDirective = new GraphQLDirective({
|
|
|
222
245
|
name: 'httpOperation',
|
|
223
246
|
locations: [DirectiveLocation.FIELD_DEFINITION],
|
|
224
247
|
args: {
|
|
248
|
+
subgraph: {
|
|
249
|
+
type: GraphQLString,
|
|
250
|
+
},
|
|
225
251
|
path: {
|
|
226
252
|
type: GraphQLString,
|
|
227
253
|
},
|
|
@@ -262,7 +288,7 @@ export const GlobalOptionsDirective = new GraphQLDirective({
|
|
|
262
288
|
name: 'globalOptions',
|
|
263
289
|
locations: [DirectiveLocation.OBJECT],
|
|
264
290
|
args: {
|
|
265
|
-
|
|
291
|
+
subgraph: {
|
|
266
292
|
type: GraphQLString,
|
|
267
293
|
},
|
|
268
294
|
endpoint: {
|
|
@@ -282,6 +308,11 @@ export const GlobalOptionsDirective = new GraphQLDirective({
|
|
|
282
308
|
export const ResponseMetadataDirective = new GraphQLDirective({
|
|
283
309
|
name: 'responseMetadata',
|
|
284
310
|
locations: [DirectiveLocation.FIELD_DEFINITION],
|
|
311
|
+
args: {
|
|
312
|
+
subgraph: {
|
|
313
|
+
type: GraphQLString,
|
|
314
|
+
},
|
|
315
|
+
},
|
|
285
316
|
});
|
|
286
317
|
export function processResponseMetadataAnnotations(field) {
|
|
287
318
|
field.resolve = function responseMetadataResolver(root) {
|
|
@@ -311,6 +342,9 @@ export const LinkResolverDirective = new GraphQLDirective({
|
|
|
311
342
|
name: 'linkResolver',
|
|
312
343
|
locations: [DirectiveLocation.FIELD_DEFINITION],
|
|
313
344
|
args: {
|
|
345
|
+
subgraph: {
|
|
346
|
+
type: GraphQLString,
|
|
347
|
+
},
|
|
314
348
|
linkResolverMap: {
|
|
315
349
|
type: ObjMapScalar,
|
|
316
350
|
},
|
|
@@ -379,6 +413,11 @@ export function processLinkFieldAnnotations(field, defaultRootTypeName, defaultF
|
|
|
379
413
|
export const DictionaryDirective = new GraphQLDirective({
|
|
380
414
|
name: 'dictionary',
|
|
381
415
|
locations: [DirectiveLocation.FIELD_DEFINITION],
|
|
416
|
+
args: {
|
|
417
|
+
subgraph: {
|
|
418
|
+
type: GraphQLString,
|
|
419
|
+
},
|
|
420
|
+
},
|
|
382
421
|
});
|
|
383
422
|
export function processDictionaryDirective(fieldMap, field) {
|
|
384
423
|
field.resolve = root => {
|
|
@@ -398,6 +437,11 @@ export function processDictionaryDirective(fieldMap, field) {
|
|
|
398
437
|
export const FlattenDirective = new GraphQLDirective({
|
|
399
438
|
name: 'flatten',
|
|
400
439
|
locations: [DirectiveLocation.FIELD_DEFINITION],
|
|
440
|
+
args: {
|
|
441
|
+
subgraph: {
|
|
442
|
+
type: GraphQLString,
|
|
443
|
+
},
|
|
444
|
+
},
|
|
401
445
|
});
|
|
402
446
|
export function processFlattenAnnotations(field) {
|
|
403
447
|
if (!field.resolve || field.resolve.name === 'defaultFieldResolver') {
|
|
@@ -548,6 +592,9 @@ export const StatusCodeTypeNameDirective = new GraphQLDirective({
|
|
|
548
592
|
locations: [DirectiveLocation.UNION],
|
|
549
593
|
isRepeatable: true,
|
|
550
594
|
args: {
|
|
595
|
+
subgraph: {
|
|
596
|
+
type: GraphQLString,
|
|
597
|
+
},
|
|
551
598
|
typeName: {
|
|
552
599
|
type: GraphQLString,
|
|
553
600
|
},
|
|
@@ -560,6 +607,9 @@ export const EnumDirective = new GraphQLDirective({
|
|
|
560
607
|
name: 'enum',
|
|
561
608
|
locations: [DirectiveLocation.ENUM_VALUE],
|
|
562
609
|
args: {
|
|
610
|
+
subgraph: {
|
|
611
|
+
type: GraphQLString,
|
|
612
|
+
},
|
|
563
613
|
value: {
|
|
564
614
|
type: GraphQLString,
|
|
565
615
|
},
|
|
@@ -583,6 +633,9 @@ export const ExampleDirective = new GraphQLDirective({
|
|
|
583
633
|
DirectiveLocation.SCALAR,
|
|
584
634
|
],
|
|
585
635
|
args: {
|
|
636
|
+
subgraph: {
|
|
637
|
+
type: GraphQLString,
|
|
638
|
+
},
|
|
586
639
|
value: {
|
|
587
640
|
type: ObjMapScalar,
|
|
588
641
|
},
|
|
@@ -9,7 +9,7 @@ import { getJSONSchemaStringFormatScalarMap } from './getJSONSchemaStringFormatS
|
|
|
9
9
|
import { getUnionTypeComposers } from './getUnionTypeComposers.js';
|
|
10
10
|
import { getValidTypeName } from './getValidTypeName.js';
|
|
11
11
|
import { GraphQLFile, GraphQLVoid } from './scalars.js';
|
|
12
|
-
export function getComposerFromJSONSchema(schema, logger) {
|
|
12
|
+
export function getComposerFromJSONSchema(subgraphName, schema, logger) {
|
|
13
13
|
const schemaComposer = new SchemaComposer();
|
|
14
14
|
const formatScalarMap = getJSONSchemaStringFormatScalarMap();
|
|
15
15
|
const rootInputTypeNameComposerMap = {
|
|
@@ -112,12 +112,14 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
112
112
|
{
|
|
113
113
|
name: 'regexp',
|
|
114
114
|
args: {
|
|
115
|
+
subgraph: subgraphName,
|
|
115
116
|
pattern: subSchema.pattern,
|
|
116
117
|
},
|
|
117
118
|
},
|
|
118
119
|
{
|
|
119
120
|
name: 'typescript',
|
|
120
121
|
args: {
|
|
122
|
+
subgraph: subgraphName,
|
|
121
123
|
type: typeScriptType,
|
|
122
124
|
},
|
|
123
125
|
},
|
|
@@ -149,6 +151,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
149
151
|
{
|
|
150
152
|
name: 'enum',
|
|
151
153
|
args: {
|
|
154
|
+
subgraph: subgraphName,
|
|
152
155
|
value: JSON.stringify(subSchema.const),
|
|
153
156
|
},
|
|
154
157
|
},
|
|
@@ -159,12 +162,14 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
159
162
|
{
|
|
160
163
|
name: 'typescript',
|
|
161
164
|
args: {
|
|
165
|
+
subgraph: subgraphName,
|
|
162
166
|
type: JSON.stringify(subSchema.const),
|
|
163
167
|
},
|
|
164
168
|
},
|
|
165
169
|
{
|
|
166
170
|
name: 'example',
|
|
167
171
|
args: {
|
|
172
|
+
subgraph: subgraphName,
|
|
168
173
|
value: subSchema.const,
|
|
169
174
|
},
|
|
170
175
|
},
|
|
@@ -201,6 +206,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
201
206
|
directives.push({
|
|
202
207
|
name: 'enum',
|
|
203
208
|
args: {
|
|
209
|
+
subgraph: subgraphName,
|
|
204
210
|
value: JSON.stringify(enumValue),
|
|
205
211
|
},
|
|
206
212
|
});
|
|
@@ -217,6 +223,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
217
223
|
directives.push({
|
|
218
224
|
name: 'example',
|
|
219
225
|
args: {
|
|
226
|
+
subgraph: subgraphName,
|
|
220
227
|
value: example,
|
|
221
228
|
},
|
|
222
229
|
});
|
|
@@ -596,6 +603,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
596
603
|
{
|
|
597
604
|
name: 'length',
|
|
598
605
|
args: {
|
|
606
|
+
subgraph: subgraphName,
|
|
599
607
|
min: subSchema.minLength,
|
|
600
608
|
max: subSchema.maxLength,
|
|
601
609
|
},
|
|
@@ -667,6 +675,9 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
667
675
|
directives: [
|
|
668
676
|
{
|
|
669
677
|
name: 'oneOf',
|
|
678
|
+
args: {
|
|
679
|
+
subgraph: subgraphName,
|
|
680
|
+
},
|
|
670
681
|
},
|
|
671
682
|
],
|
|
672
683
|
});
|
|
@@ -730,6 +741,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
730
741
|
config.directives.push({
|
|
731
742
|
name: 'example',
|
|
732
743
|
args: {
|
|
744
|
+
subgraph: subgraphName,
|
|
733
745
|
value: example,
|
|
734
746
|
},
|
|
735
747
|
});
|
|
@@ -745,6 +757,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
745
757
|
directives.push({
|
|
746
758
|
name: 'example',
|
|
747
759
|
args: {
|
|
760
|
+
subgraph: subgraphName,
|
|
748
761
|
value: example,
|
|
749
762
|
},
|
|
750
763
|
});
|
|
@@ -794,6 +807,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
794
807
|
if (subSchemaOnly.discriminator?.propertyName) {
|
|
795
808
|
schemaComposer.addDirective(DiscriminatorDirective);
|
|
796
809
|
const discriminatorArgs = {
|
|
810
|
+
subgraph: subgraphName,
|
|
797
811
|
field: subSchemaOnly.discriminator.propertyName,
|
|
798
812
|
};
|
|
799
813
|
if (subSchemaOnly.discriminator.mapping) {
|
|
@@ -810,6 +824,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
810
824
|
const isPlural = subSchemaAndTypeComposers.oneOf.some(({ output }) => output instanceof ListComposer);
|
|
811
825
|
if (isPlural) {
|
|
812
826
|
const { input, output, flatten } = getUnionTypeComposers({
|
|
827
|
+
subgraphName,
|
|
813
828
|
schemaComposer,
|
|
814
829
|
typeComposersList: subSchemaAndTypeComposers.oneOf.map(({ input, output }) => ({
|
|
815
830
|
input: input.ofType || input,
|
|
@@ -832,6 +847,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
832
847
|
};
|
|
833
848
|
}
|
|
834
849
|
return getUnionTypeComposers({
|
|
850
|
+
subgraphName,
|
|
835
851
|
schemaComposer,
|
|
836
852
|
typeComposersList: subSchemaAndTypeComposers.oneOf,
|
|
837
853
|
subSchemaAndTypeComposers,
|
|
@@ -895,6 +911,9 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
895
911
|
directives: [
|
|
896
912
|
{
|
|
897
913
|
name: 'resolveRoot',
|
|
914
|
+
args: {
|
|
915
|
+
subgraph: subgraphName,
|
|
916
|
+
},
|
|
898
917
|
},
|
|
899
918
|
],
|
|
900
919
|
};
|
|
@@ -952,6 +971,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
952
971
|
directives.push({
|
|
953
972
|
name: 'example',
|
|
954
973
|
args: {
|
|
974
|
+
subgraph: subgraphName,
|
|
955
975
|
value: example,
|
|
956
976
|
},
|
|
957
977
|
});
|
|
@@ -972,6 +992,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
972
992
|
directives.push({
|
|
973
993
|
name: 'example',
|
|
974
994
|
args: {
|
|
995
|
+
subgraph: subgraphName,
|
|
975
996
|
value: example,
|
|
976
997
|
},
|
|
977
998
|
});
|
|
@@ -1058,6 +1079,9 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
1058
1079
|
directives: [
|
|
1059
1080
|
{
|
|
1060
1081
|
name: 'resolveRoot',
|
|
1082
|
+
args: {
|
|
1083
|
+
subgraph: subgraphName,
|
|
1084
|
+
},
|
|
1061
1085
|
},
|
|
1062
1086
|
],
|
|
1063
1087
|
};
|
|
@@ -1075,6 +1099,9 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
1075
1099
|
directives: [
|
|
1076
1100
|
{
|
|
1077
1101
|
name: 'resolveRoot',
|
|
1102
|
+
args: {
|
|
1103
|
+
subgraph: subgraphName,
|
|
1104
|
+
},
|
|
1078
1105
|
},
|
|
1079
1106
|
],
|
|
1080
1107
|
};
|
|
@@ -1122,6 +1149,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
1122
1149
|
directives.push({
|
|
1123
1150
|
name: 'example',
|
|
1124
1151
|
args: {
|
|
1152
|
+
subgraph: subgraphName,
|
|
1125
1153
|
value: example,
|
|
1126
1154
|
},
|
|
1127
1155
|
});
|
|
@@ -1145,6 +1173,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
1145
1173
|
directives.push({
|
|
1146
1174
|
name: 'example',
|
|
1147
1175
|
args: {
|
|
1176
|
+
subgraph: subgraphName,
|
|
1148
1177
|
value: example,
|
|
1149
1178
|
},
|
|
1150
1179
|
});
|
|
@@ -1174,6 +1203,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
1174
1203
|
fieldDirectives.push({
|
|
1175
1204
|
name: 'resolveRootField',
|
|
1176
1205
|
args: {
|
|
1206
|
+
subgraph: subgraphName,
|
|
1177
1207
|
field: propertyName,
|
|
1178
1208
|
},
|
|
1179
1209
|
});
|
|
@@ -1182,6 +1212,9 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
1182
1212
|
schemaComposer.addDirective(FlattenDirective);
|
|
1183
1213
|
fieldDirectives.push({
|
|
1184
1214
|
name: 'flatten',
|
|
1215
|
+
args: {
|
|
1216
|
+
subgraph: subgraphName,
|
|
1217
|
+
},
|
|
1185
1218
|
});
|
|
1186
1219
|
}
|
|
1187
1220
|
fieldMap[fieldName] = {
|
|
@@ -1217,6 +1250,7 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
1217
1250
|
directives.push({
|
|
1218
1251
|
name: 'resolveRootField',
|
|
1219
1252
|
args: {
|
|
1253
|
+
subgraph: subgraphName,
|
|
1220
1254
|
field: propertyName,
|
|
1221
1255
|
},
|
|
1222
1256
|
});
|
|
@@ -1271,6 +1305,9 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
1271
1305
|
directives: [
|
|
1272
1306
|
{
|
|
1273
1307
|
name: 'dictionary',
|
|
1308
|
+
args: {
|
|
1309
|
+
subgraph: subgraphName,
|
|
1310
|
+
},
|
|
1274
1311
|
},
|
|
1275
1312
|
],
|
|
1276
1313
|
};
|
|
@@ -1282,6 +1319,9 @@ export function getComposerFromJSONSchema(schema, logger) {
|
|
|
1282
1319
|
directives: [
|
|
1283
1320
|
{
|
|
1284
1321
|
name: 'resolveRoot',
|
|
1322
|
+
args: {
|
|
1323
|
+
subgraph: subgraphName,
|
|
1324
|
+
},
|
|
1285
1325
|
},
|
|
1286
1326
|
],
|
|
1287
1327
|
};
|
|
@@ -2,10 +2,10 @@ import { specifiedDirectives } from 'graphql';
|
|
|
2
2
|
import { SchemaComposer } from 'graphql-compose';
|
|
3
3
|
import { addExecutionDirectivesToComposer, } from './addExecutionLogicToComposer.js';
|
|
4
4
|
import { getComposerFromJSONSchema } from './getComposerFromJSONSchema.js';
|
|
5
|
-
export async function getGraphQLSchemaFromDereferencedJSONSchema(
|
|
5
|
+
export async function getGraphQLSchemaFromDereferencedJSONSchema(subgraphName, opts) {
|
|
6
6
|
const { fullyDeferencedSchema, logger, operations, operationHeaders, endpoint, queryParams, queryStringOptions, } = opts;
|
|
7
7
|
logger.debug(`Generating GraphQL Schema from the bundled JSON Schema`);
|
|
8
|
-
const visitorResult = await getComposerFromJSONSchema(fullyDeferencedSchema, logger.child('getComposerFromJSONSchema'));
|
|
8
|
+
const visitorResult = await getComposerFromJSONSchema(subgraphName, fullyDeferencedSchema, logger.child('getComposerFromJSONSchema'));
|
|
9
9
|
const schemaComposerWithoutExecutionLogic = visitorResult.output;
|
|
10
10
|
if (!(schemaComposerWithoutExecutionLogic instanceof SchemaComposer)) {
|
|
11
11
|
throw new Error('The visitor result should be a SchemaComposer instance.');
|
|
@@ -14,7 +14,7 @@ export async function getGraphQLSchemaFromDereferencedJSONSchema(name, opts) {
|
|
|
14
14
|
for (const directive of specifiedDirectives) {
|
|
15
15
|
schemaComposerWithoutExecutionLogic.addDirective(directive);
|
|
16
16
|
}
|
|
17
|
-
const schemaComposerWithExecutionLogic = await addExecutionDirectivesToComposer(
|
|
17
|
+
const schemaComposerWithExecutionLogic = await addExecutionDirectivesToComposer(subgraphName, {
|
|
18
18
|
schemaComposer: schemaComposerWithoutExecutionLogic,
|
|
19
19
|
logger,
|
|
20
20
|
operations,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isSomeInputTypeComposer, ListComposer, } from 'graphql-compose';
|
|
2
2
|
import { ResolveRootDirective, StatusCodeTypeNameDirective } from './directives.js';
|
|
3
|
-
export function getContainerTC(schemaComposer, output) {
|
|
3
|
+
export function getContainerTC(subgraphName, schemaComposer, output) {
|
|
4
4
|
const containerTypeName = `${output.getTypeName()}_container`;
|
|
5
5
|
schemaComposer.addDirective(ResolveRootDirective);
|
|
6
6
|
return schemaComposer.getOrCreateOTC(containerTypeName, otc => otc.addFields({
|
|
@@ -9,12 +9,15 @@ export function getContainerTC(schemaComposer, output) {
|
|
|
9
9
|
directives: [
|
|
10
10
|
{
|
|
11
11
|
name: 'resolveRoot',
|
|
12
|
+
args: {
|
|
13
|
+
subgraph: subgraphName,
|
|
14
|
+
},
|
|
12
15
|
},
|
|
13
16
|
],
|
|
14
17
|
},
|
|
15
18
|
}));
|
|
16
19
|
}
|
|
17
|
-
export function getUnionTypeComposers({ schemaComposer, typeComposersList, subSchemaAndTypeComposers, logger, }) {
|
|
20
|
+
export function getUnionTypeComposers({ subgraphName, schemaComposer, typeComposersList, subSchemaAndTypeComposers, logger, }) {
|
|
18
21
|
if (new Set(typeComposersList).size === 1) {
|
|
19
22
|
return typeComposersList[0];
|
|
20
23
|
}
|
|
@@ -28,7 +31,7 @@ export function getUnionTypeComposers({ schemaComposer, typeComposersList, subSc
|
|
|
28
31
|
isOutputPlural = true;
|
|
29
32
|
}
|
|
30
33
|
if (isSomeInputTypeComposer(output)) {
|
|
31
|
-
outputTypeComposers.push(getContainerTC(schemaComposer, output));
|
|
34
|
+
outputTypeComposers.push(getContainerTC(subgraphName, schemaComposer, output));
|
|
32
35
|
}
|
|
33
36
|
else {
|
|
34
37
|
outputTypeComposers.push(output);
|
|
@@ -67,6 +70,7 @@ export function getUnionTypeComposers({ schemaComposer, typeComposersList, subSc
|
|
|
67
70
|
directives.push({
|
|
68
71
|
name: 'statusCodeTypeName',
|
|
69
72
|
args: {
|
|
73
|
+
subgraph: subgraphName,
|
|
70
74
|
statusCode,
|
|
71
75
|
typeName: outputTypeComposer.getTypeName(),
|
|
72
76
|
},
|
package/package.json
CHANGED
|
@@ -11,4 +11,4 @@ export interface AddExecutionLogicToComposerOptions {
|
|
|
11
11
|
queryParams?: Record<string, string | number | boolean>;
|
|
12
12
|
queryStringOptions?: IStringifyOptions;
|
|
13
13
|
}
|
|
14
|
-
export declare function addExecutionDirectivesToComposer(
|
|
14
|
+
export declare function addExecutionDirectivesToComposer(subgraphName: string, { schemaComposer, logger, operations, operationHeaders, endpoint, queryParams, queryStringOptions, }: AddExecutionLogicToComposerOptions): Promise<SchemaComposer<any>>;
|
|
@@ -11,4 +11,4 @@ export interface AddExecutionLogicToComposerOptions {
|
|
|
11
11
|
queryParams?: Record<string, string | number | boolean>;
|
|
12
12
|
queryStringOptions?: IStringifyOptions;
|
|
13
13
|
}
|
|
14
|
-
export declare function addExecutionDirectivesToComposer(
|
|
14
|
+
export declare function addExecutionDirectivesToComposer(subgraphName: string, { schemaComposer, logger, operations, operationHeaders, endpoint, queryParams, queryStringOptions, }: AddExecutionLogicToComposerOptions): Promise<SchemaComposer<any>>;
|
|
@@ -12,4 +12,4 @@ export interface TypeComposers {
|
|
|
12
12
|
flatten?: boolean;
|
|
13
13
|
deprecated?: boolean;
|
|
14
14
|
}
|
|
15
|
-
export declare function getComposerFromJSONSchema(schema: JSONSchema, logger: Logger): Promise<TypeComposers>;
|
|
15
|
+
export declare function getComposerFromJSONSchema(subgraphName: string, schema: JSONSchema, logger: Logger): Promise<TypeComposers>;
|
|
@@ -12,4 +12,4 @@ export interface TypeComposers {
|
|
|
12
12
|
flatten?: boolean;
|
|
13
13
|
deprecated?: boolean;
|
|
14
14
|
}
|
|
15
|
-
export declare function getComposerFromJSONSchema(schema: JSONSchema, logger: Logger): Promise<TypeComposers>;
|
|
15
|
+
export declare function getComposerFromJSONSchema(subgraphName: string, schema: JSONSchema, logger: Logger): Promise<TypeComposers>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JSONSchemaObject } from 'json-machete';
|
|
2
2
|
import { AddExecutionLogicToComposerOptions } from './addExecutionLogicToComposer.cjs';
|
|
3
|
-
export declare function getGraphQLSchemaFromDereferencedJSONSchema(
|
|
3
|
+
export declare function getGraphQLSchemaFromDereferencedJSONSchema(subgraphName: string, opts: Omit<AddExecutionLogicToComposerOptions, 'schemaComposer'> & {
|
|
4
4
|
fullyDeferencedSchema: JSONSchemaObject;
|
|
5
5
|
}): Promise<import("graphql").GraphQLSchema>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { JSONSchemaObject } from 'json-machete';
|
|
2
2
|
import { AddExecutionLogicToComposerOptions } from './addExecutionLogicToComposer.js';
|
|
3
|
-
export declare function getGraphQLSchemaFromDereferencedJSONSchema(
|
|
3
|
+
export declare function getGraphQLSchemaFromDereferencedJSONSchema(subgraphName: string, opts: Omit<AddExecutionLogicToComposerOptions, 'schemaComposer'> & {
|
|
4
4
|
fullyDeferencedSchema: JSONSchemaObject;
|
|
5
5
|
}): Promise<import("graphql").GraphQLSchema>;
|
|
@@ -3,6 +3,7 @@ import { Logger } from '@graphql-mesh/types';
|
|
|
3
3
|
import { JSONSchemaObject } from '@json-schema-tools/meta-schema';
|
|
4
4
|
import { TypeComposers } from './getComposerFromJSONSchema.cjs';
|
|
5
5
|
export interface GetUnionTypeComposersOpts {
|
|
6
|
+
subgraphName: string;
|
|
6
7
|
schemaComposer: SchemaComposer;
|
|
7
8
|
typeComposersList: {
|
|
8
9
|
input?: AnyTypeComposer<any>;
|
|
@@ -11,5 +12,5 @@ export interface GetUnionTypeComposersOpts {
|
|
|
11
12
|
subSchemaAndTypeComposers: JSONSchemaObject & TypeComposers;
|
|
12
13
|
logger: Logger;
|
|
13
14
|
}
|
|
14
|
-
export declare function getContainerTC(schemaComposer: SchemaComposer, output: ComposeInputType): ObjectTypeComposer<any, any>;
|
|
15
|
-
export declare function getUnionTypeComposers({ schemaComposer, typeComposersList, subSchemaAndTypeComposers, logger, }: GetUnionTypeComposersOpts): TypeComposers;
|
|
15
|
+
export declare function getContainerTC(subgraphName: string, schemaComposer: SchemaComposer, output: ComposeInputType): ObjectTypeComposer<any, any>;
|
|
16
|
+
export declare function getUnionTypeComposers({ subgraphName, schemaComposer, typeComposersList, subSchemaAndTypeComposers, logger, }: GetUnionTypeComposersOpts): TypeComposers;
|
|
@@ -3,6 +3,7 @@ import { Logger } from '@graphql-mesh/types';
|
|
|
3
3
|
import { JSONSchemaObject } from '@json-schema-tools/meta-schema';
|
|
4
4
|
import { TypeComposers } from './getComposerFromJSONSchema.js';
|
|
5
5
|
export interface GetUnionTypeComposersOpts {
|
|
6
|
+
subgraphName: string;
|
|
6
7
|
schemaComposer: SchemaComposer;
|
|
7
8
|
typeComposersList: {
|
|
8
9
|
input?: AnyTypeComposer<any>;
|
|
@@ -11,5 +12,5 @@ export interface GetUnionTypeComposersOpts {
|
|
|
11
12
|
subSchemaAndTypeComposers: JSONSchemaObject & TypeComposers;
|
|
12
13
|
logger: Logger;
|
|
13
14
|
}
|
|
14
|
-
export declare function getContainerTC(schemaComposer: SchemaComposer, output: ComposeInputType): ObjectTypeComposer<any, any>;
|
|
15
|
-
export declare function getUnionTypeComposers({ schemaComposer, typeComposersList, subSchemaAndTypeComposers, logger, }: GetUnionTypeComposersOpts): TypeComposers;
|
|
15
|
+
export declare function getContainerTC(subgraphName: string, schemaComposer: SchemaComposer, output: ComposeInputType): ObjectTypeComposer<any, any>;
|
|
16
|
+
export declare function getUnionTypeComposers({ subgraphName, schemaComposer, typeComposersList, subSchemaAndTypeComposers, logger, }: GetUnionTypeComposersOpts): TypeComposers;
|