GraphQL and pyramid

336 views
Skip to first unread message

Lukasz Szybalski

unread,
May 9, 2018, 8:16:44 PM5/9/18
to pylons-...@googlegroups.com
Hello,
Are there any examples on how to create a GraphQL endpoint in pyramid project that was created using pyramid-cookiecutter-alchemy

config.add_route('api_graphql', '/api/graphql')



@view_config(route_name='api_graphql', renderer='json')
def api_graphql(request):
    """?."""
    return


Thanks
Lucas

Tres Seaver

unread,
May 10, 2018, 12:02:16 PM5/10/18
to pylons-...@googlegroups.com
I don't know from graphql. Looking at the "Python server library" link on
graphql.org[1], it looks like you would define a graphene query class, and
then use it to respond to a JSON POST request[2]:

---------------------------------- %< ----------------------------------
import graphene

class Query(graphene.ObjectType):
hello = graphene.String()

def resolve_hello(self, args, context, info):
return 'Hello world!'

schema = graphene.Schema(query=Query)

@view_config(route_name='api_graphql', method='POST', renderer='json')
def api_graphql(request):
json_body = request.json_body
query = json_body['query']
variables = json_body.get('variables', {}
return schema.execute(query, variable_values=variables)

---------------------------------- %< ----------------------------------


[1] https://graphql.org/code/#python
[2] http://graphql.org/learn/serving-over-http/#post-request



Tres.
--
===================================================================
Tres Seaver +1 540-429-0999 tse...@palladion.com
Palladion Software "Excellence by Design" http://palladion.com

Alexandre Souza

unread,
May 16, 2018, 3:37:42 PM5/16/18
to pylons-discuss
Hello,

I'm actually working on one. It's a brazilian_portuguese project, but the code is in english and it's from cookiecutter-alchemy:

The CRUD is almost complete, but I think it could be useful for you. =]

Have a nice day,
Alexandre S.

Steve Piercy

unread,
May 16, 2018, 4:22:18 PM5/16/18
to pylons-...@googlegroups.com
Would this be a good Pyramid Community Cookbook recipe?

https://docs.pylonsproject.org/projects/pyramid_cookbook/en/latest/

I'm not sure under which category it would fall. A new category
can be created, or use the default "miscellaneous".

--steve


On 5/16/18 at 8:28 AM, alexandre....@gmail.com
(Alexandre Souza) pronounced:
------------------------
Steve Piercy, Eugene, OR

Reply all
Reply to author
Forward
0 new messages