1313import graphql .schema .Coercing ;
1414import graphql .schema .DataFetcher ;
1515import graphql .schema .DataFetchingEnvironment ;
16+ import graphql .schema .GraphQLCodeRegistry ;
1617import graphql .schema .GraphQLEnumType ;
1718import graphql .schema .GraphQLInputObjectType ;
1819import graphql .schema .GraphQLInterfaceType ;
4950import static graphql .Scalars .GraphQLBoolean ;
5051import static graphql .Scalars .GraphQLString ;
5152import static graphql .StarWarsSchema .queryType ;
53+ import static graphql .schema .FieldCoordinates .coordinates ;
5254import static graphql .schema .GraphQLArgument .newArgument ;
55+ import static graphql .schema .GraphQLCodeRegistry .newCodeRegistry ;
5356import static graphql .schema .GraphQLEnumType .newEnum ;
5457import static graphql .schema .GraphQLFieldDefinition .newFieldDefinition ;
5558import static graphql .schema .GraphQLInputObjectField .newInputObjectField ;
@@ -143,23 +146,28 @@ void enumTypes() {
143146 }
144147
145148 void unionType () {
149+ TypeResolver typeResolver = new TypeResolver () {
150+ @ Override
151+ public GraphQLObjectType getType (TypeResolutionEnvironment env ) {
152+ if (env .getObject () instanceof Cat ) {
153+ return CatType ;
154+ }
155+ if (env .getObject () instanceof Dog ) {
156+ return DogType ;
157+ }
158+ return null ;
159+ }
160+ };
146161 GraphQLUnionType PetType = newUnionType ()
147162 .name ("Pet" )
148163 .possibleType (CatType )
149164 .possibleType (DogType )
150- .typeResolver (new TypeResolver () {
151- @ Override
152- public GraphQLObjectType getType (TypeResolutionEnvironment env ) {
153- if (env .getObject () instanceof Cat ) {
154- return CatType ;
155- }
156- if (env .getObject () instanceof Dog ) {
157- return DogType ;
158- }
159- return null ;
160- }
161- })
162165 .build ();
166+
167+ GraphQLCodeRegistry codeRegistry = newCodeRegistry ()
168+ .typeResolver ("Pet" , typeResolver )
169+ .build ();
170+
163171 }
164172
165173
@@ -207,7 +215,13 @@ public Foo get(DataFetchingEnvironment environment) {
207215 .field (newFieldDefinition ()
208216 .name ("foo" )
209217 .type (GraphQLString )
210- .dataFetcher (fooDataFetcher ))
218+ )
219+ .build ();
220+
221+ GraphQLCodeRegistry codeRegistry = newCodeRegistry ()
222+ .dataFetcher (
223+ coordinates ("ObjectType" , "foo" ),
224+ fooDataFetcher )
211225 .build ();
212226
213227 }
@@ -242,14 +256,14 @@ private ReviewStore reviewStore() {
242256
243257 void mutationExample () {
244258
245- GraphQLInputObjectType episodeType = GraphQLInputObjectType . newInputObject ()
259+ GraphQLInputObjectType episodeType = newInputObject ()
246260 .name ("Episode" )
247261 .field (newInputObjectField ()
248262 .name ("episodeNumber" )
249263 .type (Scalars .GraphQLInt ))
250264 .build ();
251265
252- GraphQLInputObjectType reviewInputType = GraphQLInputObjectType . newInputObject ()
266+ GraphQLInputObjectType reviewInputType = newInputObject ()
253267 .name ("ReviewInput" )
254268 .field (newInputObjectField ()
255269 .name ("stars" )
@@ -281,13 +295,21 @@ void mutationExample() {
281295 .name ("review" )
282296 .type (reviewInputType )
283297 )
284- .dataFetcher (mutationDataFetcher ())
285298 )
286299 .build ();
287300
301+ GraphQLCodeRegistry codeRegistry = newCodeRegistry ()
302+ .dataFetcher (
303+ coordinates ("CreateReviewForEpisodeMutation" , "createReview" ),
304+ mutationDataFetcher ()
305+ )
306+ .build ();
307+
308+
288309 GraphQLSchema schema = GraphQLSchema .newSchema ()
289310 .query (queryType )
290311 .mutation (createReviewForEpisodeMutation )
312+ .codeRegistry (codeRegistry )
291313 .build ();
292314 }
293315
@@ -467,7 +489,7 @@ private Directive getDirective(FieldDefinition fieldDefintion, String type) {
467489 }
468490
469491
470- public static GraphQLScalarType CustomScalar = new GraphQLScalarType ( "Custom" , "Custom Scalar" , new Coercing <Integer , Integer >() {
492+ public static GraphQLScalarType CustomScalar = GraphQLScalarType . newScalar (). name ( "Custom" ). description ( "Custom Scalar" ). coercing ( new Coercing <Integer , Integer >() {
471493 @ Override
472494 public Integer serialize (Object input ) {
473495 throw new UnsupportedOperationException ("Not implemented" );
@@ -482,7 +504,7 @@ public Integer parseValue(Object input) {
482504 public Integer parseLiteral (Object input ) {
483505 throw new UnsupportedOperationException ("Not implemented" );
484506 }
485- });
507+ }). build () ;
486508
487509 private File loadSchema (String s ) {
488510 return null ;
0 commit comments