Overview
TheRails::GraphQL::Schema class is the core representation of a GraphQL schema. Each schema is associated with a single namespace and manages QueryFields, Mutations, and Subscriptions.
Inherits from: Rails::GraphQL::Type
Includes:
ActiveSupport::ConfigurableActiveSupport::RescuableHelpers::Instantiable
Helpers::WithSchemaFieldsHelpers::WithDirectivesHelpers::WithGlobalIDHelpers::RegisterableGraphQL::Introspection
Class Methods
find
Find a schema associated with a namespace (soft mode).The namespace to search for
Schema or nil
find!
Find a schema associated with a namespace. Raises an exception if not found.The namespace to search for
Schema
Raises: NameError if schema not found
namespace
Get or set the namespace for the schema.The namespace to assign
Optional module to associate with the namespace
Symbol - The current namespace (defaults to :base)
types
Find all types available for the current schema.The base class to filter types by
Optional block to iterate over types
find_type
Find a type associated with the schema.The type to find
Additional options (base_class, namespaces)
nil
find_type!
Find a type associated with the schema. Raises an exception if not found.The type to find
find_directive!
Find a directive associated with the schema.The directive to find
request
Create a new request instance for this schema. Returns:Rails::GraphQL::Request
execute
Shortcut to execute a GraphQL request.Arguments passed to the request
Additional execution options
perform
validate
Validate the schema. Only runs if not already validated.validate!
Force validation of the schema.valid?
Check if the schema has been validated. Returns:Boolean
Subscription Methods
subscription_provider
Return the subscription provider for the current schema. Returns: Subscription provider instanceadd_subscriptions
Add new subscriptions using provided request subscription objects.Request subscription objects to add
remove_subscriptions
Remove subscriptions by their subscription IDs.Subscription IDs to remove
accepts_subscription?
Check if the given operation can be subscribed to.The operation to check
Boolean
subscription_id_for
Generate a subscription ID. By default, produces a random UUID. Returns:String - UUID
Cache Methods
cached?
Check if a value exists in the schema cache.Cache key name
Cache options
Boolean
read_from_cache
Read a value from the schema cache.Cache key name
nil
write_on_cache
Write a value to the schema cache.Cache key name
Value to cache
Cache options
fetch_from_cache
Fetch a value from cache, executing the block if not found.Cache key name
delete_from_cache
Delete a value from the schema cache.Cache key name
Type Creation Methods
create_type
Create a new type dynamically without defining a separate class.Name of the type
Base type (e.g., :Object, :Interface)
Additional type options
Configuration block
source
Create a single source type.The source object/model
Superclass for the source
Whether to build immediately
sources
Create multiple source types of the same base type.List of source objects
Base type for all sources
Whether to build immediately
Loading Methods
load_directory
Load all files in a directory as dependencies.Directory path
Whether to load recursively
load_current_directory
load_dependencies
Load a list of known dependencies.Type of dependencies (:directive, :source, etc.)
List of dependencies to load
load_directives
Load directive dependencies.List of directives to load
load_sources
Load source dependencies.List of sources to load
Whether to build sources immediately
Configuration Options
Introspection
gql_name
The GraphQL name for schemas is always__Schema.
Returns: String
graphql_name
kind
The kind of object, always:schema.
Returns: Symbol
to_sym
to_gql
Describe the schema as a GraphQL SDL string.Options for SDL generation
String - GraphQL SDL