Basic tutorial on graphql in go ... with gophers in space.
What is it? Graphql is a query language for APIs developed by Facebook.
Why use it?
- one call
- define percisely the data you want
How a graphql server is used:
- As a main server (ie CRUD)
- As a microservice that exposes data. Business logic lives in other services written in many languages
No apollo today :( ...
Instead we will make our queries and mutations with altair, a graphql client.
install with brew cask:
$ brew cask install altair-graphql-client
./example_1
Implement using graphql-go/graphql
We create the graphql schema, types, and define the resolvers.
./example_2
Lib implements it for you 99designs/gqlgen
Pick a library that will manage splitting the schema and mutations in seperate files with autogenerated code. Some comparisons
This examples in this repo depend on:
Install them by running:
example_1
$ go get github.com/gorilla/mux
$ go get github.com/graphql-go
example_2
$ go get github.com/99designs/gqlgen
After installing the deps, you can start the application by browsing to the root folder.
example_1
$ go run main.go
example_2
implement notes in README.md
go run ./server/server.go
For the learnings:
For the noice implementation:
https://developer.github.com/v4/
https://developer.github.com/v4/guides/forming-calls/
Glossary:
https://www.apollographql.com/docs/resources/graphql-glossary
How to graphql
- Study examples, and think about how the front end views data
- Make it obvious with names: Query vs Mutation
- Focus on writing the schema, types, and the resolvers
Dev Tools