Search in sources :

Example 1 with TypeExtensionDirectiveRedefinitionError

use of graphql.schema.idl.errors.TypeExtensionDirectiveRedefinitionError in project graphql-java by graphql-java.

the class SchemaTypeExtensionsChecker method checkTypeExtensionDirectiveRedefinition.

@SuppressWarnings("unchecked")
private void checkTypeExtensionDirectiveRedefinition(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry, String name, List<? extends TypeDefinition> extensions, Class<? extends TypeDefinition> targetClass) {
    Optional<? extends TypeDefinition> typeDefinition = typeRegistry.getType(new TypeName(name), targetClass);
    if (typeDefinition.isPresent() && typeDefinition.get().getClass().equals(targetClass)) {
        List<Directive> directives = typeDefinition.get().getDirectives();
        Map<String, Directive> directiveMap = FpKit.getByName(directives, Directive::getName, mergeFirst());
        extensions.forEach(typeExt -> {
            List<Directive> extDirectives = typeExt.getDirectives();
            extDirectives.forEach(directive -> {
                if (directiveMap.containsKey(directive.getName())) {
                    errors.add(new TypeExtensionDirectiveRedefinitionError(typeDefinition.get(), directive));
                }
            });
        });
    }
}
Also used : TypeName(graphql.language.TypeName) TypeExtensionDirectiveRedefinitionError(graphql.schema.idl.errors.TypeExtensionDirectiveRedefinitionError) SchemaTypeChecker.checkDeprecatedDirective(graphql.schema.idl.SchemaTypeChecker.checkDeprecatedDirective) Directive(graphql.language.Directive)

Aggregations

Directive (graphql.language.Directive)1 TypeName (graphql.language.TypeName)1 SchemaTypeChecker.checkDeprecatedDirective (graphql.schema.idl.SchemaTypeChecker.checkDeprecatedDirective)1 TypeExtensionDirectiveRedefinitionError (graphql.schema.idl.errors.TypeExtensionDirectiveRedefinitionError)1