Search in sources :

Example 6 with GraphQLInputType

use of graphql.schema.GraphQLInputType in project graphql-java by graphql-java.

the class NoUnbrokenInputCycles method check.

@Override
public void check(GraphQLFieldDefinition fieldDef, SchemaValidationErrorCollector validationErrorCollector) {
    for (GraphQLArgument argument : fieldDef.getArguments()) {
        GraphQLInputType argumentType = argument.getType();
        if (argumentType instanceof GraphQLInputObjectType) {
            List<String> path = new ArrayList<>();
            path.add(argumentType.getName());
            check((GraphQLInputObjectType) argumentType, new HashSet<>(), path, validationErrorCollector);
        }
    }
}
Also used : GraphQLInputType(graphql.schema.GraphQLInputType) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) ArrayList(java.util.ArrayList) GraphQLArgument(graphql.schema.GraphQLArgument)

Example 7 with GraphQLInputType

use of graphql.schema.GraphQLInputType in project graphql-java by graphql-java.

the class VariableTypesMatchRule method checkVariable.

@Override
public void checkVariable(VariableReference variableReference) {
    VariableDefinition variableDefinition = variableDefinitionMap.get(variableReference.getName());
    if (variableDefinition == null) {
        return;
    }
    GraphQLType variableType = TypeFromAST.getTypeFromAST(getValidationContext().getSchema(), variableDefinition.getType());
    if (variableType == null) {
        return;
    }
    GraphQLInputType expectedType = getValidationContext().getInputType();
    if (expectedType == null) {
        // we must have a unknown variable say to not have a known type
        return;
    }
    if (!variablesTypesMatcher.doesVariableTypesMatch(variableType, variableDefinition.getDefaultValue(), expectedType)) {
        GraphQLType effectiveType = variablesTypesMatcher.effectiveType(variableType, variableDefinition.getDefaultValue());
        String message = String.format("Variable type '%s' doesn't match expected type '%s'", GraphQLTypeUtil.getUnwrappedTypeName(effectiveType), GraphQLTypeUtil.getUnwrappedTypeName(expectedType));
        addError(ValidationErrorType.VariableTypeMismatch, variableReference.getSourceLocation(), message);
    }
}
Also used : GraphQLInputType(graphql.schema.GraphQLInputType) VariableDefinition(graphql.language.VariableDefinition) GraphQLType(graphql.schema.GraphQLType)

Example 8 with GraphQLInputType

use of graphql.schema.GraphQLInputType in project graphql-java by graphql-java.

the class SchemaGenerator method buildInputType.

private GraphQLInputType buildInputType(BuildContext buildCtx, Type rawType) {
    TypeDefinition typeDefinition = buildCtx.getTypeDefinition(rawType);
    TypeInfo typeInfo = TypeInfo.typeInfo(rawType);
    GraphQLInputType inputType = buildCtx.hasInputType(typeDefinition);
    if (inputType != null) {
        return typeInfo.decorate(inputType);
    }
    if (buildCtx.stackContains(typeInfo)) {
        // we have circled around so put in a type reference and fix it later
        return typeInfo.decorate(typeRef(typeInfo.getName()));
    }
    buildCtx.push(typeInfo);
    if (typeDefinition instanceof InputObjectTypeDefinition) {
        inputType = buildInputObjectType(buildCtx, (InputObjectTypeDefinition) typeDefinition);
    } else if (typeDefinition instanceof EnumTypeDefinition) {
        inputType = buildEnumType(buildCtx, (EnumTypeDefinition) typeDefinition);
    } else if (typeDefinition instanceof ScalarTypeDefinition) {
        inputType = buildScalar(buildCtx, (ScalarTypeDefinition) typeDefinition);
    } else {
        // typeDefinition is not a valid InputType
        throw new NotAnInputTypeError(typeDefinition);
    }
    buildCtx.put(inputType);
    buildCtx.pop();
    return typeInfo.decorate(inputType);
}
Also used : GraphQLInputType(graphql.schema.GraphQLInputType) ScalarTypeDefinition(graphql.language.ScalarTypeDefinition) EnumTypeDefinition(graphql.language.EnumTypeDefinition) NotAnInputTypeError(graphql.schema.idl.errors.NotAnInputTypeError) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) EnumTypeDefinition(graphql.language.EnumTypeDefinition) OperationTypeDefinition(graphql.language.OperationTypeDefinition) ObjectTypeDefinition(graphql.language.ObjectTypeDefinition) TypeDefinition(graphql.language.TypeDefinition) InterfaceTypeDefinition(graphql.language.InterfaceTypeDefinition) InputObjectTypeDefinition(graphql.language.InputObjectTypeDefinition) UnionTypeDefinition(graphql.language.UnionTypeDefinition) ScalarTypeDefinition(graphql.language.ScalarTypeDefinition)

Example 9 with GraphQLInputType

use of graphql.schema.GraphQLInputType in project graphql-java by graphql-java.

the class SchemaGenerator method buildInputField.

private GraphQLInputObjectField buildInputField(BuildContext buildCtx, InputValueDefinition fieldDef) {
    GraphQLInputObjectField.Builder fieldBuilder = GraphQLInputObjectField.newInputObjectField();
    fieldBuilder.definition(fieldDef);
    fieldBuilder.name(fieldDef.getName());
    fieldBuilder.description(schemaGeneratorHelper.buildDescription(fieldDef, fieldDef.getDescription()));
    // currently the spec doesnt allow deprecations on InputValueDefinitions but it should!
    // fieldBuilder.deprecate(buildDeprecationReason(fieldDef.getDirectives()));
    GraphQLInputType inputType = buildInputType(buildCtx, fieldDef.getType());
    fieldBuilder.type(inputType);
    Value defaultValue = fieldDef.getDefaultValue();
    if (defaultValue != null) {
        fieldBuilder.defaultValue(schemaGeneratorHelper.buildValue(defaultValue, inputType));
    }
    fieldBuilder.withDirectives(buildDirectives(fieldDef.getDirectives(), emptyList(), INPUT_FIELD_DEFINITION));
    return fieldBuilder.build();
}
Also used : GraphQLInputType(graphql.schema.GraphQLInputType) GraphQLInputObjectField(graphql.schema.GraphQLInputObjectField) Value(graphql.language.Value)

Example 10 with GraphQLInputType

use of graphql.schema.GraphQLInputType in project graphql-java by graphql-java.

the class SchemaGenerator method buildArgument.

private GraphQLArgument buildArgument(BuildContext buildCtx, InputValueDefinition valueDefinition) {
    GraphQLArgument.Builder builder = GraphQLArgument.newArgument();
    builder.definition(valueDefinition);
    builder.name(valueDefinition.getName());
    builder.description(schemaGeneratorHelper.buildDescription(valueDefinition, valueDefinition.getDescription()));
    GraphQLInputType inputType = buildInputType(buildCtx, valueDefinition.getType());
    builder.type(inputType);
    Value defaultValue = valueDefinition.getDefaultValue();
    if (defaultValue != null) {
        builder.defaultValue(schemaGeneratorHelper.buildValue(defaultValue, inputType));
    }
    return builder.build();
}
Also used : GraphQLInputType(graphql.schema.GraphQLInputType) Value(graphql.language.Value) GraphQLArgument(graphql.schema.GraphQLArgument)

Aggregations

GraphQLInputType (graphql.schema.GraphQLInputType)13 GraphQLInputObjectField (graphql.schema.GraphQLInputObjectField)4 GraphQLArgument (graphql.schema.GraphQLArgument)3 GraphQLInputObjectType (graphql.schema.GraphQLInputObjectType)3 Value (graphql.language.Value)2 GraphQLList (graphql.schema.GraphQLList)2 GraphQLType (graphql.schema.GraphQLType)2 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Scalars (graphql.Scalars)1 EnumTypeDefinition (graphql.language.EnumTypeDefinition)1 InputObjectTypeDefinition (graphql.language.InputObjectTypeDefinition)1 InterfaceTypeDefinition (graphql.language.InterfaceTypeDefinition)1 ObjectTypeDefinition (graphql.language.ObjectTypeDefinition)1 OperationTypeDefinition (graphql.language.OperationTypeDefinition)1 ScalarTypeDefinition (graphql.language.ScalarTypeDefinition)1 TypeDefinition (graphql.language.TypeDefinition)1 UnionTypeDefinition (graphql.language.UnionTypeDefinition)1