Search in sources :

Example 1 with NullValue

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

the class SchemaGeneratorHelper method buildValue.

public Object buildValue(Value value, GraphQLType requiredType) {
    Object result = null;
    if (requiredType instanceof GraphQLNonNull) {
        requiredType = ((GraphQLNonNull) requiredType).getWrappedType();
    }
    if (requiredType instanceof GraphQLScalarType) {
        result = parseLiteral(value, (GraphQLScalarType) requiredType);
    } else if (value instanceof EnumValue && requiredType instanceof GraphQLEnumType) {
        result = ((EnumValue) value).getName();
    } else if (value instanceof ArrayValue && requiredType instanceof GraphQLList) {
        ArrayValue arrayValue = (ArrayValue) value;
        GraphQLType wrappedType = ((GraphQLList) requiredType).getWrappedType();
        result = arrayValue.getValues().stream().map(item -> this.buildValue(item, wrappedType)).collect(Collectors.toList());
    } else if (value instanceof ObjectValue && requiredType instanceof GraphQLInputObjectType) {
        result = buildObjectValue((ObjectValue) value, (GraphQLInputObjectType) requiredType);
    } else if (value != null && !(value instanceof NullValue)) {
        Assert.assertShouldNeverHappen("cannot build value of %s from %s", requiredType.getName(), String.valueOf(value));
    }
    return result;
}
Also used : GraphQLList(graphql.schema.GraphQLList) ObjectValue(graphql.language.ObjectValue) NullValue(graphql.language.NullValue) GraphQLEnumType(graphql.schema.GraphQLEnumType) EnumValue(graphql.language.EnumValue) GraphQLInputObjectType(graphql.schema.GraphQLInputObjectType) GraphQLNonNull(graphql.schema.GraphQLNonNull) GraphQLType(graphql.schema.GraphQLType) ArrayValue(graphql.language.ArrayValue) GraphQLScalarType(graphql.schema.GraphQLScalarType)

Aggregations

ArrayValue (graphql.language.ArrayValue)1 EnumValue (graphql.language.EnumValue)1 NullValue (graphql.language.NullValue)1 ObjectValue (graphql.language.ObjectValue)1 GraphQLEnumType (graphql.schema.GraphQLEnumType)1 GraphQLInputObjectType (graphql.schema.GraphQLInputObjectType)1 GraphQLList (graphql.schema.GraphQLList)1 GraphQLNonNull (graphql.schema.GraphQLNonNull)1 GraphQLScalarType (graphql.schema.GraphQLScalarType)1 GraphQLType (graphql.schema.GraphQLType)1