@graphql-tools/utils 7.5.2 → 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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/utils/es5",
3
- "version": "7.5.2",
3
+ "version": "7.6.0",
4
4
  "description": "Common package containing utils and types for GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
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
@@ -3356,6 +3356,10 @@ function pruneSchema(schema, options = {}) {
3356
3356
  visitTypes(pruningContext, schema);
3357
3357
  return mapSchema(schema, {
3358
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
+ }
3359
3363
  if (graphql.isObjectType(type) || graphql.isInputObjectType(type)) {
3360
3364
  if ((!Object.keys(type.getFields()).length && !options.skipEmptyCompositeTypePruning) ||
3361
3365
  (pruningContext.unusedTypes[type.name] && !options.skipUnusedTypesPruning)) {