|
20 | 20 | import graphql.schema.*; |
21 | 21 | import org.testng.annotations.Test; |
22 | 22 |
|
23 | | -import java.util.Collections; |
24 | | -import java.util.HashMap; |
25 | | -import java.util.List; |
26 | | -import java.util.Map; |
| 23 | +import java.util.*; |
27 | 24 |
|
28 | 25 | import static graphql.schema.GraphQLSchema.newSchema; |
29 | 26 | import static org.testng.Assert.assertEquals; |
@@ -89,6 +86,30 @@ public String value(RecursiveInputObject input) { |
89 | 86 | } |
90 | 87 | } |
91 | 88 |
|
| 89 | + static class Code { |
| 90 | + public Code(HashMap map) { |
| 91 | + this.firstField = (String) map.get("firstField"); |
| 92 | + this.secondField = (String) map.get("secondField"); |
| 93 | + } |
| 94 | + |
| 95 | + @GraphQLField |
| 96 | + public String firstField; |
| 97 | + @GraphQLField |
| 98 | + public String secondField; |
| 99 | + } |
| 100 | + |
| 101 | + static class QueryMultipleDefinitions { |
| 102 | + @GraphQLField |
| 103 | + public String something(Code code) { |
| 104 | + return code.firstField + code.secondField; |
| 105 | + } |
| 106 | + |
| 107 | + @GraphQLField |
| 108 | + public String somethingElse(Code code) { |
| 109 | + return code.firstField + code.secondField; |
| 110 | + } |
| 111 | + } |
| 112 | + |
92 | 113 | static class Query { |
93 | 114 | @GraphQLField |
94 | 115 | public TestIface object() { |
@@ -121,6 +142,17 @@ public void query() { |
121 | 142 | assertEquals(((Map<String, Map<String, String>>) result.getData()).get("object").get("value"), "testa"); |
122 | 143 | } |
123 | 144 |
|
| 145 | + @Test |
| 146 | + public void queryMultipleDefinitions() { |
| 147 | + GraphQLSchema schema = newSchema().query(GraphQLAnnotations.object(QueryMultipleDefinitions.class)).build(); |
| 148 | + |
| 149 | + GraphQL graphQL = GraphQL.newGraphQL(schema).build(); |
| 150 | + ExecutionResult result = graphQL.execute("{ something(code: {firstField:\"a\",secondField:\"b\"}) somethingElse(code: {firstField:\"c\",secondField:\"d\"}) }", new QueryMultipleDefinitions()); |
| 151 | + assertTrue(result.getErrors().isEmpty()); |
| 152 | + assertEquals(((Map<String, String>) result.getData()).get("something"), "ab"); |
| 153 | + assertEquals(((Map<String, String>) result.getData()).get("somethingElse"), "cd"); |
| 154 | + } |
| 155 | + |
124 | 156 | @Test |
125 | 157 | public void queryWithRecursion() { |
126 | 158 | GraphQLSchema schema = newSchema().query(GraphQLAnnotations.object(QueryRecursion.class)).build(); |
|
0 commit comments