1414import graphql .language .InputValueDefinition ;
1515import graphql .language .InterfaceTypeDefinition ;
1616import graphql .language .ListType ;
17+ import graphql .language .NodeDirectivesBuilder ;
1718import graphql .language .NonNullType ;
1819import graphql .language .ObjectTypeDefinition ;
1920import graphql .language .OperationTypeDefinition ;
@@ -70,41 +71,41 @@ public Document createSchemaDefinition(Map<String, Object> introspectionResult)
7071
7172 Map <String , Object > queryType = (Map <String , Object >) schema .get ("queryType" );
7273 assertNotNull (queryType , "queryType expected" );
73- TypeName query = new TypeName (( String ) queryType .get ("name" ));
74+ TypeName query = TypeName . newTypeName (). name (( String ) queryType .get ("name" )). build ( );
7475 boolean nonDefaultQueryName = !"Query" .equals (query .getName ());
7576
76- SchemaDefinition schemaDefinition = new SchemaDefinition ();
77- schemaDefinition .getOperationTypeDefinitions (). add ( new OperationTypeDefinition ( "query" , query ));
77+ SchemaDefinition . Builder schemaDefinition = SchemaDefinition . newSchemaDefintion ();
78+ schemaDefinition .operationTypeDefinition ( OperationTypeDefinition . newOperationTypeDefinition (). name ( "query" ). type ( query ). build ( ));
7879
7980 Map <String , Object > mutationType = (Map <String , Object >) schema .get ("mutationType" );
8081 boolean nonDefaultMutationName = false ;
8182 if (mutationType != null ) {
82- TypeName mutation = new TypeName (( String ) mutationType .get ("name" ));
83+ TypeName mutation = TypeName . newTypeName (). name (( String ) mutationType .get ("name" )). build ( );
8384 nonDefaultMutationName = !"Mutation" .equals (mutation .getName ());
84- schemaDefinition .getOperationTypeDefinitions (). add ( new OperationTypeDefinition ( "mutation" , mutation ));
85+ schemaDefinition .operationTypeDefinition ( OperationTypeDefinition . newOperationTypeDefinition (). name ( "mutation" ). type ( mutation ). build ( ));
8586 }
8687
8788 Map <String , Object > subscriptionType = (Map <String , Object >) schema .get ("subscriptionType" );
8889 boolean nonDefaultSubscriptionName = false ;
8990 if (subscriptionType != null ) {
90- TypeName subscription = new TypeName (( String ) subscriptionType .get ("name" ));
91+ TypeName subscription = TypeName . newTypeName (). name ((( String ) subscriptionType .get ("name" ))). build ( );
9192 nonDefaultSubscriptionName = !"Subscription" .equals (subscription .getName ());
92- schemaDefinition .getOperationTypeDefinitions (). add ( new OperationTypeDefinition ( "subscription" , subscription ));
93+ schemaDefinition .operationTypeDefinition ( OperationTypeDefinition . newOperationTypeDefinition (). name ( "subscription" ). type ( subscription ). build ( ));
9394 }
9495
95- Document document = new Document ();
96+ Document . Builder document = Document . newDocument ();
9697 if (nonDefaultQueryName || nonDefaultMutationName || nonDefaultSubscriptionName ) {
97- document .getDefinitions (). add ( schemaDefinition );
98+ document .definition ( schemaDefinition . build () );
9899 }
99100
100101 List <Map <String , Object >> types = (List <Map <String , Object >>) schema .get ("types" );
101102 for (Map <String , Object > type : types ) {
102103 TypeDefinition typeDefinition = createTypeDefinition (type );
103104 if (typeDefinition == null ) continue ;
104- document .getDefinitions (). add (typeDefinition );
105+ document .definition (typeDefinition );
105106 }
106107
107- return document ;
108+ return document . build () ;
108109 }
109110
110111 private TypeDefinition createTypeDefinition (Map <String , Object > type ) {
@@ -134,59 +135,60 @@ private TypeDefinition createScalar(Map<String, Object> input) {
134135 if (ScalarInfo .isStandardScalar (name )) {
135136 return null ;
136137 }
137- return new ScalarTypeDefinition ( name );
138+ return ScalarTypeDefinition . newScalarTypeDefinition (). name ( name ). build ( );
138139 }
139140
140141
141142 @ SuppressWarnings ("unchecked" )
142143 UnionTypeDefinition createUnion (Map <String , Object > input ) {
143144 assertTrue (input .get ("kind" ).equals ("UNION" ), "wrong input" );
144145
145- UnionTypeDefinition unionTypeDefinition = new UnionTypeDefinition ((String ) input .get ("name" ));
146- unionTypeDefinition .setComments (toComment ((String ) input .get ("description" )));
146+ UnionTypeDefinition .Builder unionTypeDefinition = UnionTypeDefinition .newUnionTypeDefinition ();
147+ unionTypeDefinition .name ((String ) input .get ("name" ));
148+ unionTypeDefinition .comments (toComment ((String ) input .get ("description" )));
147149
148150 List <Map <String , Object >> possibleTypes = (List <Map <String , Object >>) input .get ("possibleTypes" );
149151
150152 for (Map <String , Object > possibleType : possibleTypes ) {
151- TypeName typeName = new TypeName (( String ) possibleType .get ("name" ));
152- unionTypeDefinition .getMemberTypes (). add (typeName );
153+ TypeName typeName = TypeName . newTypeName (). name (( String ) possibleType .get ("name" )). build ( );
154+ unionTypeDefinition .memberType (typeName );
153155 }
154156
155- return unionTypeDefinition ;
157+ return unionTypeDefinition . build () ;
156158 }
157159
158160 @ SuppressWarnings ("unchecked" )
159161 EnumTypeDefinition createEnum (Map <String , Object > input ) {
160162 assertTrue (input .get ("kind" ).equals ("ENUM" ), "wrong input" );
161163
162- EnumTypeDefinition enumTypeDefinition = new EnumTypeDefinition ((String ) input .get ("name" ));
163- enumTypeDefinition .setComments (toComment ((String ) input .get ("description" )));
164+ EnumTypeDefinition . Builder enumTypeDefinition = EnumTypeDefinition . newEnumTypeDefinition (). name ((String ) input .get ("name" ));
165+ enumTypeDefinition .comments (toComment ((String ) input .get ("description" )));
164166
165167 List <Map <String , Object >> enumValues = (List <Map <String , Object >>) input .get ("enumValues" );
166168
167169 for (Map <String , Object > enumValue : enumValues ) {
168170
169- EnumValueDefinition enumValueDefinition = new EnumValueDefinition ((String ) enumValue .get ("name" ));
170- enumValueDefinition .setComments (toComment ((String ) enumValue .get ("description" )));
171+ EnumValueDefinition . Builder enumValueDefinition = EnumValueDefinition . newEnumValueDefinition (). name ((String ) enumValue .get ("name" ));
172+ enumValueDefinition .comments (toComment ((String ) enumValue .get ("description" )));
171173
172- createDeprecatedDirective (enumValue , enumValueDefinition . getDirectives () );
174+ createDeprecatedDirective (enumValue , enumValueDefinition );
173175
174- enumTypeDefinition .getEnumValueDefinitions (). add ( enumValueDefinition );
176+ enumTypeDefinition .enumValueDefinition ( enumValueDefinition . build () );
175177 }
176178
177- return enumTypeDefinition ;
179+ return enumTypeDefinition . build () ;
178180 }
179181
180182 @ SuppressWarnings ("unchecked" )
181183 InterfaceTypeDefinition createInterface (Map <String , Object > input ) {
182184 assertTrue (input .get ("kind" ).equals ("INTERFACE" ), "wrong input" );
183185
184- InterfaceTypeDefinition interfaceTypeDefinition = new InterfaceTypeDefinition ((String ) input .get ("name" ));
185- interfaceTypeDefinition .setComments (toComment ((String ) input .get ("description" )));
186+ InterfaceTypeDefinition . Builder interfaceTypeDefinition = InterfaceTypeDefinition . newInterfaceTypeDefinition (). name ((String ) input .get ("name" ));
187+ interfaceTypeDefinition .comments (toComment ((String ) input .get ("description" )));
186188 List <Map <String , Object >> fields = (List <Map <String , Object >>) input .get ("fields" );
187- interfaceTypeDefinition .getFieldDefinitions (). addAll (createFields (fields ));
189+ interfaceTypeDefinition .definitions (createFields (fields ));
188190
189- return interfaceTypeDefinition ;
191+ return interfaceTypeDefinition . build () ;
190192
191193 }
192194
@@ -209,65 +211,67 @@ InputObjectTypeDefinition createInputObject(Map<String, Object> input) {
209211 ObjectTypeDefinition createObject (Map <String , Object > input ) {
210212 assertTrue (input .get ("kind" ).equals ("OBJECT" ), "wrong input" );
211213
212- ObjectTypeDefinition objectTypeDefinition = new ObjectTypeDefinition ((String ) input .get ("name" ));
213- objectTypeDefinition .setComments (toComment ((String ) input .get ("description" )));
214+ ObjectTypeDefinition . Builder objectTypeDefinition = ObjectTypeDefinition . newObjectTypeDefinition (). name ((String ) input .get ("name" ));
215+ objectTypeDefinition .comments (toComment ((String ) input .get ("description" )));
214216 if (input .containsKey ("interfaces" )) {
215- objectTypeDefinition .getImplements (). addAll (
216- ((List <Map <String , Object >>)input .get ("interfaces" )).stream ()
217+ objectTypeDefinition .implementz (
218+ ((List <Map <String , Object >>) input .get ("interfaces" )).stream ()
217219 .map (this ::createTypeIndirection )
218220 .collect (Collectors .toList ())
219221 );
220222 }
221223 List <Map <String , Object >> fields = (List <Map <String , Object >>) input .get ("fields" );
222224
223- objectTypeDefinition .getFieldDefinitions (). addAll (createFields (fields ));
225+ objectTypeDefinition .fieldDefinitions (createFields (fields ));
224226
225- return objectTypeDefinition ;
227+ return objectTypeDefinition . build () ;
226228 }
227229
228230 private List <FieldDefinition > createFields (List <Map <String , Object >> fields ) {
229231 List <FieldDefinition > result = new ArrayList <>();
230232 for (Map <String , Object > field : fields ) {
231- FieldDefinition fieldDefinition = new FieldDefinition ((String ) field .get ("name" ));
232- fieldDefinition .setComments (toComment ((String ) field .get ("description" )));
233- fieldDefinition .setType (createTypeIndirection ((Map <String , Object >) field .get ("type" )));
233+ FieldDefinition . Builder fieldDefinition = FieldDefinition . newFieldDefintion (). name ((String ) field .get ("name" ));
234+ fieldDefinition .comments (toComment ((String ) field .get ("description" )));
235+ fieldDefinition .type (createTypeIndirection ((Map <String , Object >) field .get ("type" )));
234236
235- createDeprecatedDirective (field , fieldDefinition . getDirectives () );
237+ createDeprecatedDirective (field , fieldDefinition );
236238
237239 List <Map <String , Object >> args = (List <Map <String , Object >>) field .get ("args" );
238240 List <InputValueDefinition > inputValueDefinitions = createInputValueDefinitions (args );
239- fieldDefinition .getInputValueDefinitions (). addAll (inputValueDefinitions );
240- result .add (fieldDefinition );
241+ fieldDefinition .inputValueDefinitions (inputValueDefinitions );
242+ result .add (fieldDefinition . build () );
241243 }
242244 return result ;
243245 }
244246
245- private void createDeprecatedDirective (Map <String , Object > field , List <Directive > directives ) {
247+ private void createDeprecatedDirective (Map <String , Object > field , NodeDirectivesBuilder nodeDirectivesBuilder ) {
248+ List <Directive > directives = new ArrayList <>();
246249 if ((Boolean ) field .get ("isDeprecated" )) {
247250 String reason = (String ) field .get ("deprecationReason" );
248251 if (reason == null ) {
249252 reason = "No longer supported" ; // default according to spec
250253 }
251- Argument reasonArg = new Argument ( "reason" , new StringValue ( reason ));
252- Directive deprecated = new Directive ( "deprecated" , Collections .singletonList (reasonArg ));
254+ Argument reasonArg = Argument . newArgument (). name ( "reason" ). value ( StringValue . newStringValue (). value ( reason ). build ()). build ( );
255+ Directive deprecated = Directive . newDirective (). name ( "deprecated" ). arguments ( Collections .singletonList (reasonArg )). build ( );
253256 directives .add (deprecated );
254257 }
258+ nodeDirectivesBuilder .directives (directives );
255259 }
256260
257261 @ SuppressWarnings ("unchecked" )
258262 private List <InputValueDefinition > createInputValueDefinitions (List <Map <String , Object >> args ) {
259263 List <InputValueDefinition > result = new ArrayList <>();
260264 for (Map <String , Object > arg : args ) {
261265 Type argType = createTypeIndirection ((Map <String , Object >) arg .get ("type" ));
262- InputValueDefinition inputValueDefinition = new InputValueDefinition (( String ) arg .get ("name" ), argType );
263- inputValueDefinition .setComments (toComment ((String ) arg .get ("description" )));
266+ InputValueDefinition . Builder inputValueDefinition = InputValueDefinition . newInputValueDefinition (). name (( String ) arg .get ("name" )). type ( argType );
267+ inputValueDefinition .comments (toComment ((String ) arg .get ("description" )));
264268
265269 String valueLiteral = (String ) arg .get ("defaultValue" );
266270 if (valueLiteral != null ) {
267271 Value defaultValue = AstValueHelper .valueFromAst (valueLiteral );
268- inputValueDefinition .setDefaultValue (defaultValue );
272+ inputValueDefinition .defaultValue (defaultValue );
269273 }
270- result .add (inputValueDefinition );
274+ result .add (inputValueDefinition . build () );
271275 }
272276 return result ;
273277 }
@@ -282,11 +286,11 @@ private Type createTypeIndirection(Map<String, Object> type) {
282286 case "ENUM" :
283287 case "INPUT_OBJECT" :
284288 case "SCALAR" :
285- return new TypeName (( String ) type .get ("name" ));
289+ return TypeName . newTypeName (). name (( String ) type .get ("name" )). build ( );
286290 case "NON_NULL" :
287- return new NonNullType ( createTypeIndirection ((Map <String , Object >) type .get ("ofType" )));
291+ return NonNullType . newNonNullType (). type ( createTypeIndirection ((Map <String , Object >) type .get ("ofType" ))). build ( );
288292 case "LIST" :
289- return new ListType ( createTypeIndirection ((Map <String , Object >) type .get ("ofType" )));
293+ return ListType . newListType (). type ( createTypeIndirection ((Map <String , Object >) type .get ("ofType" ))). build ( );
290294 default :
291295 return assertShouldNeverHappen ("Unknown kind %s" , kind );
292296 }
0 commit comments