Skip to content

Commit 23972c6

Browse files
author
Thomas Draier
committed
Fix for more complex input types
1 parent 4b9ad5f commit 23972c6

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

src/main/java/graphql/annotations/MethodDataFetcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ private Object buildArg(Type p, GraphQLType graphQLType, Object arg) {
9595
Map map = (Map) arg;
9696
for (Parameter parameter : parameters) {
9797
String name = toGraphqlName(parameter.getAnnotation(GraphQLName.class) != null ? parameter.getAnnotation(GraphQLName.class).value() : parameter.getName());
98-
objects.add(buildArg(parameter.getType(), ((GraphQLInputObjectType)graphQLType).getField(name).getType(),map.get(name)));
98+
objects.add(buildArg(parameter.getParameterizedType(), ((GraphQLInputObjectType)graphQLType).getField(name).getType(),map.get(name)));
9999
}
100100
return constructNewInstance(constructor, objects.toArray(new Object[objects.size()]));
101101
}

src/test/java/graphql/annotations/GraphQLObjectTest.java

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,19 +546,42 @@ private static class TestInputArgument {
546546
@GraphQLField
547547
public int b;
548548

549-
public TestInputArgument(HashMap<String, Object> args) {
550-
a = (String) args.get("a");
551-
b = (int) args.get("b");
549+
public TestInputArgument(String a, int b) {
550+
this.a = a;
551+
this.b = b;
552552
}
553553
}
554554

555+
private static class TestComplexInputArgument {
556+
557+
public Collection<TestInputArgument> inputs;
558+
559+
public TestComplexInputArgument(Collection<TestInputArgument> inputs) {
560+
this.inputs = inputs;
561+
}
562+
563+
@GraphQLField
564+
public Collection<TestInputArgument> getInputs() {
565+
return inputs;
566+
}
567+
568+
}
569+
570+
571+
555572
private static class TestObjectInput {
556573
@GraphQLField
557574
public String test(int other, TestInputArgument arg) {
558575
return arg.a;
559576
}
577+
578+
@GraphQLField
579+
public String test2(int other, TestComplexInputArgument arg) {
580+
return arg.inputs.iterator().next().a;
581+
}
560582
}
561583

584+
562585
@Test
563586
public void inputObjectArgument() {
564587
GraphQLObjectType object = GraphQLAnnotations.object(TestObjectInput.class);
@@ -573,6 +596,20 @@ public void inputObjectArgument() {
573596
assertEquals(v.get("test"), "ok");
574597
}
575598

599+
@Test
600+
public void complexInputObjectArgument() {
601+
GraphQLObjectType object = GraphQLAnnotations.object(TestObjectInput.class);
602+
GraphQLArgument argument = object.getFieldDefinition("test2").getArgument("arg");
603+
assertTrue(argument.getType() instanceof GraphQLInputObjectType);
604+
assertEquals(argument.getName(), "arg");
605+
606+
GraphQLSchema schema = newSchema().query(object).build();
607+
ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{ test2(arg: {inputs:[{ a:\"ok\", b:2 }]}, other:0) }", new TestObjectInput());
608+
assertTrue(result.getErrors().isEmpty());
609+
Map<String, Object> v = (Map<String, Object>) result.getData();
610+
assertEquals(v.get("test2"), "ok");
611+
}
612+
576613
@Test
577614
public void inputObject() {
578615
GraphQLObjectType object = GraphQLAnnotations.object(TestObjectInput.class);

0 commit comments

Comments
 (0)