--- title: Welcome fullwidth: false ---
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.

{% highlight bash %} # Download the gem: bundle add graphql # Setup with Rails: rails generate graphql:install {% endhighlight %}

Define Your Schema

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

{% highlight ruby %} # 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 {% endhighlight %}

Serve Queries

Provide custom data to clients and extend your API with {% internal_link "mutations", "/mutations/mutation_root" %}, {% internal_link "subscriptions", "/subscriptions/overview" %}, {% internal_link "streaming responses", "/defer/overview" %}, and {% internal_link "multiplexing", "/queries/multiplex" %}.

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

Harden Your API

Confidently deploy GraphQL with GraphQL-Ruby:

  • {% internal_link "Testing helpers", "/testing/overview" %} to validate your system
  • {% internal_link "Authorization", "/authorization/overview" %} integrates with your app's permission system
  • {% internal_link "GraphQL::Dataloader", "/dataloader/overview" %} optimizes access to data sources
  • {% internal_link "Complexity limits", "/queries/complexity_and_depth" %}, {% internal_link "timeouts", "/queries/timeout" %}, and {% internal_link "rate limits", "/limiters/overview" %} to protect your server resources
  • {% internal_link "Tracing", "/queries/tracing" %} for integration with your APM or custom usage
  • {% internal_link "API versioning", "/changesets/overview" %} to roll out changes while preserving client experience
  • {% internal_link "Persisted queries", "/operation_store/overview" %} to guarantee approved API usage
  • {% internal_link "Caching", "/object_cache/overview" %} to serve repeated data requests

Integrate with Client Libraries

{% internal_link "graphql-ruby-client", "/javascript_client/overview" %} provides integration with {% internal_link "Apollo Client", "/javascript_client/apollo_subscriptions" %}, {% internal_link "Relay", "/javascript_client/relay_subscriptions" %}, {% internal_link "GraphiQL", "/javascript_client/graphiql_subscriptions" %}, {% internal_link "urql", "/javascript_client/urql_subscriptions" %}, or custom JavaScript.

Going Beyond

Customize your GraphQL API:

  • {% internal_link "Language tooling", "/language_tools/visitor/ %} for manipulating GraphQL documents
  • {% internal_link "Type system extensions", "/type_definitions/extensions/ %} for customizing your schema definition
  • {% internal_link "Query analysis", "/queries/ast_analysis" %} for ahead-of-time query inspection

Add GraphQL to your Ruby app. Get Started!