webob-graphql
webob-graphql copied to clipboard
Recommendation: add SQLAlchemy session object context_value in README
Thank you for creating such a great library. This is a huge benefit to my project.
That being said, I had to jump through a few hoops to figure out how to get querying up and running for the graphiql interface (with SQLalchemy running the backend models and linked into the database session/transaction manager)
I was finally able to get everything wired up by setting the following: return serve_graphql_request(request, schema, context_value={'session': request.dbsession}, graphiql_enabled=True)
It would be helpful to list for other SQLAlchemy users who want a quick graphql interface via webob instead of flask.
Thank you guys for all your hard work
If cookie cutter has been used to create pyramid project, and result of session factory(new session) is added to request method as dbsession, then we should replace session with dbsession: serve_graphql_request(request, schema, context_value={'session': request.dbsession}, graphiql_enabled=True)
https://github.com/Pylons/pyramid-cookiecutter-starter/blob/latest/%7B%7Bcookiecutter.repo_name%7D%7D/%7B%7Bcookiecutter.repo_name%7D%7D/sqlalchemy_models/init.py#L75
Otherwise, session is available in request method with the same name and current example works fine: https://github.com/graphql-python/webob-graphql#pyramid