-
-
Notifications
You must be signed in to change notification settings - Fork 796
/
FilterTypes.ts
30 lines (24 loc) · 830 Bytes
/
FilterTypes.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { GraphQLSchema, GraphQLNamedType } from 'graphql';
import { mapSchema, MapperKind } from '@graphql-tools/utils';
import { SubschemaConfig, Transform } from '@graphql-tools/delegate';
export default class FilterTypes implements Transform {
private readonly filter: (type: GraphQLNamedType) => boolean;
constructor(filter: (type: GraphQLNamedType) => boolean) {
this.filter = filter;
}
public transformSchema(
originalWrappingSchema: GraphQLSchema,
_subschemaConfig?: SubschemaConfig,
_transforms?: Array<Transform>,
_transformedSchema?: GraphQLSchema
): GraphQLSchema {
return mapSchema(originalWrappingSchema, {
[MapperKind.TYPE]: (type: GraphQLNamedType) => {
if (this.filter(type)) {
return undefined;
}
return null;
},
});
}
}