Well what do you know, I had a pleasure getting started with Ruby on Rails framework. I liked the productivity that it has and how most of pieces were pretty straightforward to do.
Today, I am going go over on how to setup GraphQL application with Ruby on Rails framework in API only mode.
First of, obviously, you would need to have to have Ruby
language installed on your system.
I used rbenv
to manage my ruby versions, it is similar to nvm
or sdkman
if you are
coming from JVM
world.
brew install rbenv
# then install actual ruby version
# for this blog post I am going to use ruby version 3
rbenv install 3.0.1
# Downloading ruby-3.0.1.tar.gz...
# -> https://cache.ruby-lang.org/pub/ruby/3.0/ruby-3.0.1.tar.gz
# Installing ruby-3.0.1...
# ruby-build: using readline from homebrew
# you can also list versions that you can install with rbenv
# if you wish choose something else
rbenv install --list
Let's then install rails
gem and bundler
to manage our dependencies.
gem install rails
gem install bundler
Alright, so nwo we have rails cli tool installed, it can generate a lot of boilerplate code for us like models, GraphQL types and etc.
Next, we will start new application without frontend and with postgres as our database choice
rails new app --api -d postgresql
Once that installed, let's go inside of that folder and install GraphQL
gem
bundle add graphql
Bootstrap GraphQL
configuration and some built-in types
rails generate graphql:install
Now everything located under app/graphql
is obviously GraphQL
related stuff