REST Servers in Go: Part 7 - GraphQL

submited by
Style Pass
2021-06-10 06:30:02

In the previous parts of this series, we've focused on different approaches to develop a REST API for our simple task management application. In this part, we're going to take a much larger leap and look at how a similar API can be exposed with GraphQL instead of REST.

Although this post spends some time explaining the motivation for using GraphQL and compares GraphQL to REST, this is not its primary goal. There are many resources explaining these things, and I encourage you to google and read a few. The main goal of this post is to show an example of setting up a GraphQL server in Go. To make things simpler, it uses a very similar data model to the one in previous parts in the series (a simple backend API for managing a task list).

Consider our task database as described in part 1; it's very simplistic, so to really motivate GraphQL we'll want to make it a bit more realistic. Let's add a sequences of attachments to each task; the Go model will now look like this:

The 1 ---- * edge between the boxes implies a one-to-many relationship in relational database terms. Each task can have multiple attachments.

Leave a Comment