GraphQL is a another way to build your APIs.
First of all - I would say what GraphQL is not a REST “killer” or replacement for REST, it’s a completely different concept.
You can find a tons of “comparison” between REST and GrahpQL, and topics about “why” and “when” you should use it.
Let’s see some quick checkpoints:
- REST and GraphQL are totally different
- GraphQL isn’t a magic bullet, nor is it “better”
- You can use both at the same time
- GraphQL is great tools if used for the right thing
So, let’s start. As a example project, I’ll use my small pet project for our office purposes runboard.
Simple add graphql into your Gemfile.
And run installer script. It creates some GraphQL specific files in your project.
So, we are ready to write our first queries.
All root queries we should describe in QueryType Type, for example like this:
Nothing unclear here, right? Simple ActiveRecord queries in field blocks.
After that, we need to create our first Type for our User and Project models:
After that, we are ready for our queries!
P.S You can use web graphiql or desktop version.