Blog Post

Technology-Watch - GraphQL

by: Simon Hughes
date: Thursday, Dec 16, 2021
category: technology-watch graphql

I regularly get asked what technology I would use to build a brand new greenfield application and the answer is never simple and always depends on the context of the application, the use-cases required, but what is really clear to me is that GraphQL is coming up in more and more of my conversations. So what is GraphQL?

Code

If we go back 5 years and look at the standard typical web architecture we woulr have been talking about a web or mobile front end build in JavaScript running the browser and it would connect to REST style services over https. Its a great architectural model that is still being used everywhere today, but it does have some limitations.

The first major limitations of REST is the sheer number of endpoints that are needed. Typically a REST interfaces would comprise of a disrete endpoint for each entitiy in the business domain. What this means is we might end up having to call 10-20 services on each page to be able to provice the full suite of capabilites required. The second limitation is the rigidity of these API endpoints, each would return a defined entity, and we may only require 1 or 2 elements on it, but we end up retrieving everything and throwing it away.

In a simple example to render a list of transactions on a bank screen, we may end up calling an endpoint to get the bank account, then a separate end point to get a list of transactions for the bank account, but to display the details, we then have to iteratively call get transaction on each and every one of those transactions.

Enter GraphQL. GraphQL is a single endpoint that is used to allow you to read, update and create data across the whole platform, and its a structured language which allows us to query exactly what we need, and allows us to get hierachical data allowing simpe queries to get everything in one go. A simple GraphQL query below allows us to get the details on the user, their bank acccounts, and all the transaction details in one go.

query {
    User (id: "simon") {
        FirstName
        LastName
        Accounts {
            AccountName
            SortCode
            Transactions {
                Date
                Credit
                Debit
                Balance
            }
        }
    }
}

So whats does this mean. Well for one thing it makes things quick, much quicker. If you decide to use an off the shelf GraphQL server then you can start developing within hours. This year we put a team together to build msgboxx which is a team inbox solution for WhatsApp. When we started out we wanted to use the best technology we could find to build the system as quickly as possible. We chose an dedicated SaaS platform for identity to manage our users and handle issuing JWT tokens, and we deployed an instance of Hasura. Within a small number of hours we had our first cut data model built out in Hasura and had authenticated users able to query it. That meant we cool quickly start to build out our react application and start to iterate. Within the first 2 days we had the basics of users, authentication, authorisation, inboxes, and the basics of a messaging app built. Had we been building this with a REST style model then we would have a good 2-3 weeks of work still to do.

But there must be some downsides of GraphQL? Of course, as with everything there are downsides. The biggest issue we had to overcome was around the use of documents. GraphQL is great for relational data in databases, but has no solution for files. Thanksfully this was easily solved by build out a simple REST API in AWS Lambda functions wrapping an S3 bucket to give us a nice simple secure API for uploading and downloading documments, all secured with the same JWT tokens.

A quick shoutout to some technology in the GraphQL space which we have been using to great effect. Hasura.io is a great place to start if you're looking for a GraphQL server. They have a free open source community edition which is supported as a prebuilt docker instance, though to a commercial Software a Service cloud hosted solution. And on the client side we also had great success with ApolloClient, and Auth0 for an authentication Saas Platform.

Related Blog Posts

Technology-Watch - Insource or Outsource

Almost all of the companies I work with have started off by having an MVP built by an external design agency, but usually struggle to get the focus their products require post launch. At this point there are many options that I explore below.

Read More

Technology-Watch - Buy or Build

The question about whether we should build software or buy software is one I get asked more than any other. Here I will explain some of my thought processes on this subject. In case you don't already know it building software is hard, really really hard, and very expensive.

Read More

Technology-Watch - Progressive Web Applications

For a long time web applications provided a sub-standard user experience on a mobile compared to native applications. Historically the device APIs including offline content, push notifications, and location were only available to native applications but recently these APIs have been opened up to web applications. So what do we have?

Read More