GraphQL Ruby Logo

GraphQL Ruby

The graphql gem implements the GraphQL Server Specification in Ruby.

Use it to add a GraphQL API to your Ruby or Rails app.

Install the Gem

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

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

Define Your Schema

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

# app/graphql/types/profile_type.rb
class Types::ProfileType < Types::BaseObject
  field :id, ID, null: false
  field :name, String, null: false
  field :avatar, Types::PhotoType
end

Serve Queries

Provide custom data to clients and extend your API with mutations, subscriptions, streaming responses, and multiplexing.

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

Harden Your API

Confidently deploy GraphQL with GraphQL-Ruby:

Integrate with Client Libraries

graphql-ruby-client provides integration with Apollo Client, Relay, GraphiQL, urql, or custom JavaScript.

Going Beyond

Customize your GraphQL API:

Add GraphQL to your Ruby app. Get Started!