falcon-graphene icon indicating copy to clipboard operation
falcon-graphene copied to clipboard

Helpers for registering Graphene schemas in Falcon.

falcon-graphene

Helpers for registering Graphene schemas in Falcon as advised by the GraphQL best practices documentation for GraphQL over HTTP.

Example

import falcon

from falcon_graphene import GrapheneRouter

import graphene


class Clock(graphene.ObjectType):
    name = graphene.String()


class RootQuery(graphene.ObjectType):
    clock = graphene.Field(Clock)

    def resolve_clock(self, args, context, info):
        return Clock(name="Charlie")


application = falcon.API()
schema = graphene.Schema(query=RootQuery)
router = GrapheneRouter.from_schema(schema).serving_on(application)

Note: You can try this out in the examples directory.

We can now execute GraphQL queries via a GET or POST to /graphql:

http POST :8000/graphql query='{ clock { name } }'

Note: This example uses HTTPie.

What is this?

This is simply a bit of glue to interact with a GraphQL API defined in Graphene with the Falcon API framework. By staying simple and using Falcon's architecture, it can do a few things for you:

  • Registers handlers under the standard /graphql endpoint
  • Allows you to bring all of your existing middleware, request/response handling, etc.
  • Pushes the Falcon request context down as the resolve_* context argument

What is this not?

Fancy.

Testing

Tests use toxTo get started, ensure tox installed, then just run tox.