Skip to content
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

Problem with EmbeddedFiled (Can't query via graphql #152

Open
david2003542 opened this issue Aug 29, 2020 · 1 comment
Open

Problem with EmbeddedFiled (Can't query via graphql #152

david2003542 opened this issue Aug 29, 2020 · 1 comment

Comments

@david2003542
Copy link

david2003542 commented Aug 29, 2020

Hi Guys, Currently I set up a simple model, schema, type as below. However, I don't know why when I use EmbeddedField it works in the runtime (It doesn't show any runtime error) but I can't operate any query on this field.

Error messge
"Cannot query field "metadata" on type "Scenario"

Environment:
Python3.6
Python3.8

Computer system
Mac: MacOC

Models.py

# EmbeddedDocument Models
class Scenario(EmbeddedDocument):
    name = models.StringField(max_length=100)
    creationDatetime = models.DateTimeField()
    lastUpdateDatetime = models.DateTimeField()
    data = models.DictField()
    cancellation = models.BooleanField(default=False)
    isDefault = models.BooleanField(default=False)


# Document Models
class View(Document):
    name = models.StringField(max_length=100)
    scenarios = models.EmbeddedDocumentListField(Scenario)
    cancellation = models.BooleanField(default=False)

Types.py

class ViewType(MongoengineObjectType):
    class Meta:
        model = View
        interfaces = (relay.Node,)

Schema.py

class Query(graphene.ObjectType):
    node = Node.Field()    
    view = MongoengineConnectionField(ViewType)
    views = graphene.List(ViewType)
    
    def resolve_views(self, info, name):
        return View.objects.get(name=name)

Also, I have tried the solution on this issue as well
#32

I will get an error when I declare the reference model

@david2003542 david2003542 changed the title Problem s Problem with EmbeddedFiled (Can't query via graphql Aug 29, 2020
@abawchen
Copy link
Collaborator

abawchen commented Sep 2, 2020

@david2003542
Have you tried to declare ScenarioType as follows before ViewType?

class ScenarioType(MongoengineObjectType):
    class Meta:
        model = Senario
        interfaces = (relay.Node,)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants