Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Example for UnionType

See original GitHub issue

We 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:closed
  • Created 8 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

alex-wilmercommented, Aug 1, 2016

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?

syrusakbarycommented, Feb 3, 2016

Just published a new version to PyPI with this fix and other features pip install graphene==0.7.1

Release notes:

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found