GraphQL-first Django
2020-09-19, 11:15–11:55, Virtual

GraphQL is a more flexible alternative to REST for building web APIs, and thus is becoming a strong foundation for any modern web stack. This is especially true where static HTML templates are not cutting it or a sophisticated single-page interface is needed, which is often the case on the web nowadays. Even though Django was designed as a model-view-template framework, it can work perfectly well as a GraphQL server to power JavaScript apps. This talk will elaborate on the anatomy of a GraphQL-first Django application, in which GraphQL queries and mutations are the primary interfaces exposed by the backend, while the frontend remains fully dynamic.


GraphQL is finding itself as a foundation of the modern web development stack, particularly where a dynamic, single-page UI is required. It unlocks many great benefits, some of which are:

  • fetching only the required data necessary to render particular views; while eliminating the need to call and combine data from multiple endpoints
  • developer experience through incredible out-of-the-box tooling available - interactive API explorers or code generators for statically typed languages used in the frontend
  • ability to combine various APIs under a single gateway with federations

Django is loved for its simplicity, reliability, and excellent documentation. All this makes it an obvious choice for many backend teams that speak Python. Although designed as a model-view-template framework, it can be successfully used as a GraphQL server.

In this talk, we'll take a look at the architecture and different aspects of a Django project, where the GraphQL API is a first-class citizen:

  • structure of a single Django app - how to organize the modules for GraphQL types, mutations and queries
  • mapping Django models to GraphQL types and building CRUD mutations to manage them
  • authentication with JSON Web Tokens
  • testing GraphQL queries with py.test

Additionally, we will also see how choosing GraphQL can affect the entire product development process in teams where JavaScript / TypeScript are the primary languages used for frontend development. Lastly, we'll talk about some of the downsides of Graphene that every developer needs to be aware of, and also about the new alternatives that have begun to show up in the Python/GraphQL ecosystem.

The structure of the talk:

  1. A case for GraphQL - the most essential benefits, how it differs from REST, the main concepts, and examples - 5 min
  2. GraphQL-first Django - the anatomy of a Django application that exposes a GraphQL API built using the Graphene framework - 15 min
  3. A GraphQL-first workflow - how schema-first approach speeds up web development for both frontend and backend teams - 5 min
  4. The limitations of Graphene and the future of GraphQL in Python - 5 min

Video: https://www.youtube.com/watch?v=GoGpjngDB7c&ab_channel=DjangoConEurope