private boolean alwaysHasValue(GraphQLInputObjectField inputField) { return inputField.getDefaultValue() != null || isNonNull(inputField.getType()); }
private Object coerceValueForInputObjectType(GraphqlFieldVisibility fieldVisibility, VariableDefinition variableDefinition, GraphQLInputObjectType inputObjectType, Map<String, Object> input) { Map<String, Object> result = new LinkedHashMap<>(); List<GraphQLInputObjectField> fields = fieldVisibility.getFieldDefinitions(inputObjectType); List<String> fieldNames = fields.stream().map(GraphQLInputObjectField::getName).collect(Collectors.toList()); for (String inputFieldName : input.keySet()) { if (!fieldNames.contains(inputFieldName)) { throw new InputMapDefinesTooManyFieldsException(inputObjectType, inputFieldName); } } for (GraphQLInputObjectField inputField : fields) { if (input.containsKey(inputField.getName()) || alwaysHasValue(inputField)) { Object value = coerceValue(fieldVisibility, variableDefinition, inputField.getName(), inputField.getType(), input.get(inputField.getName())); result.put(inputField.getName(), value == null ? inputField.getDefaultValue() : value); } } return result; }
public Builder(GraphQLInputObjectField existing) { this.name = existing.getName(); this.description = existing.getDescription(); this.defaultValue = existing.getDefaultValue(); this.type = existing.getType(); this.definition = existing.getDefinition(); this.directives.putAll(getByName(existing.getDirectives(), GraphQLDirective::getName)); }
fieldObject = inputTypeField.getDefaultValue(); assertNonNullInputField(inputTypeField); } else if (inputTypeField.getDefaultValue() != null) { result.put(inputTypeField.getName(), inputTypeField.getDefaultValue()); } else { assertNonNullInputField(inputTypeField);
private TypePrinter<GraphQLInputObjectType> inputObjectPrinter() { return (out, type, visibility) -> { if (isIntrospectionType(type)) { return; } printComments(out, type, ""); out.format("input %s%s {\n", type.getName(), directivesString(type.getDirectives())); visibility.getFieldDefinitions(type) .stream() .sorted(Comparator.comparing(GraphQLInputObjectField::getName)) .forEach(fd -> { printComments(out, fd, " "); out.format(" %s: %s", fd.getName(), typeString(fd.getType())); Object defaultValue = fd.getDefaultValue(); if (defaultValue != null) { String astValue = printAst(defaultValue, fd.getType()); out.format(" = %s", astValue); } out.format(directivesString(fd.getDirectives())); out.format("\n"); }); out.format("}\n\n"); }; }
private boolean alwaysHasValue(GraphQLInputObjectField inputField) { return inputField.getDefaultValue() != null || isNonNull(inputField.getType()); }
private Object coerceValueForInputObjectType(GraphqlFieldVisibility fieldVisibility, VariableDefinition variableDefinition, GraphQLInputObjectType inputObjectType, Map<String, Object> input) { Map<String, Object> result = new LinkedHashMap<>(); List<GraphQLInputObjectField> fields = fieldVisibility.getFieldDefinitions(inputObjectType); List<String> fieldNames = fields.stream().map(GraphQLInputObjectField::getName).collect(Collectors.toList()); for (String inputFieldName : input.keySet()) { if (!fieldNames.contains(inputFieldName)) { throw new InputMapDefinesTooManyFieldsException(inputObjectType, inputFieldName); } } for (GraphQLInputObjectField inputField : fields) { if (input.containsKey(inputField.getName()) || alwaysHasValue(inputField)) { Object value = coerceValue(fieldVisibility, variableDefinition, inputField.getName(), inputField.getType(), input.get(inputField.getName())); result.put(inputField.getName(), value == null ? inputField.getDefaultValue() : value); } } return result; }
public Builder(GraphQLInputObjectField existing) { this.name = existing.getName(); this.description = existing.getDescription(); this.defaultValue = existing.getDefaultValue(); this.type = existing.getType(); this.definition = existing.getDefinition(); this.directives.putAll(getByName(existing.getDirectives(), GraphQLDirective::getName)); }
fieldObject = inputTypeField.getDefaultValue(); assertNonNullInputField(inputTypeField); } else if (inputTypeField.getDefaultValue() != null) { result.put(inputTypeField.getName(), inputTypeField.getDefaultValue()); } else { assertNonNullInputField(inputTypeField);
@Override public GraphQLInputObjectField transformInputField(GraphQLInputObjectField field, InputField inputField, OperationMapper operationMapper, BuildContext buildContext) { if (field.getDefaultValue() == null && shouldWrap(field.getType(), inputField.getTypedElement())) { return field.transform(builder -> builder.type(new GraphQLNonNull(field.getType()))); } if (shouldUnwrap(field.getDefaultValue(), field.getType())) { //do not warn on primitives as their non-nullness is implicit if (!ClassUtils.getRawType(inputField.getJavaType().getType()).isPrimitive()) { log.warn("Non-null input field with a default value will be treated as nullable: " + inputField); } return field.transform(builder -> builder.type((GraphQLInputType) GraphQLUtils.unwrapNonNull(field.getType()))); } return field; }
private TypePrinter<GraphQLInputObjectType> inputObjectPrinter() { return (out, type, visibility) -> { if (isIntrospectionType(type)) { return; } printComments(out, type, ""); SchemaPrinterComparatorEnvironment environment = SchemaPrinterComparatorEnvironment.newEnvironment() .parentType(GraphQLInputObjectType.class) .elementType(GraphQLInputObjectField.class) .build(); Comparator<? super GraphQLType> comparator = options.comparatorRegistry.getComparator(environment); out.format("input %s%s {\n", type.getName(), directivesString(GraphQLInputObjectType.class, type.getDirectives())); visibility.getFieldDefinitions(type) .stream() .sorted(comparator) .forEach(fd -> { printComments(out, fd, " "); out.format(" %s: %s", fd.getName(), typeString(fd.getType())); Object defaultValue = fd.getDefaultValue(); if (defaultValue != null) { String astValue = printAst(defaultValue, fd.getType()); out.format(" = %s", astValue); } out.format(directivesString(GraphQLInputObjectField.class, fd.getDirectives())); out.format("\n"); }); out.format("}\n\n"); }; }