GraphQL Ruby Logo

GraphQL Ruby

Install the Gem

# Download the gem:
gem install graphql
# Setup with Rails:
rails generate graphql:install

Get going fast with the graphql gem, battle-tested and trusted by GitHub and Shopify.

Define Your Schema

Describe your application with the GraphQL type system to create a self-documenting, strongly-typed API.

# app/graphql/types/profile_type.rb
Types::ProfileType = GraphQL::ObjectType.define do
  name "Profile"
  field :id, !types.ID
  field :name, !types.String
  field :avatar, Types::PhotoType
end

Run Queries

# app/controllers/graphql_controller.rb
result = MySchema.execute(
  params[:query],
  variables: params[:variables],
  context: { current_user: current_user },
)
render json: result

Serve queries to build a great UI or webservice.

Add GraphQL to your Ruby app. Get Started!