Introduction

Graphql is all the rage since it was released to the public from Facebook in 2015 “GraphQL: A data query language”. Numerous clients/servers in varying degrees of maturity have appeared. The tangible benefit of Graphql is to reduce the storm of REST calls to compose the parts of an object. This way the API is not abused to behave as a query language. We use SQL to send queries to the database, we send GraphQL to query whole objects to a server that aggregates the parts of the result not from a database only, but from various sources like third-party services too.

Scope

This article targets the beginner Pythonista. Just the bare basics but with the ambition to help the beginner blossom. We target the typical Flask / SQLAlchemy duo through the wonderful Graphene library . We also utilize the flask-graphql library from the same master project. The purpose of this article is modest and builds upon the excellent Flask tutorial that is a prerequisite and from which we heavily borrowed. Grab you favorite text editor or IDE and lets get started. I used Python 3.8.5 during development, and I manually tested the app.

Code and Dependencies

You can grab the code from my repo:

fithisux/beginner-python-graphql

You can’t perform that action at this time. You signed in with another tab or window. You signed out in another tab or…

github.com

The specific combination of packages in the requirements.txt was a successful one when this article was written. Hopefully people can use latest packages in the future.

Target

Lets outline here from the beginning what we are trying to achieve. We aim to throw away the html layers of the Flask tutorial app and instead CRUD posts and users through GraphQL. We still use the SQLite database of the tutorial app but instead we use SQLAlchemy as an ORM both for initialization and access. We will not write automated tests in this article. But in any case we need to be able to manually test what we have achieve so far. To this purpose we use the interactive GraphQL client that runs as part of our server to view our schema and to execute CRUD actions. There maybe more automated ways to achieve our purpose. These are out of scope for this article.

#flask #graphql

GraphQL for the Beginner Pythonistas
1.10 GEEK