@@ -369,7 +369,8 @@ def can_build_recursive_union():
369369 msg = str (exc_info .value )
370370 assert msg == "Hello types must be GraphQLObjectType objects."
371371
372- def specifying_union_type_using_typename ():
372+ def describe_specifying_union_type_using_typename ():
373+
373374 schema = build_schema (
374375 """
375376 type Query {
@@ -401,19 +402,33 @@ def specifying_union_type_using_typename():
401402 }
402403 """
403404
404- root = {
405- "fruits" : [
406- {"color" : "green" , "__typename" : "Apple" },
407- {"length" : 5 , "__typename" : "Banana" },
408- ]
409- }
405+ expected = ({"fruits" : [{"color" : "green" }, {"length" : 5 }]}, None )
410406
411- assert graphql_sync (schema , query , root ) == (
412- {"fruits" : [{"color" : "green" }, {"length" : 5 }]},
413- None ,
414- )
407+ def using_dicts ():
408+ root = {
409+ "fruits" : [
410+ {"color" : "green" , "__typename" : "Apple" },
411+ {"length" : 5 , "__typename" : "Banana" },
412+ ]
413+ }
414+
415+ assert graphql_sync (schema , query , root ) == expected
416+
417+ def using_objects ():
418+ class Apple :
419+ __typename = "Apple"
420+ color = "green"
421+
422+ class Banana :
423+ __typename = "Banana"
424+ length = 5
425+
426+ class Root :
427+ fruits = [Apple (), Banana ()]
428+
429+ assert graphql_sync (schema , query , Root ()) == expected
415430
416- def specifying_interface_type_using_typename ():
431+ def describe_specifying_interface_type_using_typename ():
417432 schema = build_schema (
418433 """
419434 type Query {
@@ -450,18 +465,7 @@ def specifying_interface_type_using_typename():
450465 }
451466 """
452467
453- root = {
454- "characters" : [
455- {"name" : "Han Solo" , "totalCredits" : 10 , "__typename" : "Human" },
456- {
457- "name" : "R2-D2" ,
458- "primaryFunction" : "Astromech" ,
459- "__typename" : "Droid" ,
460- },
461- ]
462- }
463-
464- assert graphql_sync (schema , query , root ) == (
468+ expected = (
465469 {
466470 "characters" : [
467471 {"name" : "Han Solo" , "totalCredits" : 10 },
@@ -471,6 +475,36 @@ def specifying_interface_type_using_typename():
471475 None ,
472476 )
473477
478+ def using_dicts ():
479+ root = {
480+ "characters" : [
481+ {"name" : "Han Solo" , "totalCredits" : 10 , "__typename" : "Human" },
482+ {
483+ "name" : "R2-D2" ,
484+ "primaryFunction" : "Astromech" ,
485+ "__typename" : "Droid" ,
486+ },
487+ ]
488+ }
489+
490+ assert graphql_sync (schema , query , root ) == expected
491+
492+ def using_objects ():
493+ class Human :
494+ __typename = "Human"
495+ name = "Han Solo"
496+ totalCredits = 10
497+
498+ class Droid :
499+ __typename = "Droid"
500+ name = "R2-D2"
501+ primaryFunction = "Astromech"
502+
503+ class Root :
504+ characters = [Human (), Droid ()]
505+
506+ assert graphql_sync (schema , query , Root ()) == expected
507+
474508 def custom_scalar ():
475509 sdl = dedent (
476510 """
0 commit comments