@@ -295,3 +295,69 @@ def test_resolve_type_on_union_yields_useful_error():
295295 result = graphql (schema , query )
296296 assert result .errors [0 ].message == 'Runtime Object type "Human" is not a possible type for "Pet".'
297297 assert result .data == {'pets' : [{'woofs' : True , 'name' : 'Odie' }, {'name' : 'Garfield' , 'meows' : False }, None ]}
298+
299+
300+ def test_resolve_type_can_use_type_string ():
301+
302+ def type_string_resolver (obj , * _ ):
303+ if isinstance (obj , Dog ):
304+ return 'Dog'
305+ if isinstance (obj , Cat ):
306+ return 'Cat'
307+
308+ PetType = GraphQLInterfaceType (
309+ name = 'Pet' ,
310+ fields = {
311+ 'name' : GraphQLField (GraphQLString )
312+ },
313+ resolve_type = type_string_resolver
314+ )
315+
316+ DogType = GraphQLObjectType (
317+ name = 'Dog' ,
318+ interfaces = [PetType ],
319+ fields = {
320+ 'name' : GraphQLField (GraphQLString ),
321+ 'woofs' : GraphQLField (GraphQLBoolean )
322+ }
323+ )
324+
325+ CatType = GraphQLObjectType (
326+ name = 'Cat' ,
327+ interfaces = [PetType ],
328+ fields = {
329+ 'name' : GraphQLField (GraphQLString ),
330+ 'meows' : GraphQLField (GraphQLBoolean )
331+ }
332+ )
333+
334+ schema = GraphQLSchema (
335+ query = GraphQLObjectType (
336+ name = 'Query' ,
337+ fields = {
338+ 'pets' : GraphQLField (
339+ GraphQLList (PetType ),
340+ resolver = lambda * _ : [Dog ('Odie' , True ), Cat ('Garfield' , False )]
341+ )
342+ }
343+ ),
344+ types = [CatType , DogType ]
345+ )
346+
347+ query = '''
348+ {
349+ pets {
350+ name
351+ ... on Dog {
352+ woofs
353+ }
354+ ... on Cat {
355+ meows
356+ }
357+ }
358+ }
359+ '''
360+
361+ result = graphql (schema , query )
362+ assert not result .errors
363+ assert result .data == {'pets' : [{'woofs' : True , 'name' : 'Odie' }, {'name' : 'Garfield' , 'meows' : False }]}
0 commit comments