1
+ use std:: collections:: { HashMap , HashSet } ;
1
2
use std:: ops:: { Deref , DerefMut } ;
2
3
3
4
use arbitrary:: Result ;
@@ -142,21 +143,18 @@ impl Unstructured<'_> {
142
143
& mut self ,
143
144
schema : & Schema ,
144
145
) -> Result < ObjectTypeDefinition > {
145
- let implements = schema. sample_interface_types ( self ) ?;
146
- let implements_fields = Self :: all_fields_from_interfaces ( & implements) ;
147
- println ! ( "implements: {:?}" , implements) ;
148
- println ! ( "implements_fields: {:?}" , implements_fields) ;
146
+ let implements = Self :: all_transitive_interfaces ( schema. sample_interface_types ( self ) ?) ;
147
+ let implements_fields = Self :: all_unique_fields_from_interfaces ( & implements) ;
149
148
let new_fields = self . arbitrary_vec ( 1 , 5 , |u| {
150
149
Ok ( Node :: new ( u. arbitrary_field_definition (
151
150
schema,
152
- DirectiveLocation :: InputFieldDefinition ,
151
+ DirectiveLocation :: FieldDefinition ,
153
152
) ?) )
154
153
} ) ?;
155
154
Ok ( ObjectTypeDefinition {
156
155
description : self . arbitrary_optional ( |u| u. arbitrary_node_str ( ) ) ?,
157
156
name : self . unique_name ( ) ,
158
- implements_interfaces : schema
159
- . sample_interface_types ( self ) ?
157
+ implements_interfaces : implements
160
158
. iter ( )
161
159
. map ( |i| i. name . clone ( ) )
162
160
. collect ( ) ,
@@ -229,7 +227,7 @@ impl Unstructured<'_> {
229
227
directives : schema
230
228
. sample_directives ( self ) ?
231
229
. into_iter ( )
232
- . with_location ( DirectiveLocation :: InputFieldDefinition )
230
+ . with_location ( DirectiveLocation :: ArgumentDefinition )
233
231
. try_collect ( self , schema) ?,
234
232
} )
235
233
}
@@ -285,15 +283,15 @@ impl Unstructured<'_> {
285
283
schema : & Schema ,
286
284
) -> Result < InterfaceTypeDefinition > {
287
285
// All interfaces need to have all the fields from the interfaces they implement.
288
- let implements = schema. sample_interface_types ( self ) ?;
289
- let implements_fields = Self :: all_fields_from_interfaces ( & implements ) ;
290
- println ! ( "implements: {:?}" , implements ) ;
291
- println ! ( "implements_fields: {:?}" , implements_fields) ;
286
+ let implements = Self :: all_transitive_interfaces ( schema. sample_interface_types ( self ) ?) ;
287
+
288
+ // Interfaces cannot have duplicate fields so stash them in a map
289
+ let mut implements_fields = Self :: all_unique_fields_from_interfaces ( & implements ) ;
292
290
293
291
let new_fields = self . arbitrary_vec ( 1 , 5 , |u| {
294
292
Ok ( Node :: new ( u. arbitrary_field_definition (
295
293
schema,
296
- DirectiveLocation :: InputFieldDefinition ,
294
+ DirectiveLocation :: FieldDefinition ,
297
295
) ?) )
298
296
} ) ?;
299
297
@@ -316,15 +314,15 @@ impl Unstructured<'_> {
316
314
} )
317
315
}
318
316
319
- fn all_fields_from_interfaces (
317
+ fn all_unique_fields_from_interfaces (
320
318
interfaces : & Vec < & Node < InterfaceType > > ,
321
319
) -> Vec < Node < FieldDefinition > > {
322
320
let all_fields = interfaces
323
321
. iter ( )
324
322
. flat_map ( |interface| interface. fields . values ( ) )
325
- . map ( |field| field. deref ( ) . clone ( ) )
326
- . collect :: < Vec < _ > > ( ) ;
327
- all_fields
323
+ . map ( |field| ( field. name . clone ( ) , field . deref ( ) . clone ( ) ) )
324
+ . collect :: < HashMap < _ , _ > > ( ) ;
325
+ all_fields. values ( ) . cloned ( ) . collect ( )
328
326
}
329
327
330
328
pub ( crate ) fn arbitrary_field_definition (
@@ -605,6 +603,10 @@ impl Unstructured<'_> {
605
603
}
606
604
Ok ( args)
607
605
}
606
+ fn all_transitive_interfaces < ' a > ( interfaces : Vec < & ' a Node < InterfaceType > > , schema : & ' a Schema ) -> Vec < & ' a Node < InterfaceType > > {
607
+ // In graphql interfaces can extend other interfaces, but when using them you need to specify every single one in the entire type hierarchy.
608
+
609
+ }
608
610
}
609
611
610
612
#[ derive( Copy , Clone , Eq , PartialEq ) ]
0 commit comments