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 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; }
for (Parameter parameter : parameters) { String name = toGraphqlName(parameter.getAnnotation(GraphQLName.class) != null ? parameter.getAnnotation(GraphQLName.class).value() : parameter.getName()); objects.add(buildArg(parameter.getParameterizedType(), ((GraphQLInputObjectType) graphQLType).getField(name).getType(), map.get(name)));
@Test public void argMutation() { GraphQLObjectType object = GraphQLAnnotations.object(TestObject.class); GraphQLFieldDefinition doSomethingElse = object.getFieldDefinition("doSomethingElse"); assertNotNull(doSomethingElse); assertEquals(doSomethingElse.getArguments().size(), 1); GraphQLInputType input = doSomethingElse.getArgument("input").getType(); assertTrue(input instanceof GraphQLNonNull); GraphQLType inputType = ((graphql.schema.GraphQLNonNull) input).getWrappedType(); assertTrue(inputType instanceof GraphQLInputObjectType); GraphQLInputObjectType inputType_ = (GraphQLInputObjectType) inputType; assertNotNull(inputType_.getField("a")); assertNotNull(inputType_.getField("b")); assertEquals(inputType_.getField("a").getDescription(), "A"); assertTrue(doSomethingElse.getType() instanceof GraphQLObjectType); GraphQLObjectType returnType = (GraphQLObjectType) doSomethingElse.getType(); assertNotNull(returnType.getFieldDefinition("getI")); assertNotNull(returnType.getFieldDefinition("clientMutationId")); GraphQLSchema schema = GraphQLSchema.newSchema().query(object).mutation(object).build(); GraphQL graphQL = GraphQL.newGraphQL(schema).queryExecutionStrategy(new EnhancedExecutionStrategy()).build(); ExecutionResult result = graphQL.execute("mutation { doSomethingElse(input: {a: 0, b: 1, clientMutationId: \"1\"}) { getI clientMutationId } }", new TestObject()); assertEquals(result.getErrors().size(), 0); Map<String, Object> returns = (Map<String, Object>) ((Map<String, Object>) result.getData()).get("doSomethingElse"); assertEquals(returns.get("getI"), -1); assertEquals(returns.get("clientMutationId"), "1"); }
@Test public void testInputAndOutputWithSameName() { // arrange + act GraphQLSchema schema = newSchema().query(GraphQLAnnotations.object(QueryInputAndOutput.class)).build(); // assert assertEquals(schema.getQueryType().getFieldDefinition("getHero").getType().getName(), "hero"); assertEquals(schema.getQueryType().getFieldDefinition("getString").getArgument("input").getType().getName(), "Inputhero"); assertEquals(((GraphQLInputObjectType) schema.getQueryType().getFieldDefinition("getString") .getArgument("input").getType()).getField("skill").getType().getName(), "InputSkill"); }