graphene-sqlalchemy
graphene-sqlalchemy copied to clipboard
Examples don't work
Hi,
I followed the flask-sqlalchemy examples here (and the snippets in the project's Readme as well) but it didn't work out of the box. I had the following exception: AttributeError: 'Request' object has no attribute 'get' when trying to request from Graphiql.
After some fiddling with flask-sqlalchemy i solved the bug by passing a context argument to GraphQLView.as_view.
Here is my full url declaration:
app.add_url_rule(
'/graphql',
view_func=GraphQLView.as_view(
'graphql',
schema=schema,
graphiql=True,
context={'session': db_session}
),
)
I don't know if this is the proper way to fix the problem, but thought it'll be useful to tell you about it.
I faced similar issues as well and @Morreski 's example helped me fix the issue somewhat.
@syrusakbary @jhgg
Any plans on updating the documents or would you accept a pull request that updates the examples?
Same problem for me. @Morreski solution works for me.
Same problem
Same problem. @Morreski 's tip worked.
However this might be related as well: http://docs.graphene-python.org/projects/sqlalchemy/en/latest/tips/
With modern flask-graphql use get_context=lambda: {'session': db.session}:
app.add_url_rule(
'/graphql',
view_func=GraphQLView.as_view(
'graphql',
schema=schema,
graphiql=True,
get_context=lambda: {'session': db.session}
)
)
See https://github.com/graphql-python/flask-graphql/issues/52#issuecomment-412773200
@yoursdearboy Super!! Your (lambda) solution worked for me using the Dec 2020 version of graphene.
If anyone wants to explore a minimal running version, code and setup instructions are here.