Python is a general purpose and mature language, used to create solutions from Web APIs to Artificial Intelligence. It has a lovable community, empowering the minorities and making everyone feel welcomed. If you are new to the language, you might want to check Learn Python the Hard Way – it’s really easy!
One of its most famous libraries is Django, the web framework for perfectionists with deadlines. It allows you to quickly prototype and build full web applications with less code.
Last but not least, there’s Graphene and Graphene-Django, exposing a simple and powerful API for creating GraphQL servers.
In this tutorial, you’ll implement your own GraphQL server by developing a Hackernews clone using the technologies mentioned above.
A GraphQL server should be able to:
{ "query": "query { allLinks { url } }" }
{ "data": { "allLinks": { "url": "http://graphql.org/" } } }
{
"errors": [{
"message": "Cannot query field \"unknown\" on type \"Link\"."
}]
}
These are the basic features all GraphQL servers have, but of course, they can do much more as needed. You can read in more detail about the expected behavior of a GraphQL server in the official specification.
An important thing to note about building a GraphQL server is that the main development process will revolve around the schema definition. You’ll see in this chapter that the main steps we’ll follow will be something like this:
The schema is a contract agreed on between the frontend and backend, so keeping it at the center allows both sides of the development to evolve without going off the spec. This also makes it easier to parallelize the work, since the frontend can move on with full knowledge of the API from the start, using a simple mocking service which can later be easily replaced with the final server.
Add Token based authentication with django-graphql-jwt. Thanks mongkok for the library and contribution!
Change Django and Graphene to version 2.
Original content :)