Overview
TheRails::GraphQL::Field class represents fields in GraphQL types. Fields can be input fields (arguments) or output fields (on objects, interfaces, queries, mutations, subscriptions).
Namespace: Rails::GraphQL
Includes:
Helpers::WithDirectivesHelpers::WithDescription
InputField- Fields on input objectsOutputField- Fields on output typesMutationField- Fields for mutationsSubscriptionField- Fields for subscriptions
Constructor
initialize
The name of the field
The type that owns this field
Whether the field value can be null
Whether the field returns an array
Whether array items can be null (only applies if array: true)
Shortcut for
null: false, nullable: false, array: trueWhether the field is enabled
Opposite of enabled (overrides enabled if true)
List of directives to apply to the field
Field description
Field description (alias for desc)
Name of the method to call on the object
Configuration block
Instance Attributes
The Ruby-style name of the field (underscore_case)
The GraphQL-style name of the field (camelCase)
The type that owns this field
to_sym→namegid_base_class→ownerproxied_owner→owner
Class Methods
input_type?
Check if this field class is valid as an input type. Returns:Boolean
output_type?
Check if this field class is valid as an output type. Returns:Boolean
leaf_type?
Check if this field is considered a leaf output. Returns:Boolean
proxy?
Check if the field is a proxy kind of field. Returns:Boolean
mutation?
Check if the field is associated with a mutation. Returns:Boolean
subscription?
Check if the field is associated with a subscription. Returns:Boolean
Instance Methods
configure
Apply additional configurations using a block.Configuration block
self
apply_changes
Apply a controlled set of changes to the field.Update nullable setting
Update null setting
Disable the field
Enable the field
Update description
Update description
Configuration block
method_name
Get the name of the method used to retrieve field data. Returns:Symbol
all_owners
Return all owners of the field (always returns single-item array). Returns:Array<Type>
State Management Methods
enable!
Mark the field as enabled.disable!
Mark the field as disabled.required!
Mark the field as non-nullable (set null to false).required_items!
Mark array items as non-nullable (set nullable to false).Query Methods
null?
Check if the field value can be null. Returns:Boolean
required?
Check if the field value cannot be null. Returns:Boolean
array?
Check if the field returns an array. Returns:Boolean
nullable?
Check if array items can be null. Returns:Boolean
enabled?
Check if the field is enabled. Returns:Boolean
disabled?
Check if the field is disabled. Returns:Boolean
internal?
Check if the field is internal (name starts with__).
Returns: Boolean
valid_input?
Check if the field is valid for input. Override in subclasses. Returns:Boolean
valid_output?
Check if the field is valid for output. Override in subclasses. Returns:Boolean
valid?
Check if the given value is valid (uses valid_input? or valid_output? based on field type).Value to validate
Boolean
Serialization Methods
to_json
Transform the given value to its JSON string representation. Must be overridden by subclasses.Value to serialize
String
Raises: NotImplementedError if not overridden
as_json
Turn the given value into a JSON-compatible object. Must be overridden by subclasses.Value to serialize
NotImplementedError if not overridden
deserialize
Convert user input into a Ruby object. Must be overridden by subclasses.Input value to deserialize
NotImplementedError if not overridden
Validation
validate!
Validate the field definition. Raises:NameError if the field name is invalid (starts with __ but is not internal)
Proxy and Comparison
to_proxy
Create a proxy of the current field.Arguments for proxy
Additional options
Configuration block
Field with ProxiedField module
=~
Check if another field is equivalent.Field to compare with
Boolean
Description
description
Get the description of the field.Namespace for the description
String