graphql-python / graphql-python/graphene-mongo
What is intended way to implement Union?
- Dominant language
- Python
- Stars
- 287
- Forks
- 111
- PR merge metrics
- No merged PRs in 30d
Description
Here is the schema that i am trying to implement:
```gql
type Text {
id: ID
content: String
}
type Image {
id: ID
image_url: String
thumb_url: String
}
union Post = Text | Image
type User {
id: ID
posts: [Post]
}
type Query {
users: [User]
}
```
and execute this query:
```gql
{
users {
posts {
... on Image {
image_url
}
... on Text {
content
}
}
}
}
```
What I have tried:
1. _Mongoengine models_: make PostModel as separate Document, inherit TextModel and ImageModel from it and reference PostModel from UserModel.
_Graphene objects_: make types for Text, Image, User and Post as MongoengineObjectType.
(full code [here](https://github.com/graphql-python/graphene-mongo/files/3951781/option1.py.txt))
This returns errors `Unknown type "Image".` and `Unknown type "Text".`
In this case Post type has only fields `Cls: String, id: ID`.
2. _Mongoengine models_: same.
_Graphene objects_: inherit Post from graphene.Union and set Image and Text as types of that union.
(full code [here](https://github.com/graphql-python/graphene-mongo/files/3951811/option2.py.txt))
This returns `Cannot query field "posts" on type "User".`.
I suppose this happens because now graphene_mongo does not state that `User.posts` reference `Post`
So how should such schema be implemented?
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.