question-mark
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.

multiple node type in a list

See original GitHub issue

I have googled around to no avail, is it possible to have a graphene list that has multiple types? I have a model with a property that returns a list of 2 related sets like so:

    @memoized_property
    def assets(self):
        return list(
            chain(self.fileasset_set.all(), self.questionasset_set.all())
        )

how can I describe that properly using graphene? Is it possible to dynamically deduce what kind of Node during runtime? I want to be able to express, for example or something close to:

assets {
  edges {
      node {
             ...FileAsset {
                uploader
             }
            ...QuestionAsset {
                author
            }
      }
   }
}

any way to do this?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
mjtamlyncommented, May 25, 2017

Your field needs to return a union type. These aren’t currently documented as far as I can see, which is a bit odd, I thought they used to be. Anyway, the code looks like this:

class AssetUnion(graphene.types.Union):
    class Meta:
        types = [FileAssetNode, QuestionAssetNode]

class ParentNode(graphene.ObjectType):
    assets = graphene.Field(AssetUnion)
    def resolve_assets(…):
        return chain(self.fileasset_set.all(), self.questionasset_set.all())
0reactions
stale[bot]commented, Jun 11, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Multiple different data types in a Node for a custom linked list ...
Save this question. Show activity on this post. I am trying to build a linked list, and each node will have one integer,...
Read more >
Adding a Node to a List - Cloud - Oracle Help Center
Bottom Nodes: Add only the bottom nodes of the selected or dragged node. Note: If multiple node types are available, you're prompted to...
Read more >
Get all nodes of given type - Drupal Answers - Stack Exchange
I know I can get all the nodes (of any type) with \Drupal\node\Entity\Node::loadMultiple() and the list of all types by \Drupal\node\Entity\NodeType:: ...
Read more >
Amazon Redshift clusters - AWS Documentation
On a multi-node cluster, the leader node is separate from the compute nodes. The leader node is the same node type as the...
Read more >
Node | Elasticsearch Guide [8.5] | Elastic
This means that a node that has an explicit empty list of roles via node.roles will ... You can run multiple Elasticsearch nodes...
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 Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found