published: 3/13/2019last updated: 4/10/2019

graphql-ruby Setup

*Goal of this chapter

  • Setup graphql-ruby

  • Setup graphiql-rails

*Related official docs part

1. Install graphql-ruby gem

gem "graphql"

rails g graphql:install
Running via Spring preloader in process 49714 create app/graphql/types create app/graphql/types/.keep create app/graphql/rails_api_graphql_crud_tuto_schema.rb create app/graphql/types/base_object.rb create app/graphql/types/base_enum.rb create app/graphql/types/base_input_object.rb create app/graphql/types/base_interface.rb create app/graphql/types/base_scalar.rb create app/graphql/types/base_union.rb create app/graphql/types/query_type.rb add_root_type query create app/graphql/mutations create app/graphql/mutations/.keep create app/graphql/types/mutation_type.rb add_root_type mutation create app/controllers/graphql_controller.rb route post "/graphql", to: "graphql#execute" Skipped graphiql, as this rails project is API only You may wish to use for development:

*Don't be afraid of the files created!

We stop here. Later we create graphql:object

2. Install graphiql-rails gem

Graphiql is tool like below. we will use it later.

gem "graphiql-rails"

I use subdomain for api

Rails.application.routes.draw do
constraints subdomain: 'api' do
if Rails.env.development?
mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/graphql"
post "/graphql", to: "graphql#execute"

# uncomment out this line
require "sprockets/railtie"

*This is only needed if you use subdomain.

Rails.application.configure do
config.action_dispatch.tld_length = 0

Try Acceess