I am creating a project to query a mongo schema in GraphQL. I have a model which act as a mongo collection and schema file for mapping the model with graphql Query. When i try to query the fields in mongo models only id is getting populated and not able to retrieve other fields.
Code snippet below:
models.py
class A(EmbeddedDocument):
content_length = StringField(name="content-length", required=True)
expires = StringField()
destination = StringField()
subscription = StringField()
priority = StringField()
class B(DynamicEmbeddedDocument):
pass
class Store(Document):
meta = {'collection': 'event_store'}
one = EmbeddedDocumentField(A, required=True)
two = EmbeddedDocumentField(B, required=True)
schema.py
class StoreType(MongoengineObjectType):
class Meta:
model = Store
interfaces = (Node,)
class Query(graphene.ObjectType):
node = Node.Field()
all_stores = MongoengineConnectionField(StoreType)
store = graphene.Field(StoreType)
def resolve_all_stores(parent, info, **kwargs):
return list(EventStoreModel.objects.all())
schema = graphene.Schema(query=Query, types=[StoreType,])
Query in GraphIQL: Current result:
query{
allEvents{
edges{
node{
id
}
}
}
}
result
{
"data": {
"allEvents": {
"edges": [
{
"node": {
"id": "RXZlbnQ6NWQwNjFiZTBiMjNjYTAwYTdmMDk5YTgy"
}
}
]
}
}
}
Expected result:
query{
allEvents{
edges{
node{
id,
one,
two
}
}
}
}
{
"data": {
"allEvents": {
"edges": [
{
"node": {
"id": "RXZlbnQ6NWQwNjFiZTBiMjNjYTAwYTdmMDk5YTgy",
"one":[data],
"two":[data]
}
}
]
}
}
}
While querying i need fields from Store model(one, two). Thanks in advance