GraphQL and Django

Anton Pirker

Django Meetup Vienna - November 7th 2017

GraphQL

  • System for fetching and manipulating data from/on a server
  • Query language + type system + server component
  • Instead of having many dump API endpoints (REST), just one smart endpoint (GraphQL).

What does it look like?

 GET request to /graphql/                                           Reponse JSON

What does it look like?

 GET request to /graphql/                                           Reponse JSON

What does it look like?

 GET request to /graphql/                                           Reponse JSON

What does it look like?

 GET request to /graphql/                                           Reponse JSON

GraphQL summarized:

  • Ask for what you need, get exactly that
  • Get many resources in a single request
  • Decoupling of client app and server API development

Implementation

Django integration

Define your models as always

  ingredients/models.py

Django integration

Add a GraphQL schema

  ingredients/schema.py

!

!

Introducing 'Relay'

  • Convention on how to specify your schema
  • Standardized way to pagenate, refetch and manipulate objects
  • Specification: facebook.github.io

More on 'Relay'

  • Graphene has complete support for Relay
  • If a schema has connections, edges and nodes, its Relay.
  • Client side lib for creating react relay apps: react-relay

Pro

  • It's cool
  • It can speed up development
  • It make changing client app way easier
  • It minimizes amount of data transferred

Cons

Conclusion

Thank's!

anton@ignaz.at - www.anton-pirker.at

GraphQL and Django

By antonpirker

GraphQL and Django

  • 1,162