-
-
Notifications
You must be signed in to change notification settings - Fork 804
/
RemoveObjectFieldDirectives.ts
27 lines (23 loc) · 1.1 KB
/
RemoveObjectFieldDirectives.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
import { GraphQLSchema } from 'graphql';
import { SubschemaConfig, Transform } from '@graphql-tools/delegate';
import { valueMatchesCriteria } from '@graphql-tools/utils';
import FilterObjectFieldDirectives from './FilterObjectFieldDirectives.js';
interface RemoveObjectFieldDirectivesTransformationContext extends Record<string, any> {}
export default class RemoveObjectFieldDirectives<TContext = Record<string, any>>
implements Transform<RemoveObjectFieldDirectivesTransformationContext, TContext>
{
private readonly transformer: FilterObjectFieldDirectives<TContext>;
constructor(directiveName: string | RegExp, args: Record<string, any> = {}) {
this.transformer = new FilterObjectFieldDirectives((dirName: string, dirValue: any) => {
return !(
valueMatchesCriteria(dirName, directiveName) && valueMatchesCriteria(dirValue, args)
);
});
}
public transformSchema(
originalWrappingSchema: GraphQLSchema,
subschemaConfig: SubschemaConfig<any, any, any, TContext>,
): GraphQLSchema {
return this.transformer.transformSchema(originalWrappingSchema, subschemaConfig);
}
}