graphql.language.NullValue Java Examples
The following examples show how to use
graphql.language.NullValue.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: _Any.java From federation-jvm with MIT License | 5 votes |
@Nullable @Override public Object parseLiteral(Object input) throws CoercingParseLiteralException { if (input instanceof NullValue) { return null; } else if (input instanceof FloatValue) { return ((FloatValue) input).getValue(); } else if (input instanceof StringValue) { return ((StringValue) input).getValue(); } else if (input instanceof IntValue) { return ((IntValue) input).getValue(); } else if (input instanceof BooleanValue) { return ((BooleanValue) input).isValue(); } else if (input instanceof EnumValue) { return ((EnumValue) input).getName(); } else if (input instanceof ArrayValue) { return ((ArrayValue) input).getValues() .stream() .map(this::parseLiteral) .collect(Collectors.toList()); } else if (input instanceof ObjectValue) { return ((ObjectValue) input).getObjectFields() .stream() .collect(Collectors.toMap(ObjectField::getName, f -> parseLiteral(f.getValue()))); } return Assert.assertShouldNeverHappen(); }
Example #2
Source File: GsonScalars.java From graphql-spqr with Apache License 2.0 | 5 votes |
@Override public JsonElement parseLiteral(Object input) { if (input instanceof ObjectValue || input instanceof ArrayValue) { throw literalParsingException(input, StringValue.class, BooleanValue.class, EnumValue.class, FloatValue.class, IntValue.class, NullValue.class); } return parseJsonValue(((Value) input)); }
Example #3
Source File: GsonScalars.java From graphql-spqr with Apache License 2.0 | 5 votes |
private static JsonElement parseJsonValue(Value value) { if (value instanceof BooleanValue) { return new JsonPrimitive(((BooleanValue) value).isValue()); } if (value instanceof EnumValue) { return new JsonPrimitive(((EnumValue) value).getName()); } if (value instanceof FloatValue) { return new JsonPrimitive(((FloatValue) value).getValue()); } if (value instanceof IntValue) { return new JsonPrimitive(((IntValue) value).getValue()); } if (value instanceof NullValue) { return JsonNull.INSTANCE; } if (value instanceof StringValue) { return new JsonPrimitive(((StringValue) value).getValue()); } if (value instanceof ArrayValue) { List<Value> values = ((ArrayValue) value).getValues(); JsonArray jsonArray = new JsonArray(values.size()); values.forEach(v -> jsonArray.add(parseJsonValue(v))); return jsonArray; } if (value instanceof ObjectValue) { final JsonObject result = new JsonObject(); ((ObjectValue) value).getObjectFields().forEach(objectField -> result.add(objectField.getName(), parseJsonValue(objectField.getValue()))); return result; } //Should never happen, as it would mean the variable was not replaced by the parser throw new CoercingParseLiteralException("Unknown scalar AST type: " + value.getClass().getName()); }
Example #4
Source File: JacksonObjectScalars.java From graphql-spqr with Apache License 2.0 | 5 votes |
private static JsonNode parseJsonValue(Value value, Map<String, Object> variables) { if (value instanceof BooleanValue) { return JsonNodeFactory.instance.booleanNode(((BooleanValue) value).isValue()); } if (value instanceof EnumValue) { return JsonNodeFactory.instance.textNode(((EnumValue) value).getName()); } if (value instanceof FloatValue) { return JsonNodeFactory.instance.numberNode(((FloatValue) value).getValue()); } if (value instanceof IntValue) { return JsonNodeFactory.instance.numberNode(((IntValue) value).getValue()); } if (value instanceof NullValue) { return JsonNodeFactory.instance.nullNode(); } if (value instanceof StringValue) { return JsonNodeFactory.instance.textNode(((StringValue) value).getValue()); } if (value instanceof ArrayValue) { List<Value> values = ((ArrayValue) value).getValues(); ArrayNode jsonArray = JsonNodeFactory.instance.arrayNode(values.size()); values.forEach(v -> jsonArray.add(parseJsonValue(v, variables))); return jsonArray; } if (value instanceof VariableReference) { return OBJECT_MAPPER.convertValue(variables.get(((VariableReference) value).getName()), JsonNode.class); } if (value instanceof ObjectValue) { final ObjectNode result = JsonNodeFactory.instance.objectNode(); ((ObjectValue) value).getObjectFields().forEach(objectField -> result.set(objectField.getName(), parseJsonValue(objectField.getValue(), variables))); return result; } //Should never happen throw new CoercingParseLiteralException("Unknown scalar AST type: " + value.getClass().getName()); }