@graphql-tools/wrap
Version:
A set of utils for faster development of GraphQL tools
16 lines (15 loc) • 812 B
JavaScript
import { getDirectives, valueMatchesCriteria } from '@graphql-tools/utils';
import FilterObjectFields from './FilterObjectFields.js';
export default class RemoveObjectFieldsWithDirective {
constructor(directiveName, args = {}) {
this.directiveName = directiveName;
this.args = args;
}
transformSchema(originalWrappingSchema, subschemaConfig) {
const transformer = new FilterObjectFields((_typeName, _fieldName, fieldConfig) => {
const directives = getDirectives(originalWrappingSchema, fieldConfig);
return !directives.some(directive => valueMatchesCriteria(directive.name, this.directiveName) && valueMatchesCriteria(directive.args, this.args));
});
return transformer.transformSchema(originalWrappingSchema, subschemaConfig);
}
}