Module: GraphQL

Defined in:
lib/rails/graphql/shortcuts.rb,
lib/generators/graphql/schema_generator.rb,
lib/generators/graphql/channel_generator.rb,
lib/generators/graphql/install_generator.rb,
lib/generators/graphql/controller_generator.rb,
lib/rails/graphql/railties/app/base_channel.rb,
lib/rails/graphql/railties/app/base_controller.rb

Overview

This exposed module allows some shortcuts while working outside of the gem

Defined Under Namespace

Modules: Generators

Constant Summary collapse

CONST_SHORTCUTS =

List of constant shortcuts, as string to not trigger autoload

{
  CacheKey:           '::Rails::GraphQL::CacheKey',
  Channel:            '::Rails::GraphQL::Channel',
  Controller:         '::Rails::GraphQL::Controller',
  Directive:          '::Rails::GraphQL::Directive',
  GlobalID:           '::Rails::GraphQL::GlobalID',
  Request:            '::Rails::GraphQL::Request',
  Schema:             '::Rails::GraphQL::Schema',
  Source:             '::Rails::GraphQL::Source',
  Type:               '::Rails::GraphQL::Type',

  Field:              '::Rails::GraphQL::Alternative::Field',
  Query:              '::Rails::GraphQL::Alternative::Query',
  Mutation:           '::Rails::GraphQL::Alternative::Mutation',
  Subscription:       '::Rails::GraphQL::Alternative::Subscription',

  FieldSet:           '::Rails::GraphQL::Alternative::FieldSet',
  QuerySet:           '::Rails::GraphQL::Alternative::QuerySet',
  MutationSet:        '::Rails::GraphQL::Alternative::MutationSet',
  SubscriptionSet:    '::Rails::GraphQL::Alternative::SubscriptionSet',

  Enum:               '::Rails::GraphQL::Type::Enum',
  Input:              '::Rails::GraphQL::Type::Input',
  Interface:          '::Rails::GraphQL::Type::Interface',
  Object:             '::Rails::GraphQL::Type::Object',
  Scalar:             '::Rails::GraphQL::Type::Scalar',
  Union:              '::Rails::GraphQL::Type::Union',

  BaseSource:         '::Rails::GraphQL::Source::BaseSource',
  ActiveRecordSource: '::Rails::GraphQL::Source::ActiveRecordSource',
}.freeze
DIRECTIVE_SHORTCUTS =

List of directive shortcuts, which are basically the shortcut of another shortcut to instantiate a directive.

Examples

GraphQL::DeprecatedDirective(...)
# => Rails::GraphQL::Directive::DeprecatedDirective(...)

Rails::GraphQL::Directive::DeprecatedDirective(...)
# => Rails::GraphQL::Directive::DeprecatedDirective.new(...)
%i[DeprecatedDirective IncludeDirective SkipDirective
SpecifiedByDirective].freeze
BaseChannel =
Class.new(base) do
  include ::Rails::GraphQL::Channel
end
BaseController =
Class.new(base) do
  include ::Rails::GraphQL::Controller

  skip_before_action :verify_authenticity_token
end

Class Method Summary collapse

Class Method Details

.compile(*args, **xargs) ⇒ Object

See Request



72
73
74
# File 'lib/rails/graphql/shortcuts.rb', line 72

def compile(*args, **xargs)
  Rails::GraphQL::Request.compile(*args, **xargs)
end

.const_defined?(name) ⇒ Boolean

Returns:

  • (Boolean)


82
83
84
85
# File 'lib/rails/graphql/shortcuts.rb', line 82

def const_defined?(name, *)
  name = :"ActiveRecord#{name[2..-1]}" if name[0..1] === 'AR'
  CONST_SHORTCUTS.key?(name) || super
end

.const_missing(name) ⇒ Object



88
89
90
91
92
93
# File 'lib/rails/graphql/shortcuts.rb', line 88

def const_missing(name)
  name = :"ActiveRecord#{name[2..-1]}" if name[0..1] === 'AR'
  return resolved[name] if resolved.key?(name)
  return super unless CONST_SHORTCUTS.key?(name)
  resolved[name] = CONST_SHORTCUTS[name].constantize
end

.execute(*args, **xargs) ⇒ Object Also known as: perform

See Request



65
66
67
# File 'lib/rails/graphql/shortcuts.rb', line 65

def execute(*args, **xargs)
  Rails::GraphQL::Request.execute(*args, **xargs)
end

.request(*args, **xargs) ⇒ Object

See Request



60
61
62
# File 'lib/rails/graphql/shortcuts.rb', line 60

def request(*args, **xargs)
  Rails::GraphQL::Request.new(*args, **xargs)
end

.valid?(*args, **xargs) ⇒ Boolean

See Request

Returns:

  • (Boolean)


77
78
79
# File 'lib/rails/graphql/shortcuts.rb', line 77

def valid?(*args, **xargs)
  Rails::GraphQL::Request.valid?(*args, **xargs)
end