Field lists are found in classes containing fields: Interfaces, Inputs, Objects, Sets, Schemas, and Sources. You can use the same methods in both single and multi-schema-based scenarios. Multi-schema-based lists require specifying the type, but when using a block focused on a specific schema type, you can treat it as a single list.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/virtualshield/rails-graphql/llms.txt
Use this file to discover all available pages before exploring further.
When methods differ between single and multi forms, they’re listed as
single / multi.Accessing the List
fields / fields_for
fields(initialize = nil) / fields_for(type, initialize = nil)
Returns the list of fields as a Concurrent::Map with sanitized names as keys and fields as values. The list is only initialized when explicitly requested.
fields? / fields_for?
fields? / fields_for?(type)
Check if the list of fields has been initialized and has items.
Adding Fields
Regular Fields
field(name, type, **settings, &configure_block) / add_field(type, name, type, **settings, &configure_block)
Add a field to the list. Fields must have unique names. Duplicate names raise a DuplicatedError.
Safe Fields
safe_field(name, type, **settings, &configure_block) / safe_add_field(type, name, type, **settings, &configure_block)
Works like regular field addition, but exceptions are already rescued. Best used with Sources.
Proxy Fields
proxy_field(field, alias = nil, **settings, &configure_block) / add_proxy_field(type, field, alias = nil, **settings, &configure_block)
Add a field that proxies to another field. This checks name uniqueness and field compatibility.
Proxy fields is an advanced feature. Read more about proxy fields.
Importing Fields
From Class
import(source) / import_into(type, source)
Import fields from a source into the list as proxies. The source can be an Array, Hash-like object, another object with fields, a Set Alternative, or a Standalone Alternative.
From Module
import_all(module, recursive: false) / import_all_into(type, module, recursive: false)
Import multiple field classes from a module. For every constant found, it calls the import method for classes or recurses for modules when recursive: true.
Modifying Fields
change_field / overwrite_field
change_field(name, **changes, &configure_block)
Modify aspects of your fields, with optional block for additional changes.
configure_field
configure_field(name, &configure_block)
Go straight to the configuration block. Use this when changes only involve adding arguments or directives.
disable_fields / enable_fields
disable_fields(name, *names) / enable_fields(name, *names)
Quick shortcuts to change the enabled status of fields.
Searching Fields
has_field?
has_field?(by)
Check if the list has a field. Accepts the name as a symbol, the GQL name as a string, or another field.
find_field / []
find_field(by) or [by]
Find and return a field. Accepts the name as a symbol, the GQL name as a string, or another field.
find_field!
find_field!(by)
Same as find_field, but raises NotFoundError if the field is not found.
Utility Methods
field_names / field_names_for
field_names(enabled_only = true) / field_names_for(type, enabled_only = true)
Get all GQL names of fields in the list. By default, returns only enabled fields.
enabled_fields / enabled_fields_from
enabled_fields / enabled_fields_from(type)
Returns an Enumerator::Lazy of all enabled fields for performance.
Multi-Schema Shortcuts
The multi-schema-based list provides type-specific methods as syntax sugar.Type-Specific Accessors
{type}_fields
Access the list of fields for a specific type. Supports a block for exclusive interaction. Does not initialize the list on its own.