Search in sources :

Example 1 with IntValue

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

the class GraphqlAntlrToLanguage method getValue.

private Value getValue(GraphqlParser.ValueWithVariableContext ctx) {
    if (ctx.IntValue() != null) {
        IntValue intValue = new IntValue(new BigInteger(ctx.IntValue().getText()));
        newNode(intValue, ctx);
        return intValue;
    } else if (ctx.FloatValue() != null) {
        FloatValue floatValue = new FloatValue(new BigDecimal(ctx.FloatValue().getText()));
        newNode(floatValue, ctx);
        return floatValue;
    } else if (ctx.BooleanValue() != null) {
        BooleanValue booleanValue = new BooleanValue(Boolean.parseBoolean(ctx.BooleanValue().getText()));
        newNode(booleanValue, ctx);
        return booleanValue;
    } else if (ctx.NullValue() != null) {
        newNode(Null, ctx);
        return Null;
    } else if (ctx.stringValue() != null) {
        StringValue stringValue = new StringValue(quotedString(ctx.stringValue()));
        newNode(stringValue, ctx);
        return stringValue;
    } else if (ctx.enumValue() != null) {
        EnumValue enumValue = new EnumValue(ctx.enumValue().getText());
        newNode(enumValue, ctx);
        return enumValue;
    } else if (ctx.arrayValueWithVariable() != null) {
        ArrayValue arrayValue = new ArrayValue();
        newNode(arrayValue, ctx);
        for (GraphqlParser.ValueWithVariableContext valueWithVariableContext : ctx.arrayValueWithVariable().valueWithVariable()) {
            arrayValue.getValues().add(getValue(valueWithVariableContext));
        }
        return arrayValue;
    } else if (ctx.objectValueWithVariable() != null) {
        ObjectValue objectValue = new ObjectValue();
        newNode(objectValue, ctx);
        for (GraphqlParser.ObjectFieldWithVariableContext objectFieldWithVariableContext : ctx.objectValueWithVariable().objectFieldWithVariable()) {
            ObjectField objectField = new ObjectField(objectFieldWithVariableContext.name().getText(), getValue(objectFieldWithVariableContext.valueWithVariable()));
            objectValue.getObjectFields().add(objectField);
        }
        return objectValue;
    } else if (ctx.variable() != null) {
        VariableReference variableReference = new VariableReference(ctx.variable().name().getText());
        newNode(variableReference, ctx);
        return variableReference;
    }
    return Assert.assertShouldNeverHappen();
}
Also used : VariableReference(graphql.language.VariableReference) EnumValue(graphql.language.EnumValue) BigDecimal(java.math.BigDecimal) ObjectValue(graphql.language.ObjectValue) GraphqlParser(graphql.parser.antlr.GraphqlParser) BooleanValue(graphql.language.BooleanValue) ObjectField(graphql.language.ObjectField) BigInteger(java.math.BigInteger) FloatValue(graphql.language.FloatValue) StringValue(graphql.language.StringValue) IntValue(graphql.language.IntValue) ArrayValue(graphql.language.ArrayValue)

Example 2 with IntValue

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

the class GraphqlAntlrToLanguage method getValue.

private Value getValue(GraphqlParser.ValueContext ctx) {
    if (ctx.IntValue() != null) {
        IntValue intValue = new IntValue(new BigInteger(ctx.IntValue().getText()));
        newNode(intValue, ctx);
        return intValue;
    } else if (ctx.FloatValue() != null) {
        FloatValue floatValue = new FloatValue(new BigDecimal(ctx.FloatValue().getText()));
        newNode(floatValue, ctx);
        return floatValue;
    } else if (ctx.BooleanValue() != null) {
        BooleanValue booleanValue = new BooleanValue(Boolean.parseBoolean(ctx.BooleanValue().getText()));
        newNode(booleanValue, ctx);
        return booleanValue;
    } else if (ctx.NullValue() != null) {
        newNode(Null, ctx);
        return Null;
    } else if (ctx.stringValue() != null) {
        StringValue stringValue = new StringValue(quotedString(ctx.stringValue()));
        newNode(stringValue, ctx);
        return stringValue;
    } else if (ctx.enumValue() != null) {
        EnumValue enumValue = new EnumValue(ctx.enumValue().getText());
        newNode(enumValue, ctx);
        return enumValue;
    } else if (ctx.arrayValue() != null) {
        ArrayValue arrayValue = new ArrayValue();
        newNode(arrayValue, ctx);
        for (GraphqlParser.ValueContext valueWithVariableContext : ctx.arrayValue().value()) {
            arrayValue.getValues().add(getValue(valueWithVariableContext));
        }
        return arrayValue;
    } else if (ctx.objectValue() != null) {
        ObjectValue objectValue = new ObjectValue();
        newNode(objectValue, ctx);
        for (GraphqlParser.ObjectFieldContext objectFieldContext : ctx.objectValue().objectField()) {
            ObjectField objectField = new ObjectField(objectFieldContext.name().getText(), getValue(objectFieldContext.value()));
            objectValue.getObjectFields().add(objectField);
        }
        return objectValue;
    }
    return Assert.assertShouldNeverHappen();
}
Also used : EnumValue(graphql.language.EnumValue) BigDecimal(java.math.BigDecimal) ObjectValue(graphql.language.ObjectValue) GraphqlParser(graphql.parser.antlr.GraphqlParser) BooleanValue(graphql.language.BooleanValue) ObjectField(graphql.language.ObjectField) BigInteger(java.math.BigInteger) FloatValue(graphql.language.FloatValue) StringValue(graphql.language.StringValue) IntValue(graphql.language.IntValue) ArrayValue(graphql.language.ArrayValue)

Example 3 with IntValue

use of graphql.language.IntValue in project structr by structr.

the class QueryConfig method castValue.

private Object castValue(final SecurityContext securityContext, final Class type, final PropertyKey key, final Value value) throws FrameworkException {
    if (value instanceof StringValue) {
        return getStringValue(value, null);
    }
    if (value instanceof IntValue) {
        return getIntegerValue(value, -1);
    }
    if (value instanceof BooleanValue) {
        return getBooleanValue(value, false);
    }
    if (value instanceof ObjectValue && key != null) {
        final Map<String, Object> parameters = new LinkedHashMap<>();
        parameters.put(key.jsonName(), getMapValue(securityContext, type, value));
        final PropertyMap propertyMap = PropertyMap.inputTypeToJavaType(securityContext, type, parameters);
        // return converted result (should be replaced by NodeInterface)
        return propertyMap.get(key);
    }
    return null;
}
Also used : ObjectValue(graphql.language.ObjectValue) PropertyMap(org.structr.core.property.PropertyMap) BooleanValue(graphql.language.BooleanValue) GraphObject(org.structr.core.GraphObject) StringValue(graphql.language.StringValue) IntValue(graphql.language.IntValue) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

BooleanValue (graphql.language.BooleanValue)3 IntValue (graphql.language.IntValue)3 ObjectValue (graphql.language.ObjectValue)3 StringValue (graphql.language.StringValue)3 ArrayValue (graphql.language.ArrayValue)2 EnumValue (graphql.language.EnumValue)2 FloatValue (graphql.language.FloatValue)2 ObjectField (graphql.language.ObjectField)2 GraphqlParser (graphql.parser.antlr.GraphqlParser)2 BigDecimal (java.math.BigDecimal)2 BigInteger (java.math.BigInteger)2 VariableReference (graphql.language.VariableReference)1 LinkedHashMap (java.util.LinkedHashMap)1 GraphObject (org.structr.core.GraphObject)1 PropertyMap (org.structr.core.property.PropertyMap)1