Over the last decade, Go has cemented its place among the most popular multipurpose programming languages. With great documentation, a highly active community, and a relatively easy learning curve, it’s become the go-to (hehe) choice for many developers. Golang can be used for many things, but its speed and code efficiency make it a great choice for building GraphQL servers!
In this post, I’ll walk through building your first GraphQL server in Golang. We’ll cover:
- The prerequisites
- Setting up your schema
- Hooking up some data
- Setting up your server and mutations
- Embedding the Apollo Sandbox IDE to explore your graph
Let’s get started!
Prerequisites to follow this Golang Tutorial
To follow along in this how-to, you should have your dev environment setup to write Go code (see the official docs), and have an understanding of how GraphQL works. If you are just starting out with GraphQL or are looking to expand your knowledge, Apollo Odyssey has some great interactive tutorials to help you.
We will be using the graphql-go library to set up our server. They have great examples and documentation if you want to continue down the GraphQL x Golang path!
You can follow along & find the final code for this tutorial on GitHub.
What are we building?
In the Middle Ages, folks created encyclopedias of real and fictional animals called bestiaries. Inspired by The Odd Bestiary by Alan James Robinson and Laurie Block, we want to digitize an encyclopedia of all these creatures, bringing together many different publications into one Bestiary API!