Skip to main content

Overview

Rails GraphQL provides extensive configuration options to customize behavior across your application. Configuration is set globally using the Rails::GraphQL.configure block.
Rails::GraphQL.configure do |config|
  config.version = ENV['GIT_COMMIT']
  config.enable_introspection = Rails.env.development?
end

Configuration Options

Version Control

version
string
default:"nil"
Helps track when objects were cached and registered. Cached objects with mismatching versions need to be upgraded or reloaded. Set this to your commit hash. TypeMap uses only the first 8 characters.

Caching

cache
ActiveSupport::Cache::Store
default:"nil"
The instance responsible for caching all information generated by requests. Maps automatically to Rails.cache if kept as nil. Can also be set per Schema.
cache_fallback
Proc
Fallback cache when Rails cache is not properly defined or set to use a NullStore. Sets itself up with a memory store because cache is crucial, especially for subscriptions.
cache_prefix
string
default:"'graphql/'"
The prefix key for all cache entries for GraphQL cached items.

File Structure

paths
Set<string>
List of nested paths inside the graphql folder that do not require their own namespace.

Logging

verbose_logs
boolean
default:"true"
Similar to ActiveRecord verbose logs, shows the path of the file that started a GraphQL request.
omit_parameters
Array<string>
List of parameters to omit from the logger when running a GraphQL request. These values are displayed better in the internal runtime logger controller.
filter_parameters
Array<string>
default:"nil"
Identical to Rails application filter_parameters, but exclusive for GraphQL operations. List of parameters to display as filtered in the logs. When nil, uses the same as the Rails application.

ActiveRecord Integration

ar_adapters
Hash
List of all supported ActiveRecord adapters. When an adapter is supported, it maps database types into GraphQL types using proper aliases and provides methods to map model attributes to their equivalent fields.

Type Configuration

auto_suffix_input_objects
string
default:"'Input'"
Suffix added automatically to all Input type objects. Prevents situations like PointInputInput. Change this if your inputs have a different suffix.
allow_string_as_enum_input
boolean
default:"false"
Set if the server should allow strings to be used as input for ENUM inputs. Operations will support quotes for ENUM values embedded in documents (heredoc won’t be accepted).

Schema Settings

enable_introspection
boolean
default:"false"
Introspection is disabled by default. Recommended to only use introspection during development and tests, never in production. Can also be set per schema.
schema_type_names
Hash
Names of the schema/operations types. The single underscore prefix prevents conflicts with application objects named Subscription, Query, etc.

Response Format

enable_string_collector
boolean
default:"true"
For performance purposes, this gem implements a JsonCollector. Disable this if you prefer standard hash-to-string serialization provided by ActiveSupport. Can also be set per Schema.
default_response_format
symbol
default:":string"
Default expected output type of GraphQL requests. String combined with enable_string_collector has the best performance. On the console, automatically shifts to Hash. Can also be set per Schema.
encode_with_active_support
boolean
default:"false"
Specifies if operation results should be encoded with ActiveSupport::JSON#encode instead of the default JSON#generate.

Callbacks

callback_inject_arguments
boolean
default:"true"
Enable the ability of a callback to inject arguments dynamically into the calling method.
callback_inject_named_arguments
boolean
default:"true"
Enable the ability of a callback to inject named arguments dynamically into the calling method.

Import & I18n

silence_import_warnings
boolean
default:"false"
When importing fields from modules or other objects, a warning is displayed for elements that couldn’t be correctly imported. Change this to silence such warnings.
enable_i18n_descriptions
boolean
default:"false"
Enable defining descriptions of any object, field, or argument using I18n. Recommended for multi-language documentation.
i18n_scopes
Array<string>
List of scopes used to locate I18n descriptions. Supports interpolation with namespace, kind, parent, and name variables.

Request Strategies

request_strategies
Array<string>
List of execution strategies. Applications can add their own by appending a class, preferably as a string. Can also be set per Schema.

Sources & Providers

sources
Array<string>
default:"['Rails::GraphQL::Source::ActiveRecordSource']"
List of all possible ruby-to-graphql compatible sources.
subscription_providers
Array<string>
List of all available subscription providers.
default_subscription_provider
string
Default subscription provider for all schemas. Can also be set per Schema.
default_subscription_broadcastable
boolean
default:"nil"
Default value for fields about their ability to be broadcasted. Can also be set per Schema.

Known Dependencies

known_dependencies
Hash
List of known dependencies that can be requested and included in any Schema. Best place for other gems to add their own resources and allow users to enable them.

Input Parsing

literal_input_parser
Method
default:"JSON.method(:parse)"
Method used to parse literal input values when provided as Hash. JSON.parse only supports keys wrapped in quotes. Use Psych.method(:safe_load) to support keys without quotes (closer to YAML). Can assign a proc to parse values any other way.
params_mapping
Hash
default:"{ query: 'query', variables: 'variables', ... }"
Mapping for internal parameters and where they should be taken from. Supports nested values using dot notation.

Logger

Access the GraphQL logger:
Rails::GraphQL.logger
Returns a tagged logger (defaults to ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT))). Configure with config.logger.

Build docs developers (and LLMs) love