@graphql-tools/utils 7.3.0 → 7.5.0
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/es5/index.cjs.js +63 -25
- package/es5/index.cjs.js.map +1 -1
- package/es5/index.esm.js +57 -24
- package/es5/index.esm.js.map +1 -1
- package/es5/package.json +1 -1
- package/es5/print-schema-with-directives.d.ts +9 -4
- package/es5/types.d.ts +2 -1
- package/index.cjs.js +62 -25
- package/index.cjs.js.map +1 -1
- package/index.esm.js +56 -24
- package/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/print-schema-with-directives.d.ts +9 -4
- package/types.d.ts +2 -1
package/es5/index.cjs.js
CHANGED
|
@@ -496,15 +496,13 @@ function astFromValueUntyped(value) {
|
|
|
496
496
|
*/
|
|
497
497
|
var integerStringRegExp = /^-?(?:0|[1-9][0-9]*)$/;
|
|
498
498
|
|
|
499
|
-
|
|
500
|
-
// currently does not allow customization of printSchema options having to do with comments.
|
|
501
|
-
function printSchemaWithDirectives(schema, options) {
|
|
499
|
+
function getDocumentNodeFromSchema(schema, options) {
|
|
502
500
|
var e_1, _a;
|
|
503
501
|
if (options === void 0) { options = {}; }
|
|
504
502
|
var pathToDirectivesInExtensions = options.pathToDirectivesInExtensions;
|
|
505
503
|
var typesMap = schema.getTypeMap();
|
|
506
504
|
var schemaNode = astFromSchema(schema, pathToDirectivesInExtensions);
|
|
507
|
-
var
|
|
505
|
+
var definitions = schemaNode != null ? [schemaNode] : [];
|
|
508
506
|
for (var typeName in typesMap) {
|
|
509
507
|
var type = typesMap[typeName];
|
|
510
508
|
var isPredefinedScalar = graphql.isSpecifiedScalarType(type);
|
|
@@ -513,22 +511,22 @@ function printSchemaWithDirectives(schema, options) {
|
|
|
513
511
|
continue;
|
|
514
512
|
}
|
|
515
513
|
if (graphql.isObjectType(type)) {
|
|
516
|
-
|
|
514
|
+
definitions.push(astFromObjectType(type, schema, pathToDirectivesInExtensions));
|
|
517
515
|
}
|
|
518
516
|
else if (graphql.isInterfaceType(type)) {
|
|
519
|
-
|
|
517
|
+
definitions.push(astFromInterfaceType(type, schema, pathToDirectivesInExtensions));
|
|
520
518
|
}
|
|
521
519
|
else if (graphql.isUnionType(type)) {
|
|
522
|
-
|
|
520
|
+
definitions.push(astFromUnionType(type, schema, pathToDirectivesInExtensions));
|
|
523
521
|
}
|
|
524
522
|
else if (graphql.isInputObjectType(type)) {
|
|
525
|
-
|
|
523
|
+
definitions.push(astFromInputObjectType(type, schema, pathToDirectivesInExtensions));
|
|
526
524
|
}
|
|
527
525
|
else if (graphql.isEnumType(type)) {
|
|
528
|
-
|
|
526
|
+
definitions.push(astFromEnumType(type, schema, pathToDirectivesInExtensions));
|
|
529
527
|
}
|
|
530
528
|
else if (graphql.isScalarType(type)) {
|
|
531
|
-
|
|
529
|
+
definitions.push(astFromScalarType(type, schema, pathToDirectivesInExtensions));
|
|
532
530
|
}
|
|
533
531
|
else {
|
|
534
532
|
throw new Error("Unknown type " + type + ".");
|
|
@@ -541,7 +539,7 @@ function printSchemaWithDirectives(schema, options) {
|
|
|
541
539
|
if (graphql.isSpecifiedDirective(directive)) {
|
|
542
540
|
continue;
|
|
543
541
|
}
|
|
544
|
-
|
|
542
|
+
definitions.push(astFromDirective(directive, schema, pathToDirectivesInExtensions));
|
|
545
543
|
}
|
|
546
544
|
}
|
|
547
545
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
@@ -551,7 +549,17 @@ function printSchemaWithDirectives(schema, options) {
|
|
|
551
549
|
}
|
|
552
550
|
finally { if (e_1) throw e_1.error; }
|
|
553
551
|
}
|
|
554
|
-
return
|
|
552
|
+
return {
|
|
553
|
+
kind: graphql.Kind.DOCUMENT,
|
|
554
|
+
definitions: definitions,
|
|
555
|
+
};
|
|
556
|
+
}
|
|
557
|
+
// this approach uses the default schema printer rather than a custom solution, so may be more backwards compatible
|
|
558
|
+
// currently does not allow customization of printSchema options having to do with comments.
|
|
559
|
+
function printSchemaWithDirectives(schema, options) {
|
|
560
|
+
if (options === void 0) { options = {}; }
|
|
561
|
+
var documentNode = getDocumentNodeFromSchema(schema, options);
|
|
562
|
+
return graphql.print(documentNode);
|
|
555
563
|
}
|
|
556
564
|
function astFromSchema(schema, pathToDirectivesInExtensions) {
|
|
557
565
|
var _a, _b;
|
|
@@ -647,7 +655,7 @@ function getDirectiveNodes(entity, schema, pathToDirectivesInExtensions) {
|
|
|
647
655
|
}
|
|
648
656
|
var directives;
|
|
649
657
|
if (directivesInExtensions != null) {
|
|
650
|
-
directives =
|
|
658
|
+
directives = makeDirectiveNodes(schema, directivesInExtensions);
|
|
651
659
|
}
|
|
652
660
|
else {
|
|
653
661
|
directives = [].concat.apply([], tslib.__spread(nodes.filter(function (node) { return node.directives != null; }).map(function (node) { return node.directives; })));
|
|
@@ -661,7 +669,7 @@ function getDeprecatableDirectiveNodes(entity, schema, pathToDirectivesInExtensi
|
|
|
661
669
|
var directivesInExtensions = getDirectivesInExtensions(entity, pathToDirectivesInExtensions);
|
|
662
670
|
var directives;
|
|
663
671
|
if (directivesInExtensions != null) {
|
|
664
|
-
directives =
|
|
672
|
+
directives = makeDirectiveNodes(schema, directivesInExtensions);
|
|
665
673
|
}
|
|
666
674
|
else {
|
|
667
675
|
directives = (_a = entity.astNode) === null || _a === void 0 ? void 0 : _a.directives;
|
|
@@ -797,10 +805,34 @@ function astFromEnumType(type, schema, pathToDirectivesInExtensions) {
|
|
|
797
805
|
};
|
|
798
806
|
}
|
|
799
807
|
function astFromScalarType(type, schema, pathToDirectivesInExtensions) {
|
|
800
|
-
var _a, _b;
|
|
808
|
+
var _a, _b, _c, _d;
|
|
809
|
+
var directiveNodesBesidesSpecifiedBy = [];
|
|
810
|
+
var specifiedByDirectiveNode;
|
|
811
|
+
var directivesInExtensions = getDirectivesInExtensions(type, pathToDirectivesInExtensions);
|
|
812
|
+
var allDirectives;
|
|
813
|
+
if (directivesInExtensions != null) {
|
|
814
|
+
allDirectives = makeDirectiveNodes(schema, directivesInExtensions);
|
|
815
|
+
}
|
|
816
|
+
else {
|
|
817
|
+
allDirectives = (_a = type.astNode) === null || _a === void 0 ? void 0 : _a.directives;
|
|
818
|
+
}
|
|
819
|
+
if (allDirectives != null) {
|
|
820
|
+
directiveNodesBesidesSpecifiedBy = allDirectives.filter(function (directive) { return directive.name.value !== 'specifiedBy'; });
|
|
821
|
+
if (type.specifiedByUrl != null) {
|
|
822
|
+
specifiedByDirectiveNode = (_b = allDirectives.filter(function (directive) { return directive.name.value === 'specifiedBy'; })) === null || _b === void 0 ? void 0 : _b[0];
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
if (type.specifiedByUrl != null && specifiedByDirectiveNode == null) {
|
|
826
|
+
specifiedByDirectiveNode = makeDirectiveNode('specifiedBy', {
|
|
827
|
+
url: type.specifiedByUrl,
|
|
828
|
+
});
|
|
829
|
+
}
|
|
830
|
+
var directives = specifiedByDirectiveNode == null
|
|
831
|
+
? directiveNodesBesidesSpecifiedBy
|
|
832
|
+
: [specifiedByDirectiveNode].concat(directiveNodesBesidesSpecifiedBy);
|
|
801
833
|
return {
|
|
802
834
|
kind: graphql.Kind.SCALAR_TYPE_DEFINITION,
|
|
803
|
-
description: ((
|
|
835
|
+
description: ((_d = (_c = type.astNode) === null || _c === void 0 ? void 0 : _c.description) !== null && _d !== void 0 ? _d : type.description) ? {
|
|
804
836
|
kind: graphql.Kind.STRING,
|
|
805
837
|
value: type.description,
|
|
806
838
|
block: true,
|
|
@@ -810,7 +842,7 @@ function astFromScalarType(type, schema, pathToDirectivesInExtensions) {
|
|
|
810
842
|
kind: graphql.Kind.NAME,
|
|
811
843
|
value: type.name,
|
|
812
844
|
},
|
|
813
|
-
directives:
|
|
845
|
+
directives: directives,
|
|
814
846
|
};
|
|
815
847
|
}
|
|
816
848
|
function astFromField(field, schema, pathToDirectivesInExtensions) {
|
|
@@ -848,6 +880,7 @@ function astFromInputField(field, schema, pathToDirectivesInExtensions) {
|
|
|
848
880
|
},
|
|
849
881
|
type: astFromType(field.type),
|
|
850
882
|
directives: getDeprecatableDirectiveNodes(field, schema, pathToDirectivesInExtensions),
|
|
883
|
+
defaultValue: graphql.astFromValue(field.defaultValue, field.type),
|
|
851
884
|
};
|
|
852
885
|
}
|
|
853
886
|
function astFromEnumValue(value, schema, pathToDirectivesInExtensions) {
|
|
@@ -868,9 +901,9 @@ function astFromEnumValue(value, schema, pathToDirectivesInExtensions) {
|
|
|
868
901
|
};
|
|
869
902
|
}
|
|
870
903
|
function makeDeprecatedDirective(deprecationReason) {
|
|
871
|
-
return
|
|
904
|
+
return makeDirectiveNode('deprecated', { reason: deprecationReason }, graphql.GraphQLDeprecatedDirective);
|
|
872
905
|
}
|
|
873
|
-
function
|
|
906
|
+
function makeDirectiveNode(name, args, directive) {
|
|
874
907
|
var directiveArguments = [];
|
|
875
908
|
if (directive != null) {
|
|
876
909
|
directive.args.forEach(function (arg) {
|
|
@@ -910,18 +943,18 @@ function makeDirective(name, args, directive) {
|
|
|
910
943
|
arguments: directiveArguments,
|
|
911
944
|
};
|
|
912
945
|
}
|
|
913
|
-
function
|
|
946
|
+
function makeDirectiveNodes(schema, directiveValues) {
|
|
914
947
|
var directiveNodes = [];
|
|
915
948
|
Object.entries(directiveValues).forEach(function (_a) {
|
|
916
949
|
var _b = tslib.__read(_a, 2), directiveName = _b[0], arrayOrSingleValue = _b[1];
|
|
917
950
|
var directive = schema.getDirective(directiveName);
|
|
918
951
|
if (Array.isArray(arrayOrSingleValue)) {
|
|
919
952
|
arrayOrSingleValue.forEach(function (value) {
|
|
920
|
-
directiveNodes.push(
|
|
953
|
+
directiveNodes.push(makeDirectiveNode(directiveName, value, directive));
|
|
921
954
|
});
|
|
922
955
|
}
|
|
923
956
|
else {
|
|
924
|
-
directiveNodes.push(
|
|
957
|
+
directiveNodes.push(makeDirectiveNode(directiveName, arrayOrSingleValue, directive));
|
|
925
958
|
}
|
|
926
959
|
});
|
|
927
960
|
return directiveNodes;
|
|
@@ -4292,7 +4325,7 @@ function isAsyncIterable(value) {
|
|
|
4292
4325
|
}
|
|
4293
4326
|
|
|
4294
4327
|
function isDocumentNode(object) {
|
|
4295
|
-
return object.kind
|
|
4328
|
+
return object && typeof object === 'object' && 'kind' in object && object.kind === graphql.Kind.DOCUMENT;
|
|
4296
4329
|
}
|
|
4297
4330
|
|
|
4298
4331
|
exports.SchemaDirectiveVisitor = SchemaDirectiveVisitor;
|
|
@@ -4305,9 +4338,13 @@ exports.asArray = asArray;
|
|
|
4305
4338
|
exports.astFromArg = astFromArg;
|
|
4306
4339
|
exports.astFromDirective = astFromDirective;
|
|
4307
4340
|
exports.astFromEnumType = astFromEnumType;
|
|
4341
|
+
exports.astFromEnumValue = astFromEnumValue;
|
|
4342
|
+
exports.astFromField = astFromField;
|
|
4343
|
+
exports.astFromInputField = astFromInputField;
|
|
4308
4344
|
exports.astFromInputObjectType = astFromInputObjectType;
|
|
4309
4345
|
exports.astFromInterfaceType = astFromInterfaceType;
|
|
4310
4346
|
exports.astFromObjectType = astFromObjectType;
|
|
4347
|
+
exports.astFromScalarType = astFromScalarType;
|
|
4311
4348
|
exports.astFromSchema = astFromSchema;
|
|
4312
4349
|
exports.astFromUnionType = astFromUnionType;
|
|
4313
4350
|
exports.astFromValueUntyped = astFromValueUntyped;
|
|
@@ -4337,6 +4374,7 @@ exports.getDeprecatableDirectiveNodes = getDeprecatableDirectiveNodes;
|
|
|
4337
4374
|
exports.getDirectiveNodes = getDirectiveNodes;
|
|
4338
4375
|
exports.getDirectives = getDirectives;
|
|
4339
4376
|
exports.getDirectivesInExtensions = getDirectivesInExtensions;
|
|
4377
|
+
exports.getDocumentNodeFromSchema = getDocumentNodeFromSchema;
|
|
4340
4378
|
exports.getFieldsWithDirectives = getFieldsWithDirectives;
|
|
4341
4379
|
exports.getImplementingTypes = getImplementingTypes;
|
|
4342
4380
|
exports.getLeadingCommentBlock = getLeadingCommentBlock;
|
|
@@ -4356,8 +4394,8 @@ exports.isNamedStub = isNamedStub;
|
|
|
4356
4394
|
exports.isNotEqual = isNotEqual;
|
|
4357
4395
|
exports.isValidPath = isValidPath;
|
|
4358
4396
|
exports.makeDeprecatedDirective = makeDeprecatedDirective;
|
|
4359
|
-
exports.
|
|
4360
|
-
exports.
|
|
4397
|
+
exports.makeDirectiveNode = makeDirectiveNode;
|
|
4398
|
+
exports.makeDirectiveNodes = makeDirectiveNodes;
|
|
4361
4399
|
exports.mapAsyncIterator = mapAsyncIterator;
|
|
4362
4400
|
exports.mapSchema = mapSchema;
|
|
4363
4401
|
exports.mergeDeep = mergeDeep;
|