Overview
Source is an abstract object that can contain fields, objects, and information that are delivered to the relative schemas throughout proxies, ensuring that it still keeps the main ownership of the objects. Sources are closely related to objects, meaning they are type-based. They generate GraphQL objects, inputs, queries, mutations, and subscriptions based on configuration.Class Methods
find_for!(object)
Find a source for a given object. Raises an exception if none is found.The class or class name to find a source for
The source class that can handle the given object
find_for(object)
Find the first source that can handle the given object using the list of base sources.The class or class name to find a source for
The source class that can handle the given object, or nil if not found
step(hook_name, unshift: false, &block)
Add a new description hook. You can usethrow :skip to skip parent hooks. If the class is already built, the hook executes immediately.
The name of the hook to execute (must be one of: start, object, input, query, mutation, subscription)
Add the hook at the beginning of the list (executes last)
The block to execute for this hook
attach_fields!(type = :all, from = self)
Attach all defined schema fields into the schemas using the namespaces configured for the source.The type of fields to attach (object, input, query, mutation, subscription, or :all)
The source to attach fields from
schemas
Find all the schemas associated with the configured namespaces.Array of schema objects
skip(*names)
Create hooks that throw a done action, preventing any parent hooks from executing.Names of hooks to skip
override(hook_name, &block)
Shortcut to skip a hook and then define a new implementation.The hook to override
The new implementation
disable(*names)
Disable specific hooks by removing them from hook_names.Names of hooks to disable
enable(*names)
Enable additional hooks by adding them to hook_names.Names of hooks to enable
skip_fields!(*list)
Add one or more fields to the list of fields that need to be ignored in all places.Field names to skip (converts to underscore)
skip_field?(name, on:)
Check if a given field name should be skipped on the given type.The field name to check
The type context (:object, :input, :query, etc.)
True if the field should be skipped
Hooks
Sources use a hook-based system to define their schema structure. The default hooks execute in this order:- start - Initial setup and configuration
- object - Define fields for the GraphQL object type
- input - Define fields for the GraphQL input type
- query - Define query fields
- mutation - Define mutation fields
- subscription - Define subscription fields
Using Hooks
Configuration
Class Attributes
If true, generates a new source describer. Non-abstract classes inherited from it will be described by this abstraction.
List of hook names used while describing a new source. Sets the order of execution.
Protected Methods
find_type!(type, **xargs)
Find a given type on the same namespaces of the source. Raises an exception if the type cannot be found.The type to find
Additional options passed to the type map
skip_from(source, *fields)
Add fields to be skipped on the given source as the segment.The source type to skip fields from
Field names to skip
Delegated Methods
The following methods are delegated to the object:field- Define a field on the objectproxy_field- Define a proxied fieldoverwrite_field- Overwrite an existing fieldfield?- Check if a field existsfield_names- Get all field namesgql_name- Get the GraphQL name