On 05/09/2018 08:16 PM, Lukasz Szybalski wrote:
> 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

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          [email protected]
Palladion Software   "Excellence by Design"    http://palladion.com

-- 
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pylons-discuss/pd1q9o%24efh%241%40blaine.gmane.org.
For more options, visit https://groups.google.com/d/optout.

Reply via email to