55 * you may not use this file except in compliance with the License.
66 * You may obtain a copy of the License at
77 *
8- * http://www.apache.org/licenses/LICENSE-2.0
8+ * http://www.apache.org/licenses/LICENSE-2.0
99 *
1010 * Unless required by applicable law or agreed to in writing, software
1111 * distributed under the License is distributed on an "AS IS" BASIS,
1717import graphql .ExceptionWhileDataFetching ;
1818import graphql .ExecutionResult ;
1919import graphql .GraphQL ;
20- import graphql .annotations .annotationTypes .GraphQLDataFetcher ;
21- import graphql .annotations .annotationTypes .GraphQLField ;
22- import graphql .annotations .annotationTypes .GraphQLInvokeDetached ;
20+ import graphql .annotations .annotationTypes .*;
2321import graphql .annotations .annotationTypes .GraphQLType ;
2422import graphql .annotations .dataFetchers .MethodDataFetcher ;
2523import graphql .annotations .processor .GraphQLAnnotations ;
@@ -68,6 +66,12 @@ public int a() {
6866 return 1 ;
6967 }
7068
69+ @ GraphQLField
70+ @ GraphQLPrettify
71+ public int getX () {
72+ return 1 ;
73+ }
74+
7175 @ GraphQLField
7276 @ GraphQLInvokeDetached
7377 public int b () {
@@ -78,11 +82,41 @@ public int b() {
7882 public int c () {
7983 return 4 ;
8084 }
85+
86+ @ GraphQLField
87+ @ GraphQLPrettify
88+ @ GraphQLDataFetcher (CanonizedFetcher .class )
89+ public CanonizedTypeApi getCanonizedType () {
90+ return null ;
91+ }
92+
93+
94+ }
95+
96+ public static class CanonizedFetcher implements DataFetcher <CanonizedType > {
97+
98+ @ Override
99+ public CanonizedType get (DataFetchingEnvironment environment ) {
100+ return new CanonizedType ();
101+ }
102+ }
103+
104+ public static class CanonizedTypeApi {
105+ @ GraphQLPrettify
106+ @ GraphQLField
107+ public int getM () {
108+ return 1 ;
109+ }
110+ }
111+
112+ public static class CanonizedType {
113+ public int m = 5 ;
81114 }
82115
83116 public static class InternalType {
84117 public int a = 123 ;
85118 public int b ;
119+ public int x = 5 ;
86120 }
87121
88122 @ GraphQLType
@@ -119,6 +153,27 @@ public void queryingOneFieldNotAnnotatedWithGraphQLInvokeDetached_valueIsDetermi
119153 assertEquals (((Map <String , Map <String , Integer >>) result .getData ()).get ("field" ).get ("a" ).toString (), "123" );
120154 }
121155
156+
157+ @ Test
158+ public void queryingOneCanonizedFieldNotAnnotatedWithGraphQLInvokeDetached_valueIsDeterminedByEntity () {
159+ GraphQLObjectType object = GraphQLAnnotations .object (Query .class );
160+ GraphQLSchema schema = newSchema ().query (object ).build ();
161+
162+ ExecutionResult result = GraphQL .newGraphQL (schema ).build ().execute ("query { field { canonizedType { m } } }" );
163+ assertTrue (result .getErrors ().isEmpty ());
164+ assertEquals (((Map <String , Map <String , Map <String , Integer >>>) result .getData ()).get ("field" ).get ("canonizedType" ).get ("m" ).toString (), "5" );
165+ }
166+
167+ @ Test
168+ public void queryingOneFieldNotAnnotatedWithGraphQLInvokeDetachedAndNameIsPrettified_valueIsDeterminedByEntity () {
169+ GraphQLObjectType object = GraphQLAnnotations .object (Query .class );
170+ GraphQLSchema schema = newSchema ().query (object ).build ();
171+
172+ ExecutionResult result = GraphQL .newGraphQL (schema ).build ().execute ("query { field { x } }" );
173+ assertTrue (result .getErrors ().isEmpty ());
174+ assertEquals (((Map <String , Map <String , Integer >>) result .getData ()).get ("field" ).get ("x" ).toString (), "5" );
175+ }
176+
122177 @ Test
123178 public void queryingOneFieldAnnotatedWithGraphQLInvokeDetached_valueIsDeterminedByApiEntity () {
124179 GraphQLObjectType object = GraphQLAnnotations .object (Query .class );
@@ -141,12 +196,12 @@ public void queryingFieldsFromApiEntityFetcher_valueIsDeterminedByApiEntity() {
141196 }
142197
143198 @ Test
144- public void queryingFieldsFromNoApiEntityFetcher_noMatchingFieldInEntity_throwException (){
199+ public void queryingFieldsFromNoApiEntityFetcher_noMatchingFieldInEntity_throwException () {
145200 GraphQLObjectType object = GraphQLAnnotations .object (Query .class );
146201 GraphQLSchema schema = newSchema ().query (object ).build ();
147202
148203 ExecutionResult result = GraphQL .newGraphQL (schema ).build ().execute ("query { field { c } }" );
149204 assertFalse (result .getErrors ().isEmpty ());
150- assertTrue (((ExceptionWhileDataFetching )result .getErrors ().get (0 )).getException ().getCause () instanceof NoSuchFieldException );
205+ assertTrue (((ExceptionWhileDataFetching ) result .getErrors ().get (0 )).getException ().getCause () instanceof NoSuchFieldException );
151206 }
152207}
0 commit comments