@graphql-tools/utils 7.5.0-alpha-3e5e5d87.0 → 7.6.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 +120 -93
- package/es5/index.cjs.js.map +1 -1
- package/es5/index.esm.js +121 -94
- package/es5/index.esm.js.map +1 -1
- package/es5/package.json +1 -1
- package/es5/types.d.ts +7 -1
- package/index.cjs.js +93 -66
- package/index.cjs.js.map +1 -1
- package/index.esm.js +93 -66
- package/index.esm.js.map +1 -1
- package/package.json +1 -1
- package/types.d.ts +7 -1
package/es5/package.json
CHANGED
package/es5/types.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { GraphQLEnumType, GraphQLInputObjectType, GraphQLScalarType } from 'graphql';
|
|
1
|
+
import { GraphQLEnumType, GraphQLInputObjectType, GraphQLNamedType, GraphQLScalarType } from 'graphql';
|
|
2
2
|
export interface SchemaPrintOptions {
|
|
3
3
|
/**
|
|
4
4
|
* Descriptions are defined as preceding string literals, however an older
|
|
@@ -16,10 +16,16 @@ export interface GetDocumentNodeFromSchemaOptions {
|
|
|
16
16
|
export declare type PrintSchemaWithDirectivesOptions = SchemaPrintOptions & GetDocumentNodeFromSchemaOptions;
|
|
17
17
|
export declare type Maybe<T> = null | undefined | T;
|
|
18
18
|
export declare type Constructor<T> = new (...args: any[]) => T;
|
|
19
|
+
export declare type PruneSchemaFilter = (type: GraphQLNamedType) => boolean;
|
|
19
20
|
/**
|
|
20
21
|
* Options for removing unused types from the schema
|
|
21
22
|
*/
|
|
22
23
|
export interface PruneSchemaOptions {
|
|
24
|
+
/**
|
|
25
|
+
* Return true to skip pruning this type. This check will run first before any other options.
|
|
26
|
+
* This can be helpful for schemas that support type extensions like Apollo Federation.
|
|
27
|
+
*/
|
|
28
|
+
skipPruning?: PruneSchemaFilter;
|
|
23
29
|
/**
|
|
24
30
|
* Set to `true` to skip pruning object types or interfaces with no no fields
|
|
25
31
|
*/
|
package/index.cjs.js
CHANGED
|
@@ -548,11 +548,12 @@ function astFromSchema(schema, pathToDirectivesInExtensions) {
|
|
|
548
548
|
directives,
|
|
549
549
|
};
|
|
550
550
|
schemaNode.description =
|
|
551
|
-
((_b = (_a = schema.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : schema.description != null)
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
551
|
+
((_b = (_a = schema.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : schema.description != null)
|
|
552
|
+
? {
|
|
553
|
+
kind: graphql.Kind.STRING,
|
|
554
|
+
value: schema.description,
|
|
555
|
+
block: true,
|
|
556
|
+
}
|
|
556
557
|
: undefined;
|
|
557
558
|
return schemaNode;
|
|
558
559
|
}
|
|
@@ -570,13 +571,15 @@ function astFromDirective(directive, schema, pathToDirectivesInExtensions) {
|
|
|
570
571
|
kind: graphql.Kind.NAME,
|
|
571
572
|
value: directive.name,
|
|
572
573
|
},
|
|
573
|
-
arguments: (directive === null || directive === void 0 ? void 0 : directive.args)
|
|
574
|
+
arguments: (directive === null || directive === void 0 ? void 0 : directive.args)
|
|
575
|
+
? directive.args.map(arg => astFromArg(arg, schema, pathToDirectivesInExtensions))
|
|
574
576
|
: undefined,
|
|
575
577
|
repeatable: directive.isRepeatable,
|
|
576
|
-
locations: (directive === null || directive === void 0 ? void 0 : directive.locations)
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
578
|
+
locations: (directive === null || directive === void 0 ? void 0 : directive.locations)
|
|
579
|
+
? directive.locations.map(location => ({
|
|
580
|
+
kind: graphql.Kind.NAME,
|
|
581
|
+
value: location,
|
|
582
|
+
}))
|
|
580
583
|
: undefined,
|
|
581
584
|
};
|
|
582
585
|
}
|
|
@@ -628,11 +631,12 @@ function astFromArg(arg, schema, pathToDirectivesInExtensions) {
|
|
|
628
631
|
var _a, _b;
|
|
629
632
|
return {
|
|
630
633
|
kind: graphql.Kind.INPUT_VALUE_DEFINITION,
|
|
631
|
-
description: ((_b = (_a = arg.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : arg.description)
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
634
|
+
description: ((_b = (_a = arg.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : arg.description)
|
|
635
|
+
? {
|
|
636
|
+
kind: graphql.Kind.STRING,
|
|
637
|
+
value: arg.description,
|
|
638
|
+
block: true,
|
|
639
|
+
}
|
|
636
640
|
: undefined,
|
|
637
641
|
name: {
|
|
638
642
|
kind: graphql.Kind.NAME,
|
|
@@ -647,11 +651,12 @@ function astFromObjectType(type, schema, pathToDirectivesInExtensions) {
|
|
|
647
651
|
var _a, _b;
|
|
648
652
|
return {
|
|
649
653
|
kind: graphql.Kind.OBJECT_TYPE_DEFINITION,
|
|
650
|
-
description: ((_b = (_a = type.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : type.description)
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
654
|
+
description: ((_b = (_a = type.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : type.description)
|
|
655
|
+
? {
|
|
656
|
+
kind: graphql.Kind.STRING,
|
|
657
|
+
value: type.description,
|
|
658
|
+
block: true,
|
|
659
|
+
}
|
|
655
660
|
: undefined,
|
|
656
661
|
name: {
|
|
657
662
|
kind: graphql.Kind.NAME,
|
|
@@ -666,11 +671,12 @@ function astFromInterfaceType(type, schema, pathToDirectivesInExtensions) {
|
|
|
666
671
|
var _a, _b;
|
|
667
672
|
const node = {
|
|
668
673
|
kind: graphql.Kind.INTERFACE_TYPE_DEFINITION,
|
|
669
|
-
description: ((_b = (_a = type.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : type.description)
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
+
description: ((_b = (_a = type.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : type.description)
|
|
675
|
+
? {
|
|
676
|
+
kind: graphql.Kind.STRING,
|
|
677
|
+
value: type.description,
|
|
678
|
+
block: true,
|
|
679
|
+
}
|
|
674
680
|
: undefined,
|
|
675
681
|
name: {
|
|
676
682
|
kind: graphql.Kind.NAME,
|
|
@@ -688,11 +694,12 @@ function astFromUnionType(type, schema, pathToDirectivesInExtensions) {
|
|
|
688
694
|
var _a, _b;
|
|
689
695
|
return {
|
|
690
696
|
kind: graphql.Kind.UNION_TYPE_DEFINITION,
|
|
691
|
-
description: ((_b = (_a = type.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : type.description)
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
697
|
+
description: ((_b = (_a = type.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : type.description)
|
|
698
|
+
? {
|
|
699
|
+
kind: graphql.Kind.STRING,
|
|
700
|
+
value: type.description,
|
|
701
|
+
block: true,
|
|
702
|
+
}
|
|
696
703
|
: undefined,
|
|
697
704
|
name: {
|
|
698
705
|
kind: graphql.Kind.NAME,
|
|
@@ -706,11 +713,12 @@ function astFromInputObjectType(type, schema, pathToDirectivesInExtensions) {
|
|
|
706
713
|
var _a, _b;
|
|
707
714
|
return {
|
|
708
715
|
kind: graphql.Kind.INPUT_OBJECT_TYPE_DEFINITION,
|
|
709
|
-
description: ((_b = (_a = type.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : type.description)
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
716
|
+
description: ((_b = (_a = type.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : type.description)
|
|
717
|
+
? {
|
|
718
|
+
kind: graphql.Kind.STRING,
|
|
719
|
+
value: type.description,
|
|
720
|
+
block: true,
|
|
721
|
+
}
|
|
714
722
|
: undefined,
|
|
715
723
|
name: {
|
|
716
724
|
kind: graphql.Kind.NAME,
|
|
@@ -724,11 +732,12 @@ function astFromEnumType(type, schema, pathToDirectivesInExtensions) {
|
|
|
724
732
|
var _a, _b;
|
|
725
733
|
return {
|
|
726
734
|
kind: graphql.Kind.ENUM_TYPE_DEFINITION,
|
|
727
|
-
description: ((_b = (_a = type.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : type.description)
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
735
|
+
description: ((_b = (_a = type.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : type.description)
|
|
736
|
+
? {
|
|
737
|
+
kind: graphql.Kind.STRING,
|
|
738
|
+
value: type.description,
|
|
739
|
+
block: true,
|
|
740
|
+
}
|
|
732
741
|
: undefined,
|
|
733
742
|
name: {
|
|
734
743
|
kind: graphql.Kind.NAME,
|
|
@@ -766,11 +775,12 @@ function astFromScalarType(type, schema, pathToDirectivesInExtensions) {
|
|
|
766
775
|
: [specifiedByDirectiveNode].concat(directiveNodesBesidesSpecifiedBy);
|
|
767
776
|
return {
|
|
768
777
|
kind: graphql.Kind.SCALAR_TYPE_DEFINITION,
|
|
769
|
-
description: ((_d = (_c = type.astNode) === null || _c === void 0 ? void 0 : _c.description) !== null && _d !== void 0 ? _d : type.description)
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
778
|
+
description: ((_d = (_c = type.astNode) === null || _c === void 0 ? void 0 : _c.description) !== null && _d !== void 0 ? _d : type.description)
|
|
779
|
+
? {
|
|
780
|
+
kind: graphql.Kind.STRING,
|
|
781
|
+
value: type.description,
|
|
782
|
+
block: true,
|
|
783
|
+
}
|
|
774
784
|
: undefined,
|
|
775
785
|
name: {
|
|
776
786
|
kind: graphql.Kind.NAME,
|
|
@@ -783,11 +793,12 @@ function astFromField(field, schema, pathToDirectivesInExtensions) {
|
|
|
783
793
|
var _a, _b;
|
|
784
794
|
return {
|
|
785
795
|
kind: graphql.Kind.FIELD_DEFINITION,
|
|
786
|
-
description: ((_b = (_a = field.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : field.description)
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
796
|
+
description: ((_b = (_a = field.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : field.description)
|
|
797
|
+
? {
|
|
798
|
+
kind: graphql.Kind.STRING,
|
|
799
|
+
value: field.description,
|
|
800
|
+
block: true,
|
|
801
|
+
}
|
|
791
802
|
: undefined,
|
|
792
803
|
name: {
|
|
793
804
|
kind: graphql.Kind.NAME,
|
|
@@ -802,11 +813,12 @@ function astFromInputField(field, schema, pathToDirectivesInExtensions) {
|
|
|
802
813
|
var _a, _b;
|
|
803
814
|
return {
|
|
804
815
|
kind: graphql.Kind.INPUT_VALUE_DEFINITION,
|
|
805
|
-
description: ((_b = (_a = field.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : field.description)
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
816
|
+
description: ((_b = (_a = field.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : field.description)
|
|
817
|
+
? {
|
|
818
|
+
kind: graphql.Kind.STRING,
|
|
819
|
+
value: field.description,
|
|
820
|
+
block: true,
|
|
821
|
+
}
|
|
810
822
|
: undefined,
|
|
811
823
|
name: {
|
|
812
824
|
kind: graphql.Kind.NAME,
|
|
@@ -821,11 +833,12 @@ function astFromEnumValue(value, schema, pathToDirectivesInExtensions) {
|
|
|
821
833
|
var _a, _b;
|
|
822
834
|
return {
|
|
823
835
|
kind: graphql.Kind.ENUM_VALUE_DEFINITION,
|
|
824
|
-
description: ((_b = (_a = value.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : value.description)
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
836
|
+
description: ((_b = (_a = value.astNode) === null || _a === void 0 ? void 0 : _a.description) !== null && _b !== void 0 ? _b : value.description)
|
|
837
|
+
? {
|
|
838
|
+
kind: graphql.Kind.STRING,
|
|
839
|
+
value: value.description,
|
|
840
|
+
block: true,
|
|
841
|
+
}
|
|
829
842
|
: undefined,
|
|
830
843
|
name: {
|
|
831
844
|
kind: graphql.Kind.NAME,
|
|
@@ -3332,7 +3345,8 @@ function pruneSchema(schema, options = {}) {
|
|
|
3332
3345
|
const type = schema.getType(typeName);
|
|
3333
3346
|
if ('getInterfaces' in type) {
|
|
3334
3347
|
type.getInterfaces().forEach(iface => {
|
|
3335
|
-
|
|
3348
|
+
const implementations = getImplementations(pruningContext, iface);
|
|
3349
|
+
if (implementations == null) {
|
|
3336
3350
|
pruningContext.implementations[iface.name] = Object.create(null);
|
|
3337
3351
|
}
|
|
3338
3352
|
pruningContext.implementations[iface.name][type.name] = true;
|
|
@@ -3342,6 +3356,10 @@ function pruneSchema(schema, options = {}) {
|
|
|
3342
3356
|
visitTypes(pruningContext, schema);
|
|
3343
3357
|
return mapSchema(schema, {
|
|
3344
3358
|
[exports.MapperKind.TYPE]: (type) => {
|
|
3359
|
+
// If we should NOT prune the type, return it immediately as unmodified
|
|
3360
|
+
if (options.skipPruning && options.skipPruning(type)) {
|
|
3361
|
+
return type;
|
|
3362
|
+
}
|
|
3345
3363
|
if (graphql.isObjectType(type) || graphql.isInputObjectType(type)) {
|
|
3346
3364
|
if ((!Object.keys(type.getFields()).length && !options.skipEmptyCompositeTypePruning) ||
|
|
3347
3365
|
(pruningContext.unusedTypes[type.name] && !options.skipUnusedTypesPruning)) {
|
|
@@ -3355,9 +3373,9 @@ function pruneSchema(schema, options = {}) {
|
|
|
3355
3373
|
}
|
|
3356
3374
|
}
|
|
3357
3375
|
else if (graphql.isInterfaceType(type)) {
|
|
3376
|
+
const implementations = getImplementations(pruningContext, type);
|
|
3358
3377
|
if ((!Object.keys(type.getFields()).length && !options.skipEmptyCompositeTypePruning) ||
|
|
3359
|
-
(!Object.keys(
|
|
3360
|
-
!options.skipUnimplementedInterfacesPruning) ||
|
|
3378
|
+
(implementations && !Object.keys(implementations).length && !options.skipUnimplementedInterfacesPruning) ||
|
|
3361
3379
|
(pruningContext.unusedTypes[type.name] && !options.skipUnusedTypesPruning)) {
|
|
3362
3380
|
return null;
|
|
3363
3381
|
}
|
|
@@ -3389,9 +3407,12 @@ function visitOutputType(visitedTypes, pruningContext, type) {
|
|
|
3389
3407
|
});
|
|
3390
3408
|
});
|
|
3391
3409
|
if (graphql.isInterfaceType(type)) {
|
|
3392
|
-
|
|
3393
|
-
|
|
3394
|
-
|
|
3410
|
+
const implementations = getImplementations(pruningContext, type);
|
|
3411
|
+
if (implementations) {
|
|
3412
|
+
Object.keys(implementations).forEach(typeName => {
|
|
3413
|
+
visitOutputType(visitedTypes, pruningContext, pruningContext.schema.getType(typeName));
|
|
3414
|
+
});
|
|
3415
|
+
}
|
|
3395
3416
|
}
|
|
3396
3417
|
if ('getInterfaces' in type) {
|
|
3397
3418
|
type.getInterfaces().forEach(type => {
|
|
@@ -3404,6 +3425,12 @@ function visitOutputType(visitedTypes, pruningContext, type) {
|
|
|
3404
3425
|
types.forEach(type => visitOutputType(visitedTypes, pruningContext, type));
|
|
3405
3426
|
}
|
|
3406
3427
|
}
|
|
3428
|
+
/**
|
|
3429
|
+
* Get the implementations of an interface. May return undefined.
|
|
3430
|
+
*/
|
|
3431
|
+
function getImplementations(pruningContext, type) {
|
|
3432
|
+
return pruningContext.implementations[type.name];
|
|
3433
|
+
}
|
|
3407
3434
|
function visitInputType(visitedTypes, pruningContext, type) {
|
|
3408
3435
|
if (visitedTypes[type.name]) {
|
|
3409
3436
|
return;
|