private Value getArrayValueWrappedType(ArrayValue value) { // empty array [] is equivalent to [null] if (value.getValues().isEmpty()) { return NullValue.Null; } // get rid of null values List<Value> nonNullValueList = value.getValues().stream() .filter(v -> !(v instanceof NullValue)) .collect(Collectors.toList()); // [null, null, ...] unwrapped is null if (nonNullValueList.isEmpty()) { return NullValue.Null; } // make sure the array isn't polymorphic Set<Class<? extends Value>> distinctTypes = nonNullValueList.stream() .map(Value::getClass) .distinct() .collect(Collectors.toSet()); assertTrue(distinctTypes.size() == 1, "Arrays containing multiple types of values are not supported yet. Detected the following types [%s]", nonNullValueList.stream() .map(Value::getClass) .map(Class::getSimpleName) .distinct() .sorted() .collect(Collectors.joining(","))); // peek at first value, value exists and is assured to be non-null return nonNullValueList.get(0); }
private void checkArgValueMatchesAllowedListType(List<GraphQLError> errors, Value instanceValue, ListType allowedArgType) { if (instanceValue instanceof NullValue) { return; } if (!(instanceValue instanceof ArrayValue)) { addValidationError(errors, EXPECTED_LIST_MESSAGE, instanceValue.getClass().getSimpleName()); return; } ArrayValue arrayValue = ((ArrayValue) instanceValue); Type unwrappedAllowedType = allowedArgType.getType(); // validate each instance value in the list, all instances must match for the list to match arrayValue.getValues().forEach(value -> checkArgValueMatchesAllowedType(errors, value, unwrappedAllowedType)); }
private Object coerceValueAstForList(GraphqlFieldVisibility fieldVisibility, GraphQLList graphQLList, Value value, Map<String, Object> variables) { if (value instanceof ArrayValue) { ArrayValue arrayValue = (ArrayValue) value; List<Object> result = new ArrayList<>(); for (Value singleValue : arrayValue.getValues()) { result.add(coerceValueAst(fieldVisibility, graphQLList.getWrappedType(), singleValue, variables)); } return result; } else { return Collections.singletonList(coerceValueAst(fieldVisibility, graphQLList.getWrappedType(), value, variables)); } }
private boolean isValidLiteralValue(Value value, GraphQLList type, GraphQLSchema schema) { GraphQLType wrappedType = type.getWrappedType(); if (value instanceof ArrayValue) { List<Value> values = ((ArrayValue) value).getValues(); for (int i = 0; i < values.size(); i++) { if (!isValidLiteralValue(values.get(i), wrappedType, schema)) { handleFieldNotValidError(values.get(i), wrappedType, i); return false; } } return true; } else { return isValidLiteralValue(value, wrappedType, schema); } }
private Builder(ArrayValue existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.values = existing.getValues(); this.ignoredChars = existing.getIgnoredChars(); }
private String value(Value value) { String argSep = compactMode ? "," : ", "; if (value instanceof IntValue) { return valueOf(((IntValue) value).getValue()); } else if (value instanceof FloatValue) { return valueOf(((FloatValue) value).getValue()); } else if (value instanceof StringValue) { return wrap("\"", valueOf(((StringValue) value).getValue()), "\""); } else if (value instanceof EnumValue) { return valueOf(((EnumValue) value).getName()); } else if (value instanceof BooleanValue) { return valueOf(((BooleanValue) value).isValue()); } else if (value instanceof NullValue) { return "null"; } else if (value instanceof ArrayValue) { return "[" + join(((ArrayValue) value).getValues(), argSep) + "]"; } else if (value instanceof ObjectValue) { return "{" + join(((ObjectValue) value).getObjectFields(), argSep) + "}"; } else if (value instanceof VariableReference) { return "$" + ((VariableReference) value).getName(); } return ""; }
public Object buildValue(Value value, GraphQLType requiredType) { Object result = null; if (GraphQLTypeUtil.isNonNull(requiredType)) { requiredType = unwrapOne(requiredType); } if (value == null) { return null; } 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 && isList(requiredType)) { ArrayValue arrayValue = (ArrayValue) value; GraphQLType wrappedType = unwrapOne(requiredType); 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 instanceof NullValue)) { assertShouldNeverHappen( "cannot build value of %s from %s", requiredType.getName(), String.valueOf(value)); } return result; }
private Value getArrayValueWrappedType(ArrayValue value) { // empty array [] is equivalent to [null] if (value.getValues().isEmpty()) { return NullValue.Null; } // get rid of null values List<Value> nonNullValueList = value.getValues().stream() .filter(v -> !(v instanceof NullValue)) .collect(Collectors.toList()); // [null, null, ...] unwrapped is null if (nonNullValueList.isEmpty()) { return NullValue.Null; } // make sure the array isn't polymorphic Set<Class<? extends Value>> distinctTypes = nonNullValueList.stream() .map(Value::getClass) .distinct() .collect(Collectors.toSet()); assertTrue(distinctTypes.size() == 1, "Arrays containing multiple types of values are not supported yet. Detected the following types [%s]", nonNullValueList.stream() .map(Value::getClass) .map(Class::getSimpleName) .distinct() .sorted() .collect(Collectors.joining(","))); // peek at first value, value exists and is assured to be non-null return nonNullValueList.get(0); }
private void checkArgValueMatchesAllowedListType(List<GraphQLError> errors, Value instanceValue, ListType allowedArgType) { if (instanceValue instanceof NullValue) { return; } if (!(instanceValue instanceof ArrayValue)) { addValidationError(errors, EXPECTED_LIST_MESSAGE, instanceValue.getClass().getSimpleName()); return; } ArrayValue arrayValue = ((ArrayValue) instanceValue); Type unwrappedAllowedType = allowedArgType.getType(); // validate each instance value in the list, all instances must match for the list to match arrayValue.getValues().forEach(value -> checkArgValueMatchesAllowedType(errors, value, unwrappedAllowedType)); }
private Object coerceValueAstForList(GraphqlFieldVisibility fieldVisibility, GraphQLList graphQLList, Value value, Map<String, Object> variables) { if (value instanceof ArrayValue) { ArrayValue arrayValue = (ArrayValue) value; List<Object> result = new ArrayList<>(); for (Value singleValue : arrayValue.getValues()) { result.add(coerceValueAst(fieldVisibility, graphQLList.getWrappedType(), singleValue, variables)); } return result; } else { return Collections.singletonList(coerceValueAst(fieldVisibility, graphQLList.getWrappedType(), value, variables)); } }
private boolean isValidLiteralValue(Value value, GraphQLList type, GraphQLSchema schema) { GraphQLType wrappedType = type.getWrappedType(); if (value instanceof ArrayValue) { List<Value> values = ((ArrayValue) value).getValues(); for (int i = 0; i < values.size(); i++) { if (!isValidLiteralValue(values.get(i), wrappedType, schema)) { handleFieldNotValidError(values.get(i), wrappedType, i); return false; } } return true; } else { return isValidLiteralValue(value, wrappedType, schema); } }
private Builder(ArrayValue existing) { this.sourceLocation = existing.getSourceLocation(); this.comments = existing.getComments(); this.values = existing.getValues(); this.ignoredChars = existing.getIgnoredChars(); }
List<Value> values = ((ArrayValue) value).getValues(); JsonArray jsonArray = new JsonArray(values.size()); values.forEach(v -> jsonArray.add(parseJsonValue(v)));
.getValues().stream().map(Scalars::parseObjectValue).collect(Collectors.toList());
List<Value> values = ((ArrayValue) value).getValues(); return values.stream() .map(v -> parseFieldValue(v, variables))
return ((ArrayValue) value).getValues().stream() .map(v -> parseObjectValue(v, variables)) .collect(Collectors.toList());
} else { return ((ArrayValue) value).getValues().stream() .map((it) -> convertValue(environment, argument, it)) .collect(Collectors.toList());
private String value(Value value) { String argSep = compactMode ? "," : ", "; if (value instanceof IntValue) { return valueOf(((IntValue) value).getValue()); } else if (value instanceof FloatValue) { return valueOf(((FloatValue) value).getValue()); } else if (value instanceof StringValue) { return wrap("\"", valueOf(((StringValue) value).getValue()), "\""); } else if (value instanceof EnumValue) { return valueOf(((EnumValue) value).getName()); } else if (value instanceof BooleanValue) { return valueOf(((BooleanValue) value).isValue()); } else if (value instanceof NullValue) { return "null"; } else if (value instanceof ArrayValue) { return "[" + join(((ArrayValue) value).getValues(), argSep) + "]"; } else if (value instanceof ObjectValue) { return "{" + join(((ObjectValue) value).getObjectFields(), argSep) + "}"; } else if (value instanceof VariableReference) { return "$" + ((VariableReference) value).getName(); } return ""; }
public Object buildValue(Value value, GraphQLType requiredType) { Object result = null; if (GraphQLTypeUtil.isNonNull(requiredType)) { requiredType = unwrapOne(requiredType); } if (value == null) { return null; } 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 && isList(requiredType)) { ArrayValue arrayValue = (ArrayValue) value; GraphQLType wrappedType = unwrapOne(requiredType); 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 instanceof NullValue)) { assertShouldNeverHappen( "cannot build value of %s from %s", requiredType.getName(), String.valueOf(value)); } return result; }
List<Value> values = ((ArrayValue) value).getValues(); ArrayNode jsonArray = JsonNodeFactory.instance.arrayNode(values.size()); values.forEach(v -> jsonArray.add(parseJsonValue(v, variables)));