This is a boilerplate for backend using: rails api only & graphql.
- Ruby Version:
2.4.2 - Database: Postgresql
gem 'rails', '~> 5.1.4'
gem 'pg', '~> 0.18'
gem 'puma', '~> 3.7'
gem 'graphql', '~> 1.7.7
# in order to make graphiQL work, these two gems are required
gem 'sass-rails'
gem 'uglifier'
# add graphiQL to development
gem 'graphiql-rails', '~> 1.4.8'
-
Clone this repository:
git clone git@github.com:moseslucas/api-rails-graphql.gitIf you're a non-git user download this as zip file -
Go to app directory and run:
bundle install && rails db:setup -
Start the server:
rails s -
Open browser and navigate to
localhost:3000/graphiql
-
At the right side of graphiQL there's a Documentation Explorer for all our APIs.
Check the query:
allMovies.Its type is
Movieand have the following properties:id: ID, title: String, price: Float -
Make a query call to fetch the
allMoviesAPI.(In graphql there are Mutations(think of it as POST) & Queries(think of it as GET)
Make a query call:
query { allMovies }we could also set the properties we want to fetch:
query { allMovies{ id, title, price } }we could also rename the propery name like javascript objects
query { allMovies{ id, title, amount: price } } -
Make a mutation call to post/create a record to the Movie model using the API
createMovie(In graphql there are Mutations(think of it as POST) & Queries(think of it as GET)
Make a mutation call:
mutation { createMovie( title: "Star Wars", price: 500 ) }we could also set what properties to return after the record has been created:
mutation { createMovie( title: "Star Wars", price: 500 ) { id, title, amount: price } }
- Moses Lucas
See also the list of contributors who participated in this project.
This project is licensed under the MIT License - see the LICENSE.md file for details



