use of graphql.language.EnumValue 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();
}
use of graphql.language.EnumValue 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();
}
use of graphql.language.EnumValue 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;
}
Aggregations