Search in sources :

Example 11 with DirectiveDefinition

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

the class SchemaTypeChecker method checkObjTypeFields.

private void checkObjTypeFields(List<GraphQLError> errors, ObjectTypeDefinition typeDefinition, List<FieldDefinition> fieldDefinitions, Map<String, DirectiveDefinition> directiveDefinitionMap) {
    // field unique ness
    checkNamedUniqueness(errors, fieldDefinitions, FieldDefinition::getName, (name, fieldDef) -> new NonUniqueNameError(typeDefinition, fieldDef));
    // field arg unique ness
    fieldDefinitions.forEach(fld -> checkNamedUniqueness(errors, fld.getInputValueDefinitions(), InputValueDefinition::getName, (name, inputValueDefinition) -> new NonUniqueArgumentError(typeDefinition, fld, name)));
    // directive checks
    fieldDefinitions.forEach(fld -> fld.getDirectives().forEach(directive -> {
        checkNamedUniqueness(errors, directive.getArguments(), Argument::getName, (argumentName, argument) -> new NonUniqueArgumentError(typeDefinition, fld, 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)

Example 12 with DirectiveDefinition

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

the class SchemaTypeChecker method checkDirectiveDefinitions.

private void checkDirectiveDefinitions(TypeDefinitionRegistry typeRegistry, List<GraphQLError> errors) {
    List<DirectiveDefinition> directiveDefinitions = new ArrayList<>(typeRegistry.getDirectiveDefinitions().values());
    directiveDefinitions.forEach(directiveDefinition -> {
        List<InputValueDefinition> arguments = directiveDefinition.getInputValueDefinitions();
        checkNamedUniqueness(errors, arguments, InputValueDefinition::getName, (name, arg) -> new NonUniqueNameError(directiveDefinition, arg));
        List<Type> inputValueTypes = arguments.stream().map(InputValueDefinition::getType).collect(toList());
        inputValueTypes.forEach(checkTypeExists(typeRegistry, errors, "directive definition", directiveDefinition, directiveDefinition.getName()));
        directiveDefinition.getDirectiveLocations().forEach(directiveLocation -> {
            String locationName = directiveLocation.getName();
            try {
                Introspection.DirectiveLocation.valueOf(locationName);
            } catch (IllegalArgumentException e) {
                errors.add(new DirectiveIllegalLocationError(directiveDefinition, locationName));
            }
        });
    });
}
Also used : Type(graphql.language.Type) DirectiveIllegalLocationError(graphql.schema.idl.errors.DirectiveIllegalLocationError) ArrayList(java.util.ArrayList) DirectiveDefinition(graphql.language.DirectiveDefinition) InputValueDefinition(graphql.language.InputValueDefinition) NonUniqueNameError(graphql.schema.idl.errors.NonUniqueNameError)

Example 13 with DirectiveDefinition

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

the class SchemaTypeExtensionsChecker method checkUnionTypeExtensions.

/*
     * Union type extensions have the potential to be invalid if incorrectly defined.
     *
     * The named type must already be defined and must be a Union type.
     * The member types of a Union type extension must all be Object base types; Scalar, Interface and Union types must not be member types of a Union. Similarly, wrapping types must not be member types of a Union.
     * All member types of a Union type extension must be unique.
     * All member types of a Union type extension must not already be a member of the original Union type.
     * Any directives provided must not already apply to the original Union type.
     */
private void checkUnionTypeExtensions(List<GraphQLError> errors, TypeDefinitionRegistry typeRegistry, Map<String, DirectiveDefinition> directiveDefinitionMap) {
    typeRegistry.unionTypeExtensions().forEach((name, extensions) -> {
        checkTypeExtensionHasCorrespondingType(errors, typeRegistry, name, extensions, UnionTypeDefinition.class);
        extensions.forEach(extension -> {
            List<TypeName> memberTypes = extension.getMemberTypes().stream().map(t -> TypeInfo.typeInfo(t).getTypeName()).collect(Collectors.toList());
            checkNamedUniqueness(errors, memberTypes, TypeName::getName, (namedMember, memberType) -> new NonUniqueNameError(extension, namedMember));
            memberTypes.forEach(memberType -> {
                Optional<ObjectTypeDefinition> unionTypeDefinition = typeRegistry.getType(memberType, ObjectTypeDefinition.class);
                if (!unionTypeDefinition.isPresent()) {
                    errors.add(new MissingTypeError("union member", extension, memberType));
                }
            });
        });
    });
}
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) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) ObjectTypeDefinition(graphql.language.ObjectTypeDefinition) TypeName(graphql.language.TypeName) MissingTypeError(graphql.schema.idl.errors.MissingTypeError) NonUniqueNameError(graphql.schema.idl.errors.NonUniqueNameError)

Example 14 with DirectiveDefinition

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

the class TypeDefinitionRegistry method add.

/**
 * Adds a definition to the registry
 *
 * @param definition the definition to add
 *
 * @return an optional error
 */
public Optional<GraphQLError> add(SDLDefinition definition) {
    // extensions
    if (definition instanceof ObjectTypeExtensionDefinition) {
        ObjectTypeExtensionDefinition newEntry = (ObjectTypeExtensionDefinition) definition;
        return defineExt(objectTypeExtensions, newEntry, ObjectTypeExtensionDefinition::getName);
    } else if (definition instanceof InterfaceTypeExtensionDefinition) {
        InterfaceTypeExtensionDefinition newEntry = (InterfaceTypeExtensionDefinition) definition;
        return defineExt(interfaceTypeExtensions, newEntry, InterfaceTypeExtensionDefinition::getName);
    } else if (definition instanceof UnionTypeExtensionDefinition) {
        UnionTypeExtensionDefinition newEntry = (UnionTypeExtensionDefinition) definition;
        return defineExt(unionTypeExtensions, newEntry, UnionTypeExtensionDefinition::getName);
    } else if (definition instanceof EnumTypeExtensionDefinition) {
        EnumTypeExtensionDefinition newEntry = (EnumTypeExtensionDefinition) definition;
        return defineExt(enumTypeExtensions, newEntry, EnumTypeExtensionDefinition::getName);
    } else if (definition instanceof ScalarTypeExtensionDefinition) {
        ScalarTypeExtensionDefinition newEntry = (ScalarTypeExtensionDefinition) definition;
        return defineExt(scalarTypeExtensions, newEntry, ScalarTypeExtensionDefinition::getName);
    } else if (definition instanceof InputObjectTypeExtensionDefinition) {
        InputObjectTypeExtensionDefinition newEntry = (InputObjectTypeExtensionDefinition) definition;
        return defineExt(inputObjectTypeExtensions, newEntry, InputObjectTypeExtensionDefinition::getName);
    } else if (definition instanceof SchemaExtensionDefinition) {
        schemaExtensionDefinitions.add((SchemaExtensionDefinition) definition);
        schemaParseOrder.addDefinition(definition);
        Optional<GraphQLError> error = checkAddOperationDefs();
        if (error.isPresent()) {
            return error;
        }
    } else if (definition instanceof ScalarTypeDefinition) {
        ScalarTypeDefinition newEntry = (ScalarTypeDefinition) definition;
        return define(scalarTypes, scalarTypes, newEntry);
    } else if (definition instanceof TypeDefinition) {
        TypeDefinition newEntry = (TypeDefinition) definition;
        return define(types, types, newEntry);
    } else if (definition instanceof DirectiveDefinition) {
        DirectiveDefinition newEntry = (DirectiveDefinition) definition;
        return define(directiveDefinitions, directiveDefinitions, newEntry);
    } else if (definition instanceof SchemaDefinition) {
        SchemaDefinition newSchema = (SchemaDefinition) definition;
        if (schema != null) {
            return Optional.of(new SchemaRedefinitionError(this.schema, newSchema));
        } else {
            schema = newSchema;
            schemaParseOrder.addDefinition(newSchema);
        }
        Optional<GraphQLError> error = checkAddOperationDefs();
        if (error.isPresent()) {
            return error;
        }
    } else {
        return Assert.assertShouldNeverHappen();
    }
    return Optional.empty();
}
Also used : SchemaDefinition(graphql.language.SchemaDefinition) SchemaRedefinitionError(graphql.schema.idl.errors.SchemaRedefinitionError) ObjectTypeExtensionDefinition(graphql.language.ObjectTypeExtensionDefinition) InputObjectTypeExtensionDefinition(graphql.language.InputObjectTypeExtensionDefinition) InterfaceTypeExtensionDefinition(graphql.language.InterfaceTypeExtensionDefinition) EnumTypeExtensionDefinition(graphql.language.EnumTypeExtensionDefinition) SchemaExtensionDefinition(graphql.language.SchemaExtensionDefinition) ScalarTypeExtensionDefinition(graphql.language.ScalarTypeExtensionDefinition) ImplementingTypeDefinition(graphql.language.ImplementingTypeDefinition) UnionTypeDefinition(graphql.language.UnionTypeDefinition) OperationTypeDefinition(graphql.language.OperationTypeDefinition) ScalarTypeDefinition(graphql.language.ScalarTypeDefinition) ObjectTypeDefinition(graphql.language.ObjectTypeDefinition) TypeDefinition(graphql.language.TypeDefinition) InterfaceTypeDefinition(graphql.language.InterfaceTypeDefinition) ScalarTypeDefinition(graphql.language.ScalarTypeDefinition) InputObjectTypeExtensionDefinition(graphql.language.InputObjectTypeExtensionDefinition) UnionTypeExtensionDefinition(graphql.language.UnionTypeExtensionDefinition) GraphQLError(graphql.GraphQLError) DirectiveDefinition(graphql.language.DirectiveDefinition)

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