Document Actions

Òscar Vilaplana - Let's make a GraphQL API in Python

Filed Under:

Òscar Vilaplana talks about making a GraphQL API in Python, at PyGrunn.

See the PyGrunn website for more info about this one-day Python conference in Groningen, The Netherlands.

This talk is about GraphQL, Graphene, and Python.

I care a lot about value. If something has no value, why are you doing it?

"Our frontend engineers want us to use GraphQL."

Sample case: there are friends, they have plans, the plans are at a location. So various relations between friends, plans and locations.

With REST you usually fetch too much or too little, you have many calls, some documentation but not really standard, it is hard to discover, not really a standard client, much postprocessing and decisions needed.

So you can try to fix some stuff, giving options to include more data, or not include that many fields. I don't really like it. What can we do?

If you go back to the data, you can see a graph: data that is linked to each other.

"Our frontend engineers want us to use GraphQL. They can just ask for what they want."

In the backend you are trying to decide or guess what the client wants. The client want a nice looking web site. What we have is a bunch of data in too many boring tables.

GraphQL is a query language for graphs. You can ask stuff like this and get data in this format back:

{ plans
  creator: {

You define possible queries:

type Query {
  plans(limit: Integer): [Plan]
type Plan {

With Graphene you can do this in Python. And there is Django support in graphene_django, to easily wrap this around some models. It is smart about combining queries.

GraphQL makes it easier to expose data. It is closer to the data, so less waste. Easy to get started.

You can play with the GitHub GraphQL api.

Twitter: @grimborg