1+ use std:: collections:: { HashMap , HashSet } ;
12use std:: ops:: { Deref , DerefMut } ;
23
34use arbitrary:: Result ;
@@ -142,21 +143,18 @@ impl Unstructured<'_> {
142143 & mut self ,
143144 schema : & Schema ,
144145 ) -> 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) ;
149148 let new_fields = self . arbitrary_vec ( 1 , 5 , |u| {
150149 Ok ( Node :: new ( u. arbitrary_field_definition (
151150 schema,
152- DirectiveLocation :: InputFieldDefinition ,
151+ DirectiveLocation :: FieldDefinition ,
153152 ) ?) )
154153 } ) ?;
155154 Ok ( ObjectTypeDefinition {
156155 description : self . arbitrary_optional ( |u| u. arbitrary_node_str ( ) ) ?,
157156 name : self . unique_name ( ) ,
158- implements_interfaces : schema
159- . sample_interface_types ( self ) ?
157+ implements_interfaces : implements
160158 . iter ( )
161159 . map ( |i| i. name . clone ( ) )
162160 . collect ( ) ,
@@ -229,7 +227,7 @@ impl Unstructured<'_> {
229227 directives : schema
230228 . sample_directives ( self ) ?
231229 . into_iter ( )
232- . with_location ( DirectiveLocation :: InputFieldDefinition )
230+ . with_location ( DirectiveLocation :: ArgumentDefinition )
233231 . try_collect ( self , schema) ?,
234232 } )
235233 }
@@ -285,15 +283,15 @@ impl Unstructured<'_> {
285283 schema : & Schema ,
286284 ) -> Result < InterfaceTypeDefinition > {
287285 // 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 ) ;
292290
293291 let new_fields = self . arbitrary_vec ( 1 , 5 , |u| {
294292 Ok ( Node :: new ( u. arbitrary_field_definition (
295293 schema,
296- DirectiveLocation :: InputFieldDefinition ,
294+ DirectiveLocation :: FieldDefinition ,
297295 ) ?) )
298296 } ) ?;
299297
@@ -316,15 +314,15 @@ impl Unstructured<'_> {
316314 } )
317315 }
318316
319- fn all_fields_from_interfaces (
317+ fn all_unique_fields_from_interfaces (
320318 interfaces : & Vec < & Node < InterfaceType > > ,
321319 ) -> Vec < Node < FieldDefinition > > {
322320 let all_fields = interfaces
323321 . iter ( )
324322 . 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 ( )
328326 }
329327
330328 pub ( crate ) fn arbitrary_field_definition (
@@ -605,6 +603,10 @@ impl Unstructured<'_> {
605603 }
606604 Ok ( args)
607605 }
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+ }
608610}
609611
610612#[ derive( Copy , Clone , Eq , PartialEq ) ]
0 commit comments