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:

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.

I’m aware that a data warehouse usually isn’t considered optimal for an API back-end. But for functional testing, it should work, and it’s cheap to set up and use, so… #winning

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.

Before you accuse me of losing my damn mind, that is most certainly *not* the external IP used to reach my server any more. Sorry, script kiddies… :)

The first step was to successfully configure Django and connect to it via a web browser.

Actually the first time I had configured Django, so was a neat exercise, except for the firewall troubleshooting (which is an exercise I will leave to the reader… eat your peas, Bob…)

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:

You can almost **feel** the excitement!

Once Django and Graphene installation and configuration were complete, next was the configuration of and connection to GraphQL as a service.

“Please state the nature of the medical emergency!”

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.

Nerd bliss, level 1 — COMPLETE!

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.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Jason Eden

Jason Eden

Data Science & Cloud nerd with a passion for making complex topics easier to understand. All writings and associated errors are my own doing, not work-related.