Search in sources :

Example 6 with DirectiveDefinition

use of graphql.language.DirectiveDefinition in project graphql-java by graphql-java.

the class SchemaTypeExtensionsChecker method checkInputObjectTypeExtensions.

/*
     * Input object type extensions have the potential to be invalid if incorrectly defined.
     *
     * The named type must already be defined and must be a Input Object type.
     * All fields of an Input Object type extension must have unique names.
     * All fields of an Input Object type extension must not already be a field of the original Input Object.
     * Any directives provided must not already apply to the original Input Object type.
     */
private void checkInputObjectTypeExtensions(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry, Map<String, DirectiveDefinition> directiveDefinitionMap) {
    typeRegistry.inputObjectTypeExtensions().forEach((name, extensions) -> {
        checkTypeExtensionHasCorrespondingType(errors, typeRegistry, name, extensions, InputObjectTypeDefinition.class);
        // field redefinitions
        extensions.forEach(extension -> {
            List<InputValueDefinition> inputValueDefinitions = extension.getInputValueDefinitions();
            // field unique ness
            checkNamedUniqueness(errors, inputValueDefinitions, InputValueDefinition::getName, (namedField, fieldDef) -> new NonUniqueNameError(extension, fieldDef));
            // directive checks
            inputValueDefinitions.forEach(fld -> fld.getDirectives().forEach(directive -> checkNamedUniqueness(errors, directive.getArguments(), Argument::getName, (argumentName, argument) -> new NonUniqueArgumentError(extension, fld, argumentName))));
            // 
            // fields must be unique within a type extension
            forEachBut(extension, extensions, otherTypeExt -> checkForInputValueRedefinition(errors, otherTypeExt, otherTypeExt.getInputValueDefinitions(), inputValueDefinitions));
            // 
            // then check for field re-defs from the base type
            Optional<InputObjectTypeDefinition> baseTypeOpt = typeRegistry.getType(extension.getName(), InputObjectTypeDefinition.class);
            baseTypeOpt.ifPresent(baseTypeDef -> checkForInputValueRedefinition(errors, extension, inputValueDefinitions, baseTypeDef.getInputValueDefinitions()));
        });
    });
}
Also used : Internal(graphql.Internal) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) InputValueDefinition(graphql.language.InputValueDefinition) DirectiveDefinition(graphql.language.DirectiveDefinition) EnumTypeDefinition(graphql.language.EnumTypeDefinition) TypeExtensionFieldRedefinitionError(graphql.schema.idl.errors.TypeExtensionFieldRedefinitionError) UnionTypeDefinition(graphql.language.UnionTypeDefinition) EnumValueDefinition(graphql.language.EnumValueDefinition) GraphQLError(graphql.GraphQLError) Map(java.util.Map) InputObjectTypeExtensionDefinition(graphql.language.InputObjectTypeExtensionDefinition) TypeExtensionEnumValueRedefinitionError(graphql.schema.idl.errors.TypeExtensionEnumValueRedefinitionError) TypeExtensionMissingBaseTypeError(graphql.schema.idl.errors.TypeExtensionMissingBaseTypeError) TypeName(graphql.language.TypeName) SchemaTypeChecker.checkNamedUniqueness(graphql.schema.idl.SchemaTypeChecker.checkNamedUniqueness) FpKit.mergeFirst(graphql.util.FpKit.mergeFirst) ScalarTypeDefinition(graphql.language.ScalarTypeDefinition) ObjectTypeDefinition(graphql.language.ObjectTypeDefinition) NonUniqueNameError(graphql.schema.idl.errors.NonUniqueNameError) FieldDefinition(graphql.language.FieldDefinition) TypeDefinition(graphql.language.TypeDefinition) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) Argument(graphql.language.Argument) MissingTypeError(graphql.schema.idl.errors.MissingTypeError) List(java.util.List) FpKit(graphql.util.FpKit) InterfaceTypeDefinition(graphql.language.InterfaceTypeDefinition) Optional(java.util.Optional) NonUniqueArgumentError(graphql.schema.idl.errors.NonUniqueArgumentError) Argument(graphql.language.Argument) NonUniqueArgumentError(graphql.schema.idl.errors.NonUniqueArgumentError) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) InputValueDefinition(graphql.language.InputValueDefinition) NonUniqueNameError(graphql.schema.idl.errors.NonUniqueNameError)

Example 7 with DirectiveDefinition

use of graphql.language.DirectiveDefinition in project graphql-java by graphql-java.

the class SchemaTypeExtensionsChecker method checkInterfaceTypeExtensions.

/*
     * Interface type extensions have the potential to be invalid if incorrectly defined.
     *
     * The named type must already be defined and must be an Interface type.
     * The fields of an Interface type extension must have unique names; no two fields may share the same name.
     * Any fields of an Interface type extension must not be already defined on the original Interface type.
     * Any Object type which implemented the original Interface type must also be a super-set of the fields of the Interface type extension (which may be due to Object type extension).
     * Any directives provided must not already apply to the original Interface type.
     */
private void checkInterfaceTypeExtensions(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry, Map<String, DirectiveDefinition> directiveDefinitionMap) {
    typeRegistry.interfaceTypeExtensions().forEach((name, extensions) -> {
        checkTypeExtensionHasCorrespondingType(errors, typeRegistry, name, extensions, InterfaceTypeDefinition.class);
        extensions.forEach(extension -> {
            List<FieldDefinition> fieldDefinitions = extension.getFieldDefinitions();
            // field unique ness
            checkNamedUniqueness(errors, extension.getFieldDefinitions(), FieldDefinition::getName, (namedField, fieldDef) -> new NonUniqueNameError(extension, fieldDef));
            // field arg unique ness
            extension.getFieldDefinitions().forEach(fld -> checkNamedUniqueness(errors, fld.getInputValueDefinitions(), InputValueDefinition::getName, (namedField, inputValueDefinition) -> new NonUniqueArgumentError(extension, fld, name)));
            // directive checks
            fieldDefinitions.forEach(fld -> fld.getDirectives().forEach(directive -> checkNamedUniqueness(errors, directive.getArguments(), Argument::getName, (argumentName, argument) -> new NonUniqueArgumentError(extension, fld, argumentName))));
            // 
            // fields must be unique within a type extension
            forEachBut(extension, extensions, otherTypeExt -> checkForFieldRedefinition(errors, otherTypeExt, otherTypeExt.getFieldDefinitions(), fieldDefinitions));
            // 
            // then check for field re-defs from the base type
            Optional<InterfaceTypeDefinition> baseTypeOpt = typeRegistry.getType(extension.getName(), InterfaceTypeDefinition.class);
            baseTypeOpt.ifPresent(baseTypeDef -> checkForFieldRedefinition(errors, extension, fieldDefinitions, baseTypeDef.getFieldDefinitions()));
        });
    });
}
Also used : Internal(graphql.Internal) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) InputValueDefinition(graphql.language.InputValueDefinition) DirectiveDefinition(graphql.language.DirectiveDefinition) EnumTypeDefinition(graphql.language.EnumTypeDefinition) TypeExtensionFieldRedefinitionError(graphql.schema.idl.errors.TypeExtensionFieldRedefinitionError) UnionTypeDefinition(graphql.language.UnionTypeDefinition) EnumValueDefinition(graphql.language.EnumValueDefinition) GraphQLError(graphql.GraphQLError) Map(java.util.Map) InputObjectTypeExtensionDefinition(graphql.language.InputObjectTypeExtensionDefinition) TypeExtensionEnumValueRedefinitionError(graphql.schema.idl.errors.TypeExtensionEnumValueRedefinitionError) TypeExtensionMissingBaseTypeError(graphql.schema.idl.errors.TypeExtensionMissingBaseTypeError) TypeName(graphql.language.TypeName) SchemaTypeChecker.checkNamedUniqueness(graphql.schema.idl.SchemaTypeChecker.checkNamedUniqueness) FpKit.mergeFirst(graphql.util.FpKit.mergeFirst) ScalarTypeDefinition(graphql.language.ScalarTypeDefinition) ObjectTypeDefinition(graphql.language.ObjectTypeDefinition) NonUniqueNameError(graphql.schema.idl.errors.NonUniqueNameError) FieldDefinition(graphql.language.FieldDefinition) TypeDefinition(graphql.language.TypeDefinition) Collectors(java.util.stream.Collectors) Consumer(java.util.function.Consumer) Argument(graphql.language.Argument) MissingTypeError(graphql.schema.idl.errors.MissingTypeError) List(java.util.List) FpKit(graphql.util.FpKit) InterfaceTypeDefinition(graphql.language.InterfaceTypeDefinition) Optional(java.util.Optional) NonUniqueArgumentError(graphql.schema.idl.errors.NonUniqueArgumentError) Argument(graphql.language.Argument) FieldDefinition(graphql.language.FieldDefinition) NonUniqueArgumentError(graphql.schema.idl.errors.NonUniqueArgumentError) InterfaceTypeDefinition(graphql.language.InterfaceTypeDefinition) NonUniqueNameError(graphql.schema.idl.errors.NonUniqueNameError)

Example 8 with DirectiveDefinition

use of graphql.language.DirectiveDefinition in project graphql-java by graphql-java.

the class SchemaTypeChecker method checkInterfaceFields.

private void checkInterfaceFields(List<GraphQLError> errors, InterfaceTypeDefinition interfaceType, List<FieldDefinition> fieldDefinitions, Map<String, DirectiveDefinition> directiveDefinitionMap) {
    // field unique ness
    checkNamedUniqueness(errors, fieldDefinitions, FieldDefinition::getName, (name, fieldDef) -> new NonUniqueNameError(interfaceType, fieldDef));
    // field arg unique ness
    fieldDefinitions.forEach(fld -> checkNamedUniqueness(errors, fld.getInputValueDefinitions(), InputValueDefinition::getName, (name, inputValueDefinition) -> new NonUniqueArgumentError(interfaceType, fld, name)));
    // directive checks
    fieldDefinitions.forEach(fieldDefinition -> {
        List<Directive> directives = fieldDefinition.getDirectives();
        directives.forEach(directive -> checkNamedUniqueness(errors, directive.getArguments(), Argument::getName, (argumentName, argument) -> new NonUniqueArgumentError(interfaceType, fieldDefinition, argumentName)));
    });
}
Also used : Internal(graphql.Internal) Node(graphql.language.Node) MissingInterfaceTypeError(graphql.schema.idl.errors.MissingInterfaceTypeError) INPUT_FIELD_DEFINITION(graphql.introspection.Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION) BiFunction(java.util.function.BiFunction) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) InputValueDefinition(graphql.language.InputValueDefinition) SchemaProblem(graphql.schema.idl.errors.SchemaProblem) DirectiveDefinition(graphql.language.DirectiveDefinition) MissingTypeResolverError(graphql.schema.idl.errors.MissingTypeResolverError) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Introspection(graphql.introspection.Introspection) EnumTypeDefinition(graphql.language.EnumTypeDefinition) Type(graphql.language.Type) UnionTypeDefinition(graphql.language.UnionTypeDefinition) MissingScalarImplementationError(graphql.schema.idl.errors.MissingScalarImplementationError) EnumValueDefinition(graphql.language.EnumValueDefinition) ObjectTypeExtensionDefinition(graphql.language.ObjectTypeExtensionDefinition) GraphQLError(graphql.GraphQLError) Map(java.util.Map) TypeName(graphql.language.TypeName) LinkedHashSet(java.util.LinkedHashSet) ObjectTypeDefinition(graphql.language.ObjectTypeDefinition) NonUniqueNameError(graphql.schema.idl.errors.NonUniqueNameError) Predicate(java.util.function.Predicate) Collection(java.util.Collection) FieldDefinition(graphql.language.FieldDefinition) Set(java.util.Set) TypeDefinition(graphql.language.TypeDefinition) Directive(graphql.language.Directive) Consumer(java.util.function.Consumer) Argument(graphql.language.Argument) MissingTypeError(graphql.schema.idl.errors.MissingTypeError) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) InterfaceTypeDefinition(graphql.language.InterfaceTypeDefinition) Optional(java.util.Optional) NonUniqueArgumentError(graphql.schema.idl.errors.NonUniqueArgumentError) DirectiveIllegalLocationError(graphql.schema.idl.errors.DirectiveIllegalLocationError) Collections(java.util.Collections) FieldDefinition(graphql.language.FieldDefinition) NonUniqueArgumentError(graphql.schema.idl.errors.NonUniqueArgumentError) NonUniqueNameError(graphql.schema.idl.errors.NonUniqueNameError) Directive(graphql.language.Directive)

Example 9 with DirectiveDefinition

use of graphql.language.DirectiveDefinition in project graphql-java by graphql-java.

the class GraphqlAntlrToLanguage method visitDirectiveDefinition.

@Override
public Void visitDirectiveDefinition(GraphqlParser.DirectiveDefinitionContext ctx) {
    DirectiveDefinition def = new DirectiveDefinition(ctx.name().getText());
    newNode(def, ctx);
    def.setDescription(newDescription(ctx.description()));
    result.getDefinitions().add(def);
    addContextProperty(ContextProperty.DirectiveDefinition, def);
    super.visitChildren(ctx);
    popContext();
    return null;
}
Also used : DirectiveDefinition(graphql.language.DirectiveDefinition)

Example 10 with DirectiveDefinition

use of graphql.language.DirectiveDefinition in project graphql-java by graphql-java.

the class SchemaTypeChecker method checkInputValues.

private void checkInputValues(List<GraphQLError> errors, InputObjectTypeDefinition inputType, List<InputValueDefinition> inputValueDefinitions, Introspection.DirectiveLocation directiveLocation, Map<String, DirectiveDefinition> directiveDefinitionMap) {
    // field unique ness
    checkNamedUniqueness(errors, inputValueDefinitions, InputValueDefinition::getName, (name, inputValueDefinition) -> {
        // not sure why this is needed but inlining breaks it
        @SuppressWarnings("UnnecessaryLocalVariable") InputObjectTypeDefinition as = inputType;
        return new NonUniqueNameError(as, inputValueDefinition);
    });
    // directive checks
    inputValueDefinitions.forEach(inputValueDef -> inputValueDef.getDirectives().forEach(directive -> checkNamedUniqueness(errors, directive.getArguments(), Argument::getName, (argumentName, argument) -> new NonUniqueArgumentError(inputType, inputValueDef, argumentName))));
}
Also used : Internal(graphql.Internal) Node(graphql.language.Node) MissingInterfaceTypeError(graphql.schema.idl.errors.MissingInterfaceTypeError) INPUT_FIELD_DEFINITION(graphql.introspection.Introspection.DirectiveLocation.INPUT_FIELD_DEFINITION) BiFunction(java.util.function.BiFunction) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) InputValueDefinition(graphql.language.InputValueDefinition) SchemaProblem(graphql.schema.idl.errors.SchemaProblem) DirectiveDefinition(graphql.language.DirectiveDefinition) MissingTypeResolverError(graphql.schema.idl.errors.MissingTypeResolverError) Function(java.util.function.Function) ArrayList(java.util.ArrayList) Introspection(graphql.introspection.Introspection) EnumTypeDefinition(graphql.language.EnumTypeDefinition) Type(graphql.language.Type) UnionTypeDefinition(graphql.language.UnionTypeDefinition) MissingScalarImplementationError(graphql.schema.idl.errors.MissingScalarImplementationError) EnumValueDefinition(graphql.language.EnumValueDefinition) ObjectTypeExtensionDefinition(graphql.language.ObjectTypeExtensionDefinition) GraphQLError(graphql.GraphQLError) Map(java.util.Map) TypeName(graphql.language.TypeName) LinkedHashSet(java.util.LinkedHashSet) ObjectTypeDefinition(graphql.language.ObjectTypeDefinition) NonUniqueNameError(graphql.schema.idl.errors.NonUniqueNameError) Predicate(java.util.function.Predicate) Collection(java.util.Collection) FieldDefinition(graphql.language.FieldDefinition) Set(java.util.Set) TypeDefinition(graphql.language.TypeDefinition) Directive(graphql.language.Directive) Consumer(java.util.function.Consumer) Argument(graphql.language.Argument) MissingTypeError(graphql.schema.idl.errors.MissingTypeError) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) InterfaceTypeDefinition(graphql.language.InterfaceTypeDefinition) Optional(java.util.Optional) NonUniqueArgumentError(graphql.schema.idl.errors.NonUniqueArgumentError) DirectiveIllegalLocationError(graphql.schema.idl.errors.DirectiveIllegalLocationError) Collections(java.util.Collections) Argument(graphql.language.Argument) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) NonUniqueArgumentError(graphql.schema.idl.errors.NonUniqueArgumentError) InputValueDefinition(graphql.language.InputValueDefinition) NonUniqueNameError(graphql.schema.idl.errors.NonUniqueNameError)

Aggregations

DirectiveDefinition (graphql.language.DirectiveDefinition)14 InterfaceTypeDefinition (graphql.language.InterfaceTypeDefinition)11 ObjectTypeDefinition (graphql.language.ObjectTypeDefinition)11 TypeDefinition (graphql.language.TypeDefinition)11 UnionTypeDefinition (graphql.language.UnionTypeDefinition)11 GraphQLError (graphql.GraphQLError)10 EnumTypeDefinition (graphql.language.EnumTypeDefinition)10 InputObjectTypeDefinition (graphql.language.InputObjectTypeDefinition)10 InputValueDefinition (graphql.language.InputValueDefinition)10 TypeName (graphql.language.TypeName)10 List (java.util.List)10 Map (java.util.Map)10 Internal (graphql.Internal)9 Argument (graphql.language.Argument)9 EnumValueDefinition (graphql.language.EnumValueDefinition)9 FieldDefinition (graphql.language.FieldDefinition)9 MissingTypeError (graphql.schema.idl.errors.MissingTypeError)9 NonUniqueNameError (graphql.schema.idl.errors.NonUniqueNameError)9 Optional (java.util.Optional)9 NonUniqueArgumentError (graphql.schema.idl.errors.NonUniqueArgumentError)8