|
18 | 18 | import graphql.GraphQL; |
19 | 19 | import graphql.Scalars; |
20 | 20 | import graphql.annotations.annotationTypes.*; |
21 | | -import graphql.annotations.dataFetchers.ExtensionDataFetcherWrapper; |
| 21 | +import graphql.annotations.annotationTypes.GraphQLNonNull; |
22 | 22 | import graphql.annotations.processor.GraphQLAnnotations; |
23 | 23 | import graphql.annotations.processor.ProcessingElementsContainer; |
24 | 24 | import graphql.annotations.processor.retrievers.GraphQLInputObjectRetriever; |
25 | 25 | import graphql.annotations.processor.retrievers.GraphQLObjectHandler; |
26 | 26 | import graphql.annotations.processor.typeFunctions.TypeFunction; |
27 | | -import graphql.schema.DataFetcher; |
28 | | -import graphql.schema.DataFetchingEnvironment; |
29 | | - |
30 | | -import graphql.schema.GraphQLArgument; |
31 | | -import graphql.schema.GraphQLFieldDefinition; |
32 | | -import graphql.schema.GraphQLInputObjectType; |
33 | | -import graphql.schema.GraphQLInputType; |
34 | | -import graphql.schema.GraphQLList; |
35 | | -import graphql.schema.GraphQLObjectType; |
36 | | -import graphql.schema.GraphQLSchema; |
| 27 | +import graphql.schema.*; |
| 28 | + |
37 | 29 | import graphql.schema.GraphQLType; |
38 | 30 | import graphql.schema.idl.SchemaParser; |
39 | 31 | import graphql.schema.idl.SchemaPrinter; |
@@ -141,6 +133,43 @@ public String fieldWithNamedArgs(@GraphQLName("namedArg") String firstArgument) |
141 | 133 | } |
142 | 134 | } |
143 | 135 |
|
| 136 | + public static class TestMappedObject { |
| 137 | + @GraphQLField |
| 138 | + public String name; |
| 139 | + } |
| 140 | + |
| 141 | + public static class TestObjectDB{ |
| 142 | + public String name; |
| 143 | + |
| 144 | + public TestObjectDB(String name) { |
| 145 | + this.name = name; |
| 146 | + } |
| 147 | + } |
| 148 | + |
| 149 | + public static class TestQuery{ |
| 150 | + @GraphQLField |
| 151 | + @GraphQLDataFetcher(ObjectFetcher.class) |
| 152 | + public TestMappedObject object; |
| 153 | + } |
| 154 | + |
| 155 | + public static class ObjectFetcher implements DataFetcher<TestObjectDB> { |
| 156 | + |
| 157 | + @Override |
| 158 | + public TestObjectDB get(DataFetchingEnvironment environment) { |
| 159 | + return new TestObjectDB("test"); |
| 160 | + } |
| 161 | + } |
| 162 | + |
| 163 | + @Test |
| 164 | + public void fetchTestMappedObject_assertNameIsMappedFromDBObject(){ |
| 165 | + GraphQLObjectType object = GraphQLAnnotations.object(TestQuery.class); |
| 166 | + GraphQLSchema schema = newSchema().query(object).build(); |
| 167 | + |
| 168 | + ExecutionResult result = GraphQL.newGraphQL(schema).build().execute("{object {name}}"); |
| 169 | + assertTrue(result.getErrors().isEmpty()); |
| 170 | + assertEquals(((LinkedHashMap)(((LinkedHashMap)result.getData()).get("object"))).get("name"), "test"); |
| 171 | + } |
| 172 | + |
144 | 173 | @Test |
145 | 174 | public void namedFields() { |
146 | 175 | GraphQLObjectType object = GraphQLAnnotations.object(TestObjectNamedArgs.class); |
@@ -214,8 +243,8 @@ public void fields() { |
214 | 243 | assertEquals(fields.get(5).getName(), "privateTest"); |
215 | 244 | assertEquals(fields.get(6).getName(), "publicTest"); |
216 | 245 |
|
217 | | - assertEquals(fields.get(5).getDataFetcher().getClass(), ExtensionDataFetcherWrapper.class); |
218 | | - assertEquals(fields.get(6).getDataFetcher().getClass(), ExtensionDataFetcherWrapper.class); |
| 246 | + assertEquals(fields.get(5).getDataFetcher().getClass(), PropertyDataFetcher.class); |
| 247 | + assertEquals(fields.get(6).getDataFetcher().getClass(), FieldDataFetcher.class); |
219 | 248 |
|
220 | 249 | assertEquals(fields.get(7).getName(), "z_nonOptionalString"); |
221 | 250 | assertTrue(fields.get(7).getType() instanceof graphql.schema.GraphQLNonNull); |
|
0 commit comments