/** * This helps you transform the current GraphQLInputObjectType into another one by starting a builder with all * the current values and allows you to transform it how you want. * * @param builderConsumer the consumer code that will be given a builder to transform * * @return a new object based on calling build on that builder */ public GraphQLInputObjectType transform(Consumer<Builder> builderConsumer) { Builder builder = newInputObject(this); builderConsumer.accept(builder); return builder.build(); }
public Object buildObjectValue(ObjectValue defaultValue, GraphQLInputObjectType objectType) { Map<String, Object> map = new LinkedHashMap<>(); defaultValue.getObjectFields().forEach(of -> map.put(of.getName(), buildValue(of.getValue(), objectType.getField(of.getName()).getType()))); return map; }
public Builder(GraphQLInputObjectType existing) { this.name = existing.getName(); this.description = existing.getDescription(); this.definition = existing.getDefinition(); this.fields.putAll(getByName(existing.getFields(), GraphQLInputObjectField::getName)); this.directives.putAll(getByName(existing.getDirectives(), GraphQLDirective::getName)); }
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"); }; }
@Test(expectedExceptions = InvalidDirectiveLocationException.class) public void wireGraphQLInputObjectType_invalidLocations_exceptionIsThrown() throws Exception { // Arrange AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); GraphQLInputObjectType directiveContainer = GraphQLInputObjectType.newInputObject().name("asdf") .build(); AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, directiveContainer.getDirective("upperCase")); when(upperWiring.onInputObjectType(upperCaseEnv)).thenReturn(directiveContainer); HashMap<GraphQLDirective, AnnotationsDirectiveWiring> map = new HashMap<>(); GraphQLDirective upperCase = newDirective().name("upperCase").build(); map.put(upperCase, upperWiring); // Act directiveWirer.wire(directiveContainer, map); }
@Test public void inputObject() { GraphQLObjectInfoRetriever graphQLObjectInfoRetriever = new GraphQLObjectInfoRetriever(); GraphQLInputObjectType type = new InputObjectBuilder(graphQLObjectInfoRetriever, new ParentalSearch(graphQLObjectInfoRetriever), new BreadthFirstSearch(graphQLObjectInfoRetriever), new GraphQLFieldRetriever()). getInputObjectBuilder(InputObject.class, GraphQLAnnotations.getInstance().getContainer()).build(); assertEquals(type.getName(), DEFAULT_INPUT_PREFIX + InputObject.class.getSimpleName(), "Type name prefix did not match expected value"); assertEquals(type.getFields().size(), InputObject.class.getDeclaredFields().length); }
new MutableGraphQLInputObjectType( objectName, ((GraphQLInputObjectType) attributeType).getDescription(), ((GraphQLInputObjectType) attributeType).getFields() ); convertedInputs.put(objectName, wrappedType);
@Override protected void handleExtraFieldError(Value value, GraphQLInputObjectType type, ObjectField objectField) { errorMessage = "contains a field not in '%s': '%s'"; arguments.add(type.getName()); arguments.add(objectField.getName()); }
private static Value handleInputObject(Object _value, GraphQLInputObjectType type) { Map mapValue = objToMap(_value); List<GraphQLInputObjectField> fields = type.getFields(); List<ObjectField> fieldNodes = new ArrayList<>(); fields.forEach(field -> { GraphQLInputType fieldType = field.getType(); Value nodeValue = astFromValue(mapValue.get(field.getName()), fieldType); if (nodeValue != null) { fieldNodes.add(ObjectField.newObjectField().name(field.getName()).value(nodeValue).build()); } }); return ObjectValue.newObjectValue().objectFields(fieldNodes).build(); }
public GraphQLInputObjectType build() { return new GraphQLInputObjectType(name, description, valuesToList(fields), valuesToList(directives), definition); } }
@Test public void wireGraphQLInputObjectType_validLocations_correctMethodIsCalled() throws Exception { // Arrange AnnotationsDirectiveWiring upperWiring = mock(AnnotationsDirectiveWiring.class); GraphQLInputObjectType directiveContainer = GraphQLInputObjectType.newInputObject().name("asdf") .build(); AnnotationsWiringEnvironmentImpl upperCaseEnv = new AnnotationsWiringEnvironmentImpl(directiveContainer, directiveContainer.getDirective("upperCase")); when(upperWiring.onInputObjectType(upperCaseEnv)).thenReturn(directiveContainer); HashMap<GraphQLDirective, AnnotationsDirectiveWiring> map = new HashMap<>(); GraphQLDirective upperCase = newDirective().name("upperCase").validLocations(Introspection.DirectiveLocation.INPUT_OBJECT).build(); map.put(upperCase, upperWiring); // Act directiveWirer.wire(directiveContainer, map); // Assert verify(upperWiring).onInputObjectType(upperCaseEnv); }
@Test public void inputObjectCustomPrefixes() { GraphQLObjectInfoRetriever graphQLObjectInfoRetriever = new GraphQLObjectInfoRetriever(); ProcessingElementsContainer container = GraphQLAnnotations.getInstance().getContainer(); container.setInputPrefix(""); container.setInputSuffix("Input"); GraphQLInputObjectType type = new InputObjectBuilder(graphQLObjectInfoRetriever, new ParentalSearch(graphQLObjectInfoRetriever), new BreadthFirstSearch(graphQLObjectInfoRetriever), new GraphQLFieldRetriever()). getInputObjectBuilder(InputObject.class, GraphQLAnnotations.getInstance().getContainer()).build(); assertEquals(type.getName(), "" + InputObject.class.getSimpleName() + "Input", "Type name prefix did not match expected value"); assertEquals(type.getFields().size(), InputObject.class.getDeclaredFields().length); container.setInputPrefix(DEFAULT_INPUT_PREFIX); container.setInputSuffix(DEFAULT_INPUT_SUFFIX); }
new MutableGraphQLInputObjectType( objectName, ((GraphQLInputObjectType) attributeType).getDescription(), ((GraphQLInputObjectType) attributeType).getFields() ); convertedInputs.put(objectName, wrappedType);
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"); }; }
@Override public TraversalControl visitGraphQLInputObjectType(GraphQLInputObjectType node, TraverserContext<GraphQLType> context) { if (isTypeReference(node.getName())) { assertTypeUniqueness(node, result); } else { save(node.getName(), node); } return super.visitGraphQLInputObjectType(node, context); }
private static Value handleInputObject(Object _value, GraphQLInputObjectType type) { Map mapValue = objToMap(_value); List<GraphQLInputObjectField> fields = type.getFields(); List<ObjectField> fieldNodes = new ArrayList<>(); fields.forEach(field -> { GraphQLInputType fieldType = field.getType(); Value nodeValue = astFromValue(mapValue.get(field.getName()), fieldType); if (nodeValue != null) { fieldNodes.add(ObjectField.newObjectField().name(field.getName()).value(nodeValue).build()); } }); return ObjectValue.newObjectValue().objectFields(fieldNodes).build(); }
public GraphQLInputObjectType build() { return new GraphQLInputObjectType(name, description, valuesToList(fields), valuesToList(directives), definition); } }
void inputTypes() { GraphQLInputObjectType inputObjectType = newInputObject() .name("inputObjectType") .field(newInputObjectField() .name("field") .type(GraphQLString)) .build(); }
public Builder(GraphQLInputObjectType existing) { this.name = existing.getName(); this.description = existing.getDescription(); this.definition = existing.getDefinition(); this.fields.putAll(getByName(existing.getFields(), GraphQLInputObjectField::getName)); this.directives.putAll(getByName(existing.getDirectives(), GraphQLDirective::getName)); }
public Object buildObjectValue(ObjectValue defaultValue, GraphQLInputObjectType objectType) { Map<String, Object> map = new LinkedHashMap<>(); defaultValue.getObjectFields().forEach(of -> map.put(of.getName(), buildValue(of.getValue(), objectType.getField(of.getName()).getType()))); return map; }