Search in sources :

Example 11 with InputValueDefinition

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

the class SchemaTypeChecker method checkEnumValues.

private void checkEnumValues(List<GraphQLError> errors, EnumTypeDefinition enumType, List<EnumValueDefinition> enumValueDefinitions) {
    // enum unique ness
    checkNamedUniqueness(errors, enumValueDefinitions, EnumValueDefinition::getName, (name, inputValueDefinition) -> new NonUniqueNameError(enumType, inputValueDefinition));
    // directive checks
    enumValueDefinitions.forEach(enumValue -> {
        BiFunction<String, Directive, NonUniqueDirectiveError> errorFunction = (directiveName, directive) -> new NonUniqueDirectiveError(enumType, enumValue, directiveName);
        checkNamedUniqueness(errors, enumValue.getDirectives(), Directive::getName, errorFunction);
    });
    enumValueDefinitions.forEach(enumValue -> enumValue.getDirectives().forEach(directive -> {
        checkDeprecatedDirective(errors, directive, () -> new InvalidDeprecationDirectiveError(enumType, enumValue));
        BiFunction<String, Argument, NonUniqueArgumentError> errorFunction = (argumentName, argument) -> new NonUniqueArgumentError(enumType, enumValue, argumentName);
        checkNamedUniqueness(errors, directive.getArguments(), Argument::getName, errorFunction);
    }));
}
Also used : MissingInterfaceTypeError(graphql.schema.idl.errors.MissingInterfaceTypeError) BiFunction(java.util.function.BiFunction) InputValueDefinition(graphql.language.InputValueDefinition) SchemaDefinition(graphql.language.SchemaDefinition) MissingInterfaceFieldError(graphql.schema.idl.errors.MissingInterfaceFieldError) EnumTypeDefinition(graphql.language.EnumTypeDefinition) Type(graphql.language.Type) 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) QueryOperationMissingError(graphql.schema.idl.errors.QueryOperationMissingError) OperationTypeDefinition(graphql.language.OperationTypeDefinition) ObjectTypeDefinition(graphql.language.ObjectTypeDefinition) InterfaceFieldRedefinitionError(graphql.schema.idl.errors.InterfaceFieldRedefinitionError) Predicate(java.util.function.Predicate) Collection(java.util.Collection) FieldDefinition(graphql.language.FieldDefinition) Set(java.util.Set) TypeDefinition(graphql.language.TypeDefinition) Collectors(java.util.stream.Collectors) BinaryOperator(java.util.function.BinaryOperator) AstPrinter(graphql.language.AstPrinter) MissingTypeError(graphql.schema.idl.errors.MissingTypeError) List(java.util.List) InterfaceTypeDefinition(graphql.language.InterfaceTypeDefinition) Optional(java.util.Optional) NonUniqueArgumentError(graphql.schema.idl.errors.NonUniqueArgumentError) InterfaceFieldArgumentRedefinitionError(graphql.schema.idl.errors.InterfaceFieldArgumentRedefinitionError) SchemaMissingError(graphql.schema.idl.errors.SchemaMissingError) NonUniqueDirectiveError(graphql.schema.idl.errors.NonUniqueDirectiveError) Internal(graphql.Internal) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) SchemaProblem(graphql.schema.idl.errors.SchemaProblem) MissingTypeResolverError(graphql.schema.idl.errors.MissingTypeResolverError) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) UnionTypeDefinition(graphql.language.UnionTypeDefinition) NonUniqueNameError(graphql.schema.idl.errors.NonUniqueNameError) OperationTypesMustBeObjects(graphql.schema.idl.errors.OperationTypesMustBeObjects) InvalidDeprecationDirectiveError(graphql.schema.idl.errors.InvalidDeprecationDirectiveError) MissingInterfaceFieldArgumentsError(graphql.schema.idl.errors.MissingInterfaceFieldArgumentsError) Directive(graphql.language.Directive) Consumer(java.util.function.Consumer) Argument(graphql.language.Argument) StringValue(graphql.language.StringValue) Collections(java.util.Collections) InvalidDeprecationDirectiveError(graphql.schema.idl.errors.InvalidDeprecationDirectiveError) BiFunction(java.util.function.BiFunction) EnumValueDefinition(graphql.language.EnumValueDefinition) NonUniqueArgumentError(graphql.schema.idl.errors.NonUniqueArgumentError) NonUniqueDirectiveError(graphql.schema.idl.errors.NonUniqueDirectiveError) NonUniqueNameError(graphql.schema.idl.errors.NonUniqueNameError) Directive(graphql.language.Directive)

Example 12 with InputValueDefinition

use of graphql.language.InputValueDefinition 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) {
    typeRegistry.inputObjectTypeExtensions().forEach((name, extensions) -> {
        checkTypeExtensionHasCorrespondingType(errors, typeRegistry, name, extensions, InputObjectTypeDefinition.class);
        checkTypeExtensionDirectiveRedefinition(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 -> checkNamedUniqueness(errors, fld.getDirectives(), Directive::getName, (directiveName, directive) -> new NonUniqueDirectiveError(extension, fld, directiveName)));
            inputValueDefinitions.forEach(fld -> fld.getDirectives().forEach(directive -> {
                checkDeprecatedDirective(errors, directive, () -> new InvalidDeprecationDirectiveError(extension, fld));
                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 : NonUniqueDirectiveError(graphql.schema.idl.errors.NonUniqueDirectiveError) Internal(graphql.Internal) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) InputValueDefinition(graphql.language.InputValueDefinition) EnumTypeDefinition(graphql.language.EnumTypeDefinition) TypeExtensionFieldRedefinitionError(graphql.schema.idl.errors.TypeExtensionFieldRedefinitionError) Type(graphql.language.Type) UnionTypeDefinition(graphql.language.UnionTypeDefinition) EnumValueDefinition(graphql.language.EnumValueDefinition) GraphQLError(graphql.GraphQLError) TypeExtensionDirectiveRedefinitionError(graphql.schema.idl.errors.TypeExtensionDirectiveRedefinitionError) 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) InvalidDeprecationDirectiveError(graphql.schema.idl.errors.InvalidDeprecationDirectiveError) SchemaTypeChecker.checkDeprecatedDirective(graphql.schema.idl.SchemaTypeChecker.checkDeprecatedDirective) TypeDefinition(graphql.language.TypeDefinition) Collectors(java.util.stream.Collectors) Directive(graphql.language.Directive) Consumer(java.util.function.Consumer) Argument(graphql.language.Argument) AstPrinter(graphql.language.AstPrinter) 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) InvalidDeprecationDirectiveError(graphql.schema.idl.errors.InvalidDeprecationDirectiveError) NonUniqueArgumentError(graphql.schema.idl.errors.NonUniqueArgumentError) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) NonUniqueDirectiveError(graphql.schema.idl.errors.NonUniqueDirectiveError) InputValueDefinition(graphql.language.InputValueDefinition) NonUniqueNameError(graphql.schema.idl.errors.NonUniqueNameError)

Example 13 with InputValueDefinition

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

the class SchemaTypeExtensionsChecker method checkObjectTypeExtensions.

/*
     * Object type extensions have the potential to be invalid if incorrectly defined.
     *
     * The named type must already be defined and must be an Object type.
     * The fields of an Object type extension must have unique names; no two fields may share the same name.
     * Any fields of an Object type extension must not be already defined on the original Object type.
     * Any directives provided must not already apply to the original Object type.
     * Any interfaces provided must not be already implemented by the original Object type.
     * The resulting extended object type must be a super-set of all interfaces it implements.
     */
private void checkObjectTypeExtensions(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry) {
    typeRegistry.objectTypeExtensions().forEach((name, extensions) -> {
        checkTypeExtensionHasCorrespondingType(errors, typeRegistry, name, extensions, ObjectTypeDefinition.class);
        checkTypeExtensionDirectiveRedefinition(errors, typeRegistry, name, extensions, ObjectTypeDefinition.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
            extension.getFieldDefinitions().forEach(fld -> checkNamedUniqueness(errors, fld.getDirectives(), Directive::getName, (directiveName, directive) -> new NonUniqueDirectiveError(extension, fld, directiveName)));
            fieldDefinitions.forEach(fld -> fld.getDirectives().forEach(directive -> {
                checkDeprecatedDirective(errors, directive, () -> new InvalidDeprecationDirectiveError(extension, fld));
                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<ObjectTypeDefinition> baseTypeOpt = typeRegistry.getType(extension.getName(), ObjectTypeDefinition.class);
            baseTypeOpt.ifPresent(baseTypeDef -> checkForFieldRedefinition(errors, extension, fieldDefinitions, baseTypeDef.getFieldDefinitions()));
        });
    });
}
Also used : NonUniqueDirectiveError(graphql.schema.idl.errors.NonUniqueDirectiveError) Internal(graphql.Internal) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) InputValueDefinition(graphql.language.InputValueDefinition) EnumTypeDefinition(graphql.language.EnumTypeDefinition) TypeExtensionFieldRedefinitionError(graphql.schema.idl.errors.TypeExtensionFieldRedefinitionError) Type(graphql.language.Type) UnionTypeDefinition(graphql.language.UnionTypeDefinition) EnumValueDefinition(graphql.language.EnumValueDefinition) GraphQLError(graphql.GraphQLError) TypeExtensionDirectiveRedefinitionError(graphql.schema.idl.errors.TypeExtensionDirectiveRedefinitionError) 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) InvalidDeprecationDirectiveError(graphql.schema.idl.errors.InvalidDeprecationDirectiveError) SchemaTypeChecker.checkDeprecatedDirective(graphql.schema.idl.SchemaTypeChecker.checkDeprecatedDirective) TypeDefinition(graphql.language.TypeDefinition) Collectors(java.util.stream.Collectors) Directive(graphql.language.Directive) Consumer(java.util.function.Consumer) Argument(graphql.language.Argument) AstPrinter(graphql.language.AstPrinter) 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) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) ObjectTypeDefinition(graphql.language.ObjectTypeDefinition) InvalidDeprecationDirectiveError(graphql.schema.idl.errors.InvalidDeprecationDirectiveError) FieldDefinition(graphql.language.FieldDefinition) NonUniqueArgumentError(graphql.schema.idl.errors.NonUniqueArgumentError) NonUniqueDirectiveError(graphql.schema.idl.errors.NonUniqueDirectiveError) NonUniqueNameError(graphql.schema.idl.errors.NonUniqueNameError)

Example 14 with InputValueDefinition

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

the class GraphqlAntlrToLanguage method visitTypeName.

// MARKER END: Here GraphqlOperation.g4 specific methods end
@Override
public Void visitTypeName(GraphqlParser.TypeNameContext ctx) {
    TypeName typeName = new TypeName(ctx.name().getText());
    newNode(typeName, ctx);
    for (ContextEntry contextEntry : contextStack) {
        if (contextEntry.value instanceof ListType) {
            ((ListType) contextEntry.value).setType(typeName);
            break;
        }
        if (contextEntry.value instanceof NonNullType) {
            ((NonNullType) contextEntry.value).setType(typeName);
            break;
        }
        if (contextEntry.value instanceof VariableDefinition) {
            ((VariableDefinition) contextEntry.value).setType(typeName);
            break;
        }
        if (contextEntry.value instanceof FieldDefinition) {
            ((FieldDefinition) contextEntry.value).setType(typeName);
            break;
        }
        if (contextEntry.value instanceof InputValueDefinition) {
            ((InputValueDefinition) contextEntry.value).setType(typeName);
            break;
        }
        if (contextEntry.contextProperty == ContextProperty.ObjectTypeDefinition) {
            ((ObjectTypeDefinition) contextEntry.value).getImplements().add(typeName);
            break;
        }
        if (contextEntry.contextProperty == ContextProperty.UnionTypeDefinition) {
            ((UnionTypeDefinition) contextEntry.value).getMemberTypes().add(typeName);
            break;
        }
        if (contextEntry.contextProperty == ContextProperty.OperationTypeDefinition) {
            ((OperationTypeDefinition) contextEntry.value).setType(typeName);
            break;
        }
    }
    return super.visitTypeName(ctx);
}
Also used : TypeName(graphql.language.TypeName) VariableDefinition(graphql.language.VariableDefinition) NonNullType(graphql.language.NonNullType) ListType(graphql.language.ListType) FieldDefinition(graphql.language.FieldDefinition) InputValueDefinition(graphql.language.InputValueDefinition) OperationTypeDefinition(graphql.language.OperationTypeDefinition)

Example 15 with InputValueDefinition

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

the class GraphqlAntlrToLanguage method visitListType.

@Override
public Void visitListType(GraphqlParser.ListTypeContext ctx) {
    ListType listType = new ListType();
    newNode(listType, ctx);
    for (ContextEntry contextEntry : contextStack) {
        if (contextEntry.value instanceof ListType) {
            ((ListType) contextEntry.value).setType(listType);
            break;
        }
        if (contextEntry.value instanceof NonNullType) {
            ((NonNullType) contextEntry.value).setType(listType);
            break;
        }
        if (contextEntry.value instanceof VariableDefinition) {
            ((VariableDefinition) contextEntry.value).setType(listType);
            break;
        }
        if (contextEntry.value instanceof FieldDefinition) {
            ((FieldDefinition) contextEntry.value).setType(listType);
            break;
        }
        if (contextEntry.value instanceof InputValueDefinition) {
            ((InputValueDefinition) contextEntry.value).setType(listType);
            break;
        }
    }
    addContextProperty(ContextProperty.ListType, listType);
    super.visitListType(ctx);
    popContext();
    return null;
}
Also used : VariableDefinition(graphql.language.VariableDefinition) NonNullType(graphql.language.NonNullType) ListType(graphql.language.ListType) FieldDefinition(graphql.language.FieldDefinition) InputValueDefinition(graphql.language.InputValueDefinition)

Aggregations

InputValueDefinition (graphql.language.InputValueDefinition)19 FieldDefinition (graphql.language.FieldDefinition)11 Map (java.util.Map)10 InputObjectTypeDefinition (graphql.language.InputObjectTypeDefinition)9 List (java.util.List)9 Directive (graphql.language.Directive)8 EnumTypeDefinition (graphql.language.EnumTypeDefinition)8 EnumValueDefinition (graphql.language.EnumValueDefinition)8 Type (graphql.language.Type)8 TypeName (graphql.language.TypeName)8 GraphQLError (graphql.GraphQLError)7 Internal (graphql.Internal)7 Argument (graphql.language.Argument)7 AstPrinter (graphql.language.AstPrinter)7 InterfaceTypeDefinition (graphql.language.InterfaceTypeDefinition)7 ObjectTypeDefinition (graphql.language.ObjectTypeDefinition)7 TypeDefinition (graphql.language.TypeDefinition)7 UnionTypeDefinition (graphql.language.UnionTypeDefinition)7 InvalidDeprecationDirectiveError (graphql.schema.idl.errors.InvalidDeprecationDirectiveError)7 MissingTypeError (graphql.schema.idl.errors.MissingTypeError)7