Example for UnionType
See original GitHub issueWe have just been trying to use UnionType
but with very little success, all throwing some error message that is hard to identify/debug.
This is a simplified example of what we have been trying, using the latest version 0.7.0
:
from graphene.core.classtypes.uniontype import UnionType
from graphene import ObjectType, String, Field, Schema
class Human(ObjectType):
some_field = String()
other_field = String()
class Pet(ObjectType):
yet_another_field = String()
class Thing(UnionType):
'''Thing union description'''
class Meta:
types = [Human, Pet]
class Query(ObjectType):
thing = Field(Thing)
def resolve_thing(self, args, info):
return Thing(some_field='test') # or Human(some_field='test')
schema = graphene.Schema(query=Query)
There are a few more variations that we have tried as well, but didn’t work. So how does a full example of using UnionType
look like?
CC @imranolas
Issue Analytics
- State:
- Created 8 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Union Type in TypeScript - TutorialsTeacher
TypeScript allows us to use more than one data type for a variable or a function parameter. This is called union type. ......
Read more >Handbook - Unions and Intersection Types - TypeScript
A union type describes a value that can be one of several types. We use the vertical bar ( | ) to separate...
Read more >TypeScript Union Types with Example - HowToDoInJava
A union type is a variable supporting multiple data types. The union type variables are defined using the pipe '|' symbol between the...
Read more >TypeScript Union type a deeper look - Daily Dev Tips
The TypeScript union type is super powerful, let's take another look at what it can do. ... Let's see how that would be...
Read more >union-type-examples-and-other-strategies - YouTube
More examples of where we might want union types, and how we make do in Java. ... union-type - examples -and-other-strategies.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi, I wasn’t able to figure this out from the docs… does it even currently address union types? Do I need to include
from graphene.core.classtypes.uniontype import UnionType
?Just published a new version to PyPI with this fix and other features
pip install graphene==0.7.1
Release notes: https://github.com/graphql-python/graphene/releases/tag/v0.7.1