-
Notifications
You must be signed in to change notification settings - Fork 113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What is intended way to implement Union? #117
Comments
@sVerentsov : I will take a look, thanks. |
I managed to solve this by explicitly stating class User(MongoengineObjectType):
class Meta:
model = UserModel
posts = graphene.Field(graphene.List(lambda: Post))
class Post(graphene.Union):
class Meta:
types = (Image, Text) Full working code here It is quite suprising that graphene-mongo resolves |
graphene-mongo/graphene_mongo/tests/models.py Lines 61 to 74 in 33be606
generic_reference = mongoengine.GenericReferenceField(
choices=[Article, Editor, ]
) or you can use |
Here is the schema that i am trying to implement:
and execute this query:
What I have tried:
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)
This returns errors
Unknown type "Image".
andUnknown type "Text".
In this case Post type has only fields
Cls: String, id: ID
.Mongoengine models: same.
Graphene objects: inherit Post from graphene.Union and set Image and Text as types of that union.
(full code here)
This returns
Cannot query field "posts" on type "User".
.I suppose this happens because now graphene_mongo does not state that
User.posts
referencePost
So how should such schema be implemented?
The text was updated successfully, but these errors were encountered: