Closed
Description
Error description
Running the tutorial application at https://graphene-mongo.readthedocs.io/en/latest/tutorial.html with graphql-server[flask]
instead of Flask-GraphQL
installed results in the following error being returned
{
"errors": [
{
"message": "'dict' object has no attribute 'queryset'",
"locations": [
{
"line": 2,
"column": 3
}
],
"path": [
"allEmployees"
]
}
],
"data": {
"allEmployees": null
}
}
Underlying Cause
graphql-server passes its GraphQLResolveInfo.context
as a dict
rather than an object with attribute getters and setters, which leads to an Exception whenever graphene-mongo attempts to set a queryset attribute on it
graphene-django and the old Flask-GraphQL pass a Request object as the GraphQLResolveInfo.context
and graphene-mongo defaults the context to a graphene Context object if no context is specified
Workaround
Specify a different default context when instantiating graphql-server's GraphQLView.
from collections import UserDict
from flask import Flask, request
from graphql_server.flask import GraphQLView
app = Flask(__name__)
app.add_url_rule(
"/graphql", view_func=GraphQLView.as_view("graphql", schema=schema, graphiql=True,
context=UserDict())
Metadata
Metadata
Assignees
Labels
No labels