The graphql
gem implements the GraphQL Server Specification in Ruby.
Use it to add a GraphQL API to your Ruby or Rails app.
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
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
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
Confidently deploy GraphQL with GraphQL-Ruby:
graphql-ruby-client
provides integration with
Apollo Client,
Relay,
GraphiQL,
urql, or custom JavaScript.
Customize your GraphQL API: