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

Recommendation: add SQLAlchemy session object context_value in README #5

Open
Diggitysc opened this issue Dec 4, 2017 · 1 comment

Comments

@Diggitysc
Copy link

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

@sydoluciani
Copy link

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

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