Skip to main content

Ruby On Rails Middleware

The Inigo plugin for Ruby On Rails provides full observability and controls on all individual graphs. Follow the instructions to get up and running.


Inigo requires an installation of Inigo::Tracer into your Rails application.

Create an Inigo Service and Get an Inigo Token

You may use the Inigo CLI as such:

inigo create service >>your_service_name<<
inigo create token >>your_service_name<<

Gem Installation

Note: The inigorb gem requires Ruby 3.1 or greater.

gem install inigorb

Integration of Inigo Tracer

Use Inigo::Tracer in your configured Graphql::Schema.

class InigoRorSchema < GraphQL::Schema
trace_with Inigo::Tracer
# use GraphQL::Pro::OperationStore, redis: Redis.new

mutation(Types::MutationType)
query(Types::QueryType)
subscription(Types::SubscriptionType)
end

Note: if you use Operation Store from graphql-pro gem you have to use tracer BEFORE you use GraphQL::Pro::OperationStore so tracer gets resolved queries.

Pass request data to Inigo Tracer

All the graphql package tracers do not have access to the request data, so it is required to pass it in the context to the execute of the schema.

class GraphqlController < ApplicationController
def execute
variables = params[:variables]
query = params[:query]
operation_name = params[:operationName]
context = {
:headers => request.headers
}
result = InigoRorSchema.execute(query, variables: variables, context: context, operation_name: operation_name)
render json: result
end
end

Add Inigo Puma plugin to Puma configuration file

...

plugin "inigo"

Puma::Plugin::InigoPlugin.configure do |config|
config.schema_class = InigoRorSchema
end

...

Note: if you use Puma clustered mode on local machine with Mac OS you might encounter errors similar to these

objc[29769]: +[NSNumber initialize] may have been in progress in another thread when fork() was called.
objc[29769]: +[NSNumber initialize] may have been in progress in another thread when fork() was called. We cannot safely call it or ignore it in the fork() child process. Crashing instead. Set a breakpoint on objc_initializeAfterForkError to debug.

This is a known Ruby-Mac issue link1 link2 and explanation with solution for local development.

Inigo Tracer Subscription Support

To be able to track subscriptions the only thing is required to do is to prepend Inigo::Data to the channels you use to build communication.

class GraphqlChannel < ActionCable::Channel::Base
prepend Inigo::Data

def subscribed
@subscription_ids = []
end

def execute(data)
...
end

def unsubscribed
@subscription_ids.each { |sid|
InigoRorSchema.subscriptions.delete_subscription(sid)
}
end
end

Note: Subscription support is only available for the ActionCable method.

Router Setup Example (If Necessary)

If /graphiql and /graphql are not automatically set up for your Rails application in config/routes.rb, it can be done as such:

Rails.application.routes.draw do
if Rails.env.development?
mount GraphiQL::Rails::Engine, at: "/graphiql", graphql_path: "/graphql"
end

post "/graphql", to: "graphql#execute"
end

Configure the Schema class (If Necessary)

In your GraphQL::Schema class (i.e. app/graphql/inigo_ror_schema.rb), make sure the mutation and query are configured as such:

class InigoRorSchema < GraphQL::Schema
mutation(Types::MutationType)
query(Types::QueryType)
end

Execute some GraphQL queries in GraphiQL and they will soon be visible on https://app.inigo.io under the relevant Inigo Service.

Configuration Options

NameTypeRequiredDescription
INIGO_SERVICE_TOKENstringYesService token
INIGO_DEBUGboolNo
default: False
Enable debug mode