-
-
Notifications
You must be signed in to change notification settings - Fork 796
/
FilterRootFields.ts
36 lines (29 loc) · 1.04 KB
/
FilterRootFields.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
31
32
33
34
35
36
import { GraphQLSchema, GraphQLFieldConfig } from 'graphql';
import { RootFieldFilter } from '@graphql-tools/utils';
import { SubschemaConfig, Transform } from '@graphql-tools/delegate';
import TransformRootFields from './TransformRootFields';
export default class FilterRootFields implements Transform {
private readonly transformer: TransformRootFields;
constructor(filter: RootFieldFilter) {
this.transformer = new TransformRootFields(
(
operation: 'Query' | 'Mutation' | 'Subscription',
fieldName: string,
fieldConfig: GraphQLFieldConfig<any, any>
) => {
if (filter(operation, fieldName, fieldConfig)) {
return undefined;
}
return null;
}
);
}
public transformSchema(
originalWrappingSchema: GraphQLSchema,
subschemaConfig?: SubschemaConfig,
transforms?: Array<Transform>,
transformedSchema?: GraphQLSchema
): GraphQLSchema {
return this.transformer.transformSchema(originalWrappingSchema, subschemaConfig, transforms, transformedSchema);
}
}