@omnigraph/json-schema 1.0.0-alpha-20220804093904-8e2e41f7f → 1.0.0-alpha-20230420220344-25b6b92bf

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 (89) hide show
  1. package/README.md +5 -4
  2. package/cjs/addExecutionLogicToComposer.js +208 -0
  3. package/cjs/addRootFieldResolver.js +395 -0
  4. package/cjs/bundle.js +65 -0
  5. package/cjs/directives.js +580 -0
  6. package/cjs/getComposerFromJSONSchema.js +1297 -0
  7. package/cjs/getDereferencedJSONSchemaFromOperations.js +33 -0
  8. package/cjs/getGraphQLSchemaFromDereferencedJSONSchema.js +39 -0
  9. package/cjs/getJSONSchemaStringFormatScalarMap.js +61 -0
  10. package/cjs/getReferencedJSONSchemaFromOperations.js +260 -0
  11. package/cjs/getTypeResolverFromOutputTCs.js +69 -0
  12. package/cjs/getUnionTypeComposers.js +85 -0
  13. package/cjs/getValidTypeName.js +20 -0
  14. package/cjs/index.js +14 -0
  15. package/cjs/loadGraphQLSchemaFromJSONSchemas.js +59 -0
  16. package/cjs/package.json +1 -0
  17. package/cjs/resolveDataByUnionInputType.js +40 -0
  18. package/cjs/scalars.js +30 -0
  19. package/cjs/types.js +0 -0
  20. package/cjs/utils.js +65 -0
  21. package/esm/addExecutionLogicToComposer.js +204 -0
  22. package/esm/addRootFieldResolver.js +390 -0
  23. package/esm/bundle.js +60 -0
  24. package/esm/directives.js +565 -0
  25. package/esm/getComposerFromJSONSchema.js +1293 -0
  26. package/esm/getDereferencedJSONSchemaFromOperations.js +29 -0
  27. package/esm/getGraphQLSchemaFromDereferencedJSONSchema.js +35 -0
  28. package/esm/getJSONSchemaStringFormatScalarMap.js +56 -0
  29. package/esm/getReferencedJSONSchemaFromOperations.js +255 -0
  30. package/esm/getTypeResolverFromOutputTCs.js +65 -0
  31. package/esm/getUnionTypeComposers.js +80 -0
  32. package/esm/getValidTypeName.js +16 -0
  33. package/esm/index.js +9 -0
  34. package/esm/loadGraphQLSchemaFromJSONSchemas.js +54 -0
  35. package/esm/resolveDataByUnionInputType.js +36 -0
  36. package/esm/scalars.js +27 -0
  37. package/esm/types.js +0 -0
  38. package/esm/utils.js +57 -0
  39. package/package.json +34 -27
  40. package/typings/addExecutionLogicToComposer.d.cts +14 -0
  41. package/typings/addExecutionLogicToComposer.d.ts +14 -0
  42. package/typings/addRootFieldResolver.d.cts +26 -0
  43. package/typings/addRootFieldResolver.d.ts +26 -0
  44. package/typings/bundle.d.cts +34 -0
  45. package/typings/bundle.d.ts +34 -0
  46. package/typings/directives.d.cts +54 -0
  47. package/typings/directives.d.ts +54 -0
  48. package/typings/getComposerFromJSONSchema.d.cts +13 -0
  49. package/{getComposerFromJSONSchema.d.ts → typings/getComposerFromJSONSchema.d.ts} +4 -1
  50. package/typings/getDereferencedJSONSchemaFromOperations.d.cts +14 -0
  51. package/{getDereferencedJSONSchemaFromOperations.d.ts → typings/getDereferencedJSONSchemaFromOperations.d.ts} +5 -3
  52. package/typings/getGraphQLSchemaFromDereferencedJSONSchema.d.cts +5 -0
  53. package/typings/getGraphQLSchemaFromDereferencedJSONSchema.d.ts +5 -0
  54. package/typings/getJSONSchemaStringFormatScalarMap.d.cts +2 -0
  55. package/typings/getJSONSchemaStringFormatScalarMap.d.ts +2 -0
  56. package/typings/getReferencedJSONSchemaFromOperations.d.cts +16 -0
  57. package/{getReferencedJSONSchemaFromOperations.d.ts → typings/getReferencedJSONSchemaFromOperations.d.ts} +6 -4
  58. package/typings/getTypeResolverFromOutputTCs.d.cts +7 -0
  59. package/typings/getTypeResolverFromOutputTCs.d.ts +7 -0
  60. package/typings/getUnionTypeComposers.d.cts +24 -0
  61. package/typings/getUnionTypeComposers.d.ts +24 -0
  62. package/{getStringScalarWithMinMaxLength.d.ts → typings/getValidTypeName.d.cts} +4 -3
  63. package/typings/index.d.cts +9 -0
  64. package/typings/index.d.ts +9 -0
  65. package/typings/loadGraphQLSchemaFromJSONSchemas.d.cts +3 -0
  66. package/typings/loadGraphQLSchemaFromJSONSchemas.d.ts +3 -0
  67. package/typings/resolveDataByUnionInputType.d.cts +2 -0
  68. package/typings/resolveDataByUnionInputType.d.ts +2 -0
  69. package/typings/scalars.d.cts +4 -0
  70. package/typings/scalars.d.ts +4 -0
  71. package/typings/types.d.cts +76 -0
  72. package/typings/types.d.ts +76 -0
  73. package/typings/utils.d.cts +15 -0
  74. package/{utils.d.ts → typings/utils.d.ts} +1 -1
  75. package/addExecutionLogicToComposer.d.ts +0 -15
  76. package/bundle.d.ts +0 -39
  77. package/getGenericJSONScalar.d.ts +0 -8
  78. package/getGraphQLSchemaFromDereferencedJSONSchema.d.ts +0 -3
  79. package/getJSONSchemaStringFormatScalarMap.d.ts +0 -3
  80. package/getTypeResolverFromOutputTCs.d.ts +0 -4
  81. package/getUnionTypeComposers.d.ts +0 -17
  82. package/getValidateFnForSchemaPath.d.ts +0 -3
  83. package/index.d.ts +0 -9
  84. package/index.js +0 -1908
  85. package/index.mjs +0 -1895
  86. package/loadGraphQLSchemaFromJSONSchemas.d.ts +0 -2
  87. package/resolveDataByUnionInputType.d.ts +0 -3
  88. package/types.d.ts +0 -62
  89. package/{getValidTypeName.d.ts → typings/getValidTypeName.d.ts} +1 -1
@@ -0,0 +1,565 @@
1
+ import { dset } from 'dset';
2
+ import { DirectiveLocation, GraphQLBoolean, GraphQLDirective, GraphQLEnumType, GraphQLID, GraphQLInt, GraphQLString, isEnumType, isInterfaceType, isListType, isNonNullType, isScalarType, isUnionType, } from 'graphql';
3
+ import { resolvers as scalarResolvers } from 'graphql-scalars';
4
+ import { stringInterpolator } from '@graphql-mesh/string-interpolation';
5
+ import { createGraphQLError, getDirective, getDirectives } from '@graphql-tools/utils';
6
+ import { addHTTPRootFieldResolver, } from './addRootFieldResolver.js';
7
+ import { getTypeResolverFromOutputTCs } from './getTypeResolverFromOutputTCs.js';
8
+ import { ObjMapScalar } from './scalars.js';
9
+ export const LengthDirective = new GraphQLDirective({
10
+ name: 'length',
11
+ locations: [DirectiveLocation.SCALAR],
12
+ args: {
13
+ min: {
14
+ type: GraphQLInt,
15
+ },
16
+ max: {
17
+ type: GraphQLInt,
18
+ },
19
+ },
20
+ });
21
+ export function processLengthAnnotations(scalar, { min: minLength, max: maxLength, }) {
22
+ function coerceString(value) {
23
+ if (value != null) {
24
+ const vStr = value.toString();
25
+ if (typeof minLength !== 'undefined' && vStr.length < minLength) {
26
+ throw new Error(`${scalar.name} cannot be less than ${minLength} but given ${vStr}`);
27
+ }
28
+ if (typeof maxLength !== 'undefined' && vStr.length > maxLength) {
29
+ throw new Error(`${scalar.name} cannot be more than ${maxLength} but given ${vStr}`);
30
+ }
31
+ return vStr;
32
+ }
33
+ }
34
+ scalar.serialize = coerceString;
35
+ scalar.parseValue = coerceString;
36
+ scalar.parseLiteral = ast => {
37
+ if ('value' in ast) {
38
+ return coerceString(ast.value);
39
+ }
40
+ return null;
41
+ };
42
+ }
43
+ export const DiscriminatorDirective = new GraphQLDirective({
44
+ name: 'discriminator',
45
+ locations: [DirectiveLocation.INTERFACE, DirectiveLocation.UNION],
46
+ args: {
47
+ field: {
48
+ type: GraphQLString,
49
+ },
50
+ mapping: {
51
+ type: ObjMapScalar,
52
+ },
53
+ },
54
+ });
55
+ export function processDiscriminatorAnnotations({ interfaceType, discriminatorFieldName, }) {
56
+ interfaceType.resolveType = root => root[discriminatorFieldName];
57
+ }
58
+ export const ResolveRootDirective = new GraphQLDirective({
59
+ name: 'resolveRoot',
60
+ locations: [DirectiveLocation.FIELD_DEFINITION],
61
+ });
62
+ export function processResolveRootAnnotations(field) {
63
+ field.resolve = root => root;
64
+ }
65
+ export const ResolveRootFieldDirective = new GraphQLDirective({
66
+ name: 'resolveRootField',
67
+ locations: [
68
+ DirectiveLocation.FIELD_DEFINITION,
69
+ DirectiveLocation.ARGUMENT_DEFINITION,
70
+ DirectiveLocation.INPUT_FIELD_DEFINITION,
71
+ ],
72
+ args: {
73
+ field: {
74
+ type: GraphQLString,
75
+ },
76
+ },
77
+ });
78
+ function isOriginallyListType(type) {
79
+ if (isNonNullType(type)) {
80
+ return isOriginallyListType(type.ofType);
81
+ }
82
+ return isListType(type);
83
+ }
84
+ export function processResolveRootFieldAnnotations(field, propertyName) {
85
+ if (!field.resolve || field.resolve.name === 'defaultFieldResolver') {
86
+ field.resolve = (root, args, context, info) => {
87
+ const actualFieldObj = root[propertyName];
88
+ if (actualFieldObj != null) {
89
+ const isArray = Array.isArray(actualFieldObj);
90
+ const isListType = isOriginallyListType(info.returnType);
91
+ if (isListType && !isArray) {
92
+ return [actualFieldObj];
93
+ }
94
+ else if (!isListType && isArray) {
95
+ return actualFieldObj[0];
96
+ }
97
+ }
98
+ return actualFieldObj;
99
+ };
100
+ }
101
+ }
102
+ export const RegExpDirective = new GraphQLDirective({
103
+ name: 'regexp',
104
+ locations: [DirectiveLocation.SCALAR],
105
+ args: {
106
+ pattern: {
107
+ type: GraphQLString,
108
+ },
109
+ },
110
+ });
111
+ export function processRegExpAnnotations(scalar, pattern) {
112
+ function coerceString(value) {
113
+ if (value != null) {
114
+ const vStr = value.toString();
115
+ const regexp = new RegExp(pattern);
116
+ if (!regexp.test(vStr)) {
117
+ throw new Error(`${scalar.name} must match ${pattern} but given ${vStr}`);
118
+ }
119
+ return vStr;
120
+ }
121
+ }
122
+ scalar.serialize = coerceString;
123
+ scalar.parseValue = coerceString;
124
+ scalar.parseLiteral = ast => {
125
+ if ('value' in ast) {
126
+ return coerceString(ast.value);
127
+ }
128
+ return null;
129
+ };
130
+ }
131
+ export const PubSubOperationDirective = new GraphQLDirective({
132
+ name: 'pubsubOperation',
133
+ locations: [DirectiveLocation.FIELD_DEFINITION],
134
+ args: {
135
+ pubsubTopic: {
136
+ type: GraphQLString,
137
+ },
138
+ },
139
+ });
140
+ export function processPubSubOperationAnnotations({ field, globalPubsub, pubsubTopic, logger, }) {
141
+ field.subscribe = (root, args, context, info) => {
142
+ const operationLogger = logger.child(`${info.parentType.name}.${field.name}`);
143
+ const pubsub = (context === null || context === void 0 ? void 0 : context.pubsub) || globalPubsub;
144
+ if (!pubsub) {
145
+ return createGraphQLError(`You should have PubSub defined in either the config or the context!`);
146
+ }
147
+ const interpolationData = { root, args, context, info, env: process.env };
148
+ let interpolatedPubSubTopic = stringInterpolator.parse(pubsubTopic, interpolationData);
149
+ if (interpolatedPubSubTopic.startsWith('webhook:')) {
150
+ const [, expectedMethod, expectedUrl] = interpolatedPubSubTopic.split(':');
151
+ const expectedPath = new URL(expectedUrl, 'http://localhost').pathname;
152
+ interpolatedPubSubTopic = `webhook:${expectedMethod}:${expectedPath}`;
153
+ }
154
+ operationLogger.debug(`=> Subscribing to pubSubTopic: ${interpolatedPubSubTopic}`);
155
+ return pubsub.asyncIterator(interpolatedPubSubTopic);
156
+ };
157
+ field.resolve = (root, args, context, info) => {
158
+ const operationLogger = logger.child(`${info.parentType.name}.${field.name}`);
159
+ operationLogger.debug('Received ', root, ' from ', pubsubTopic);
160
+ return root;
161
+ };
162
+ }
163
+ export const TypeScriptDirective = new GraphQLDirective({
164
+ name: 'typescript',
165
+ locations: [DirectiveLocation.SCALAR, DirectiveLocation.ENUM],
166
+ args: {
167
+ type: {
168
+ type: GraphQLString,
169
+ },
170
+ },
171
+ });
172
+ export function processTypeScriptAnnotations(type, typeDefinition) {
173
+ type.extensions = type.extensions || {};
174
+ type.extensions.codegenScalarType = typeDefinition;
175
+ }
176
+ function addExecutionLogicToScalar(nonExecutableScalar, actualScalar) {
177
+ Object.defineProperties(nonExecutableScalar, {
178
+ serialize: {
179
+ value: actualScalar.serialize,
180
+ },
181
+ parseValue: {
182
+ value: actualScalar.parseValue,
183
+ },
184
+ parseLiteral: {
185
+ value: actualScalar.parseLiteral,
186
+ },
187
+ extensions: {
188
+ value: {
189
+ ...actualScalar.extensions,
190
+ ...nonExecutableScalar.extensions,
191
+ },
192
+ },
193
+ });
194
+ }
195
+ export function processScalarType(schema, type) {
196
+ if (type.name in scalarResolvers) {
197
+ const actualScalar = scalarResolvers[type.name];
198
+ addExecutionLogicToScalar(type, actualScalar);
199
+ }
200
+ if (type.name === 'ObjMap') {
201
+ addExecutionLogicToScalar(type, ObjMapScalar);
202
+ }
203
+ const directiveAnnotations = getDirectives(schema, type);
204
+ for (const directiveAnnotation of directiveAnnotations) {
205
+ switch (directiveAnnotation.name) {
206
+ case 'length':
207
+ processLengthAnnotations(type, directiveAnnotation.args);
208
+ break;
209
+ case 'regexp':
210
+ processRegExpAnnotations(type, directiveAnnotation.args.pattern);
211
+ break;
212
+ case 'typescript':
213
+ processTypeScriptAnnotations(type, directiveAnnotation.args.type);
214
+ break;
215
+ }
216
+ }
217
+ }
218
+ export const HTTPOperationDirective = new GraphQLDirective({
219
+ name: 'httpOperation',
220
+ locations: [DirectiveLocation.FIELD_DEFINITION],
221
+ args: {
222
+ path: {
223
+ type: GraphQLString,
224
+ },
225
+ operationSpecificHeaders: {
226
+ type: ObjMapScalar,
227
+ },
228
+ httpMethod: {
229
+ type: new GraphQLEnumType({
230
+ name: 'HTTPMethod',
231
+ values: {
232
+ GET: { value: 'GET' },
233
+ HEAD: { value: 'HEAD' },
234
+ POST: { value: 'POST' },
235
+ PUT: { value: 'PUT' },
236
+ DELETE: { value: 'DELETE' },
237
+ CONNECT: { value: 'CONNECT' },
238
+ OPTIONS: { value: 'OPTIONS' },
239
+ TRACE: { value: 'TRACE' },
240
+ PATCH: { value: 'PATCH' },
241
+ },
242
+ }),
243
+ },
244
+ isBinary: {
245
+ type: GraphQLBoolean,
246
+ },
247
+ requestBaseBody: {
248
+ type: ObjMapScalar,
249
+ },
250
+ queryParamArgMap: {
251
+ type: ObjMapScalar,
252
+ },
253
+ queryStringOptionsByParam: {
254
+ type: ObjMapScalar,
255
+ },
256
+ },
257
+ });
258
+ export const GlobalOptionsDirective = new GraphQLDirective({
259
+ name: 'globalOptions',
260
+ locations: [DirectiveLocation.OBJECT],
261
+ args: {
262
+ sourceName: {
263
+ type: GraphQLString,
264
+ },
265
+ endpoint: {
266
+ type: GraphQLString,
267
+ },
268
+ operationHeaders: {
269
+ type: ObjMapScalar,
270
+ },
271
+ queryStringOptions: {
272
+ type: ObjMapScalar,
273
+ },
274
+ queryParams: {
275
+ type: ObjMapScalar,
276
+ },
277
+ },
278
+ });
279
+ export const ResponseMetadataDirective = new GraphQLDirective({
280
+ name: 'responseMetadata',
281
+ locations: [DirectiveLocation.FIELD_DEFINITION],
282
+ });
283
+ export function processResponseMetadataAnnotations(field) {
284
+ field.resolve = function responseMetadataResolver(root) {
285
+ return {
286
+ url: root.$url,
287
+ headers: root.$response.header,
288
+ method: root.$method,
289
+ status: root.$statusCode,
290
+ statusText: root.$statusText,
291
+ body: root.$response.body,
292
+ };
293
+ };
294
+ }
295
+ export const LinkDirective = new GraphQLDirective({
296
+ name: 'link',
297
+ locations: [DirectiveLocation.FIELD_DEFINITION],
298
+ args: {
299
+ defaultRootType: {
300
+ type: GraphQLString,
301
+ },
302
+ defaultField: {
303
+ type: GraphQLString,
304
+ },
305
+ },
306
+ });
307
+ export const LinkResolverDirective = new GraphQLDirective({
308
+ name: 'linkResolver',
309
+ locations: [DirectiveLocation.FIELD_DEFINITION],
310
+ args: {
311
+ linkResolverMap: {
312
+ type: ObjMapScalar,
313
+ },
314
+ },
315
+ });
316
+ function linkResolver({ linkObjArgs, targetTypeName, targetFieldName }, { root, args, context, info, env }) {
317
+ for (const argKey in linkObjArgs) {
318
+ const argInterpolation = linkObjArgs[argKey];
319
+ const actualValue = typeof argInterpolation === 'string'
320
+ ? stringInterpolator.parse(argInterpolation, {
321
+ root,
322
+ args,
323
+ context,
324
+ info,
325
+ env,
326
+ })
327
+ : argInterpolation;
328
+ dset(args, argKey, actualValue);
329
+ }
330
+ const type = info.schema.getType(targetTypeName);
331
+ const field = type.getFields()[targetFieldName];
332
+ return field.resolve(root, args, context, info);
333
+ }
334
+ function getLinkResolverMap(schema, field) {
335
+ const parentFieldLinkResolverDirectives = getDirective(schema, field, 'linkResolver');
336
+ if (parentFieldLinkResolverDirectives === null || parentFieldLinkResolverDirectives === void 0 ? void 0 : parentFieldLinkResolverDirectives.length) {
337
+ const linkResolverMap = parentFieldLinkResolverDirectives[0].linkResolverMap;
338
+ if (linkResolverMap) {
339
+ return linkResolverMap;
340
+ }
341
+ }
342
+ }
343
+ function findLinkResolverMap({ schema, operationType, defaultRootTypeName, defaultFieldName, }) {
344
+ const parentType = schema.getRootType(operationType);
345
+ const parentField = parentType.getFields()[operationType];
346
+ if (parentField) {
347
+ const linkResolverMap = getLinkResolverMap(schema, parentField);
348
+ if (linkResolverMap) {
349
+ return linkResolverMap;
350
+ }
351
+ }
352
+ const defaultRootType = schema.getType(defaultRootTypeName);
353
+ if (defaultRootType) {
354
+ const defaultField = defaultRootType.getFields()[defaultFieldName];
355
+ if (defaultField) {
356
+ const linkResolverMap = getLinkResolverMap(schema, defaultField);
357
+ if (linkResolverMap) {
358
+ return linkResolverMap;
359
+ }
360
+ }
361
+ }
362
+ }
363
+ export function processLinkFieldAnnotations(field, defaultRootTypeName, defaultFieldName) {
364
+ field.resolve = (root, args, context, info) => {
365
+ const linkResolverMap = findLinkResolverMap({
366
+ schema: info.schema,
367
+ defaultRootTypeName,
368
+ defaultFieldName,
369
+ parentFieldName: root.$field,
370
+ operationType: info.operation.operation,
371
+ });
372
+ const linkResolverOpts = linkResolverMap[field.name];
373
+ return linkResolver(linkResolverOpts, { root, args, context, info, env: process.env });
374
+ };
375
+ }
376
+ export const DictionaryDirective = new GraphQLDirective({
377
+ name: 'dictionary',
378
+ locations: [DirectiveLocation.FIELD_DEFINITION],
379
+ });
380
+ export function processDictionaryDirective(fieldMap, field) {
381
+ field.resolve = root => {
382
+ const result = [];
383
+ for (const key in root) {
384
+ if (key in fieldMap) {
385
+ continue;
386
+ }
387
+ result.push({
388
+ key,
389
+ value: root[key],
390
+ });
391
+ }
392
+ return result;
393
+ };
394
+ }
395
+ export function processDirectives({ schema, globalFetch, logger, pubsub, ...extraGlobalOptions }) {
396
+ const nonExecutableObjMapScalar = schema.getType('ObjMap');
397
+ if (nonExecutableObjMapScalar && isScalarType(nonExecutableObjMapScalar)) {
398
+ addExecutionLogicToScalar(nonExecutableObjMapScalar, ObjMapScalar);
399
+ }
400
+ let [globalOptions = {}] = (getDirective(schema, schema.getQueryType(), 'globalOptions') ||
401
+ []);
402
+ globalOptions = {
403
+ ...globalOptions,
404
+ ...extraGlobalOptions,
405
+ };
406
+ const typeMap = schema.getTypeMap();
407
+ for (const typeName in typeMap) {
408
+ const type = typeMap[typeName];
409
+ const exampleAnnotations = getDirective(schema, type, 'example');
410
+ if (exampleAnnotations === null || exampleAnnotations === void 0 ? void 0 : exampleAnnotations.length) {
411
+ const examples = [];
412
+ for (const exampleAnnotation of exampleAnnotations) {
413
+ if (exampleAnnotation === null || exampleAnnotation === void 0 ? void 0 : exampleAnnotation.value) {
414
+ examples.push(exampleAnnotation.value);
415
+ }
416
+ }
417
+ type.extensions = type.extensions || {};
418
+ type.extensions.examples = examples;
419
+ }
420
+ if (isScalarType(type)) {
421
+ processScalarType(schema, type);
422
+ }
423
+ if (isInterfaceType(type)) {
424
+ const directiveAnnotations = getDirectives(schema, type);
425
+ for (const directiveAnnotation of directiveAnnotations) {
426
+ switch (directiveAnnotation.name) {
427
+ case 'discriminator':
428
+ processDiscriminatorAnnotations({
429
+ interfaceType: type,
430
+ discriminatorFieldName: directiveAnnotation.args.field,
431
+ });
432
+ break;
433
+ }
434
+ }
435
+ }
436
+ if (isUnionType(type)) {
437
+ const directiveAnnotations = getDirectives(schema, type);
438
+ let statusCodeTypeNameIndexMap;
439
+ let discriminatorField;
440
+ let discriminatorMapping;
441
+ for (const directiveAnnotation of directiveAnnotations) {
442
+ switch (directiveAnnotation.name) {
443
+ case 'statusCodeTypeName':
444
+ statusCodeTypeNameIndexMap = statusCodeTypeNameIndexMap || {};
445
+ statusCodeTypeNameIndexMap[directiveAnnotation.args.statusCode] =
446
+ directiveAnnotation.args.typeName;
447
+ break;
448
+ case 'discriminator':
449
+ discriminatorField = directiveAnnotation.args.field;
450
+ discriminatorMapping = directiveAnnotation.args.mapping;
451
+ break;
452
+ }
453
+ }
454
+ type.resolveType = getTypeResolverFromOutputTCs({
455
+ possibleTypes: type.getTypes(),
456
+ discriminatorField,
457
+ discriminatorMapping,
458
+ statusCodeTypeNameMap: statusCodeTypeNameIndexMap,
459
+ });
460
+ }
461
+ if (isEnumType(type)) {
462
+ const directiveAnnotations = getDirectives(schema, type);
463
+ for (const directiveAnnotation of directiveAnnotations) {
464
+ switch (directiveAnnotation.name) {
465
+ case 'typescript':
466
+ processTypeScriptAnnotations(type, directiveAnnotation.args.type);
467
+ break;
468
+ }
469
+ }
470
+ const enumValues = type.getValues();
471
+ for (const enumValue of enumValues) {
472
+ const directiveAnnotations = getDirectives(schema, enumValue);
473
+ for (const directiveAnnotation of directiveAnnotations) {
474
+ switch (directiveAnnotation.name) {
475
+ case 'enum': {
476
+ const realValue = JSON.parse(directiveAnnotation.args.value);
477
+ enumValue.value = realValue;
478
+ type._valueLookup.set(realValue, enumValue);
479
+ break;
480
+ }
481
+ }
482
+ }
483
+ }
484
+ }
485
+ if ('getFields' in type) {
486
+ const fields = type.getFields();
487
+ for (const fieldName in fields) {
488
+ const field = fields[fieldName];
489
+ const directiveAnnotations = getDirectives(schema, field);
490
+ for (const directiveAnnotation of directiveAnnotations) {
491
+ switch (directiveAnnotation.name) {
492
+ case 'resolveRoot':
493
+ processResolveRootAnnotations(field);
494
+ break;
495
+ case 'resolveRootField':
496
+ processResolveRootFieldAnnotations(field, directiveAnnotation.args.field);
497
+ break;
498
+ case 'pubsubOperation':
499
+ processPubSubOperationAnnotations({
500
+ field: field,
501
+ pubsubTopic: directiveAnnotation.args.pubsubTopic,
502
+ globalPubsub: pubsub,
503
+ logger,
504
+ });
505
+ break;
506
+ case 'httpOperation':
507
+ addHTTPRootFieldResolver(schema, field, logger, globalFetch, directiveAnnotation.args, globalOptions);
508
+ break;
509
+ case 'responseMetadata':
510
+ processResponseMetadataAnnotations(field);
511
+ break;
512
+ case 'link':
513
+ processLinkFieldAnnotations(field, directiveAnnotation.args.defaultRootType, directiveAnnotation.args.defaultField);
514
+ break;
515
+ case 'dictionary':
516
+ processDictionaryDirective(fields, field);
517
+ }
518
+ }
519
+ }
520
+ }
521
+ }
522
+ return schema;
523
+ }
524
+ export const StatusCodeTypeNameDirective = new GraphQLDirective({
525
+ name: 'statusCodeTypeName',
526
+ locations: [DirectiveLocation.UNION],
527
+ isRepeatable: true,
528
+ args: {
529
+ typeName: {
530
+ type: GraphQLString,
531
+ },
532
+ statusCode: {
533
+ type: GraphQLID,
534
+ },
535
+ },
536
+ });
537
+ export const EnumDirective = new GraphQLDirective({
538
+ name: 'enum',
539
+ locations: [DirectiveLocation.ENUM_VALUE],
540
+ args: {
541
+ value: {
542
+ type: GraphQLString,
543
+ },
544
+ },
545
+ });
546
+ export const OneOfDirective = new GraphQLDirective({
547
+ name: 'oneOf',
548
+ locations: [DirectiveLocation.OBJECT, DirectiveLocation.INTERFACE],
549
+ });
550
+ export const ExampleDirective = new GraphQLDirective({
551
+ name: 'example',
552
+ locations: [
553
+ DirectiveLocation.FIELD_DEFINITION,
554
+ DirectiveLocation.OBJECT,
555
+ DirectiveLocation.INPUT_OBJECT,
556
+ DirectiveLocation.ENUM,
557
+ DirectiveLocation.SCALAR,
558
+ ],
559
+ args: {
560
+ value: {
561
+ type: ObjMapScalar,
562
+ },
563
+ },
564
+ isRepeatable: true,
565
+ });