graphql-python / graphql-python/graphene-mongo

What is intended way to implement Union?

Aperta
#117 3 commenti 0 reazioni 1 assegnatario Rivendicata da @abawchen Vedi su GitHub
good first issue wait for response
Lingua principale
Python
Stelle
287
Fork
111
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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?

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.