GraphQL “Hello World”
Deploying a Graphene Server on Google Cloud
Once I understood the purpose of GraphQL, my next step was to try to implement it. Given my familiarity with Python, I decided to deploy it via a Django web server and Graphene — a “code first” framework for GraphQL. I loosely followed the instructions here:
graphql-python - Introduction
is a general purpose and mature language, used to create solutions from Web APIs to Artificial Intelligence. It has a…
There were several complicating factors involved which slowed my progress, not the least of which was the fact that the tutorial is based on relatively old versions of software, some of which had compatibility issues with current OS and software packages. In addition, the demo is configured for someone to configure on their desktop / laptop environment, whereas I was deploying to a Google Compute Engine server. This required additional troubleshooting and configuration not covered in the tutorial.
I started by creating a Google Cloud project. In that project, I configured a network, firewall, and routing rules which would allow me to create a virtual machine and connect it to the Internet. Next, I enabled BigQuery — which I intend to use as the back-end data source — and created a copy of the public synthetic health data dataset.
Finally I began provisioning and testing virtual machines. I experimented with both Ubuntu and Debian, and finally landed on Ubuntu as the underlying operating system. My base server configuration was a 4-CPU core server with 15 GB of RAM.
The current version of Django, a web server for Python which Graphene relies on, is 3.2.7. The instructions were configured for Django 2.1.4. (Not uncommon in my experience with open source, volunteer-led documentation like this…) After first attempting to port the tutorial instructions to the newer version of the software, I realized I was going to be in for some time-consuming troubleshooting well before I even had a good grasp on what it was I was doing. I eventually switched over and installed the version as described in the tutorial. The same holds true for the version of Python, Graphene, and other components deployed. In the end, it took four attempts to get to a working server and configuration.
The first step was to successfully configure Django and connect to it via a web browser.
To run Graphene/GraphQL, you have to configure the settings to allow your IP address to respond to TCP requests on the management port. Once done, you start the service as follows:
Once Django and Graphene installation and configuration were complete, next was the configuration of and connection to GraphQL as a service.
Finally, it was time to see if this thing actually worked. As part of the tutorial, you create some basic data, and then to ensure proper operation, you run a simple query against this data.
At this point I had confirmed that GraphQL was operational, reachable, and responding to queries as expected. My next effort would revolve around gaining a deeper understanding of GraphQL syntax, schema, types, and such, before actually trying to hook it up to BigQuery as a back-end data source. This turned out to be a little trickier than I had first thought, but that, dear readers, is a tale for another day.