|
|
|
|
|
by blumomo
2873 days ago
|
|
The integration is actually straight forward if you use the "graphene" library which you already looked in to. If you use SQLAlchemy, there's even a graphene-sqlalchemy binding which makes it really really easy. Simply add a /graphql view to your Pyramid app such as: from cornice import Service
from pyramid.exceptions import HTTPBadRequest
from ..schemas import schema
graphql = Service(
name='graphql',
path='/graphql',
description="GraphQL",
accept='application/json',
renderer='json',
)
@graphql.post(permission='readwrite')
def post_graphql(request):
query = request.json_body.get('query')
variables = request.json_body.get('variables', None)
if not query:
raise HTTPBadRequest
return schema.execute(query, variable_values=variables, context_value={
'dbsession': request.dbsession,
'user_id': request.authenticated_userid,
})
|
|