Table of Contents
- version
- cache
- cache_fallback
- cache_prefix
- paths
- verbose_logs
- omit_parameters
- filter_parameters
- ar_adapters
- auto_suffix_input_objects
- allow_string_as_enum_input
- enable_introspection
- schema_type_names
- enable_string_collector
- default_response_format
- encode_with_active_support
- callback_inject_arguments
- callback_inject_named_arguments
- silence_import_warnings
- enable_i18n_descriptions
- i18n_scopes
- request_strategies
- sources
- subscription_providers
- default_subscription_provider
- default_subscription_broadcastable
- known_dependencies
- literal_input_parser
Settings
Several features of this gem can be changed to better adapt to your needs. You can change any of the items listed here as follows:
# config/initializer/graphql.rb
Rails::GraphQL.configure do |gql|
gql.version = 'ABCDEFG'
end
version
This helps to keep track of when things were cached and registered. Cached objects with mismatching versions need to be upgraded or simply reloaded. An excellent way to use this is to set it to the commit hash. TypePap will always use only the first 8 characters for simplicity.
Default: nil
cache
The instance responsible for caching all the information generated by
requests and all the other components. Manually setting this property
means that the object in it complies with ActiveSupport::Cache::Store
.
This will map automatically to Rails.cache
if kept as nil
. This can
also be set per Schema.
Default: nil
cache_fallback
If Rails cache is not properly defined or just set to use a NullStore, this fallback will set itself up with a memory store because cache is crucial, especially for subscriptions.
Default:
-> { ::ActiveSupport::Cache::MemoryStore.new(max_prune_time: nil) }
cache_prefix
This is the prefix key of all the cache entries for the GraphQL cached things.
Default: 'graphql/'
paths
The list of nested paths inside of the GraphQL folder that does not require to be in their own namespace.
Default:
[
"directives", "fields", "sources", "enums", "inputs",
"interfaces", "object", "scalars", "unions",
].to_set
verbose_logs
This is very similar to ActiveRecord
verbose logs, which simply show the
path of the file that started a GraphQL request.
Default: true
omit_parameters
The list of parameters to omit from the logger when running a GraphQL request. Those values are displayed better in the internal runtime logger controller.
Default: ["query", "operationName", "operation_name", "variables", "graphql"]
filter_parameters
Identical to the one available on a Rails application, but exclusive for GraphQL operations. The list of parameters to display as filtered in the logs. When it is nil, it will use the same as the Rails application.
Default: nil
ar_adapters
A list of all ActiveRecord
adapters supported. When an adapter is
supported, it will map the database types into GraphQL types using proper
aliases. Plus, it will have the method to map models attributes to their
equivalent fields.
Default:
{
'Mysql2' => { key: :mysql, path: "#{__dir__}/adapters/mysql_adapter" },
'PostgreSQL' => { key: :pg, path: "#{__dir__}/adapters/pg_adapter" },
'SQLite' => { key: :sqlite, path: "#{__dir__}/adapters/sqlite_adapter" },
}
auto_suffix_input_objects
The suffix that is added automatically to all the Input type objects. This
prevents situations like PointInputInput
. If your inputs have a
different suffix, change this value to it.
Default: 'Input'
allow_string_as_enum_input
Set if the server should allow strings be used as input for ENUM inputs. It means that operations will support quotes for ENUM values embedded in the documents.
Default: false
enable_introspection
Introspection is enabled by default. It is recommended to only use introspection during development and tests, never in production. This can also be set per Schema.
Default: false
schema_type_names
Define the names of the schema/operations types. The single _
is a
suggestion. In an application that has a Subscription object, it will
prevent the conflict. Plus, it is easy to spot that it is something
internal. This can also be set per Schema.
Default:
{
query: '_Query',
mutation: '_Mutation',
subscription: '_Subscription',
}
enable_string_collector
For performance purposes, this gem implements a JsonCollector. You can
disable this option if you prefer to use the standard hash-to-string
serialization provided by ActiveSupport
. This can also be set per
Schema.
Default: true
default_response_format
Set what is de default expected output type of GraphQL requests. String combined with the previous setting has the best performance. On the console, it will automatically shift to Hash. This can also be set per Schema.
Default: :string
encode_with_active_support
Specifies if the results of operations should be encoded with
ActiveSupport::JSON#encode
instead of the default JSON#generate
.
Default: false
callback_inject_arguments
Enable the ability of a callback to inject arguments dynamically into the calling method.
Default: true
callback_inject_named_arguments
Enable the ability of a callback to inject named arguments dynamically into the calling method.
Default: true
silence_import_warnings
When importing fields from modules or other objects, a warning is displayed for any given element that was not able to be correctly imported. You can silence such warnings by changing this option.
Default: false
enable_i18n_descriptions
Enable the ability to define the description of any object, field, or argument using I18n. It is recommended for multi-language documentation.
Default: true
i18n_scopes
The list of scopes that will be used to locate the descriptions.
Default:
[
'graphql.%{namespace}.%{kind}.%{parent}.%{name}',
'graphql.%{namespace}.%{kind}.%{name}',
'graphql.%{namespace}.%{name}',
'graphql.%{kind}.%{parent}.%{name}',
'graphql.%{kind}.%{name}',
'graphql.%{name}',
]
request_strategies
A list of execution strategies. Each application can add its own by appending a class, preferably as a string, in this list. This can also be set per Schema.
Default:
[
'Rails::GraphQL::Request::Strategy::MultiQueryStrategy',
'Rails::GraphQL::Request::Strategy::SequencedStrategy',
]
sources
A list of all possible ruby-to-graphql compatible sources.
Default:
[
'Rails::GraphQL::Source::ActiveRecordSource',
]
subscription_providers
A list of all available subscription providers.
Default:
[
'Rails::GraphQL::Subscription::Provider::ActionCable',
]
default_subscription_provider
The default subscription provider for all schemas. This can also be set per Schema.
Default: 'Rails::GraphQL::Subscription::Provider::ActionCable'
default_subscription_broadcastable
The default value for fields about their ability to be broadcasted. This can also be set per Schema.
Default: nil
known_dependencies
A list of known dependencies that can be requested and included in any Schema. This is the best place for other gems to add their own resources and allow users to enable them.
Default:
{
scalar: {
any: "#{__dir__}/type/scalar/any_scalar",
bigint: "#{__dir__}/type/scalar/bigint_scalar",
binary: "#{__dir__}/type/scalar/binary_scalar",
date_time: "#{__dir__}/type/scalar/date_time_scalar",
date: "#{__dir__}/type/scalar/date_scalar",
decimal: "#{__dir__}/type/scalar/decimal_scalar",
time: "#{__dir__}/type/scalar/time_scalar",
json: "#{__dir__}/type/scalar/json_scalar",
},
enum: {},
input: {},
interface: {},
object: {},
union: {},
directive: {},
}
literal_input_parser
Important This a temporary.
A future version of the Parser will address this.
The method that should be used to parse literal input values when they are
provided as Hash. JSON.parse
only supports keys wrapped in quotes. You
can use Psych.method(:safe_load)
to support keys without quotes, which
behaves closer to YAML. The received value is ensured to be wrapped in
{}
. If that produces unexpected results, you can assign a proc and then
parse the value in any other way.
Default: JSON.method(:parse)