Table of Contents

Handbook

Directory Structure

/ app
  / graphql
    / directives
    / enums
    / fields
    / inputs
    / interfaces
    / mutations
    / object
    / queries
    / scalars
    / sources
    / subscriptions
    / unions
    - app_schema.rb

GraphQL Module Shortcuts

List of all Shortcuts
# Classes
GraphQL::CacheKey           # Rails::GraphQL::CacheKey
GraphQL::Channel            # Rails::GraphQL::Channel
GraphQL::Controller         # Rails::GraphQL::Controller
GraphQL::Directive          # Rails::GraphQL::Directive
GraphQL::GlobalID           # Rails::GraphQL::GlobalID
GraphQL::Request            # Rails::GraphQL::Request
GraphQL::Schema             # Rails::GraphQL::Schema
GraphQL::Source             # Rails::GraphQL::Source
GraphQL::Type               # Rails::GraphQL::Type

GraphQL::Field:             # Rails::GraphQL::Alternative::Field
GraphQL::Query              # Rails::GraphQL::Alternative::Query
GraphQL::Mutation           # Rails::GraphQL::Alternative::Mutation
GraphQL::Subscription       # Rails::GraphQL::Alternative::Subscription

GraphQL::FieldSet           # Rails::GraphQL::Alternative::FieldSet
GraphQL::QuerySet           # Rails::GraphQL::Alternative::QuerySet
GraphQL::MutationSet        # Rails::GraphQL::Alternative::MutationSet
GraphQL::SubscriptionSet    # Rails::GraphQL::Alternative::SubscriptionSet

GraphQL::Enum               # Rails::GraphQL::Type::Enum
GraphQL::Input              # Rails::GraphQL::Type::Input
GraphQL::Interface          # Rails::GraphQL::Type::Interface
GraphQL::Object             # Rails::GraphQL::Type::Object
GraphQL::Scalar             # Rails::GraphQL::Type::Scalar
GraphQL::Union              # Rails::GraphQL::Type::Union

GraphQL::BaseSource         # Rails::GraphQL::Source::BaseSource
GraphQL::ActiveRecordSource # Rails::GraphQL::Source::ActiveRecordSource
GraphQL::ARSource           # Rails::GraphQL::Source::ActiveRecordSource

# Directives
GraphQL::DeprecatedDirective()
# Rails::GraphQL::Directive::DeprecatedDirective.new()
GraphQL::IncludeDirective()
# Rails::GraphQL::Directive::IncludeDirective.new()
GraphQL::SkipDirective()
# Rails::GraphQL::Directive::SkipDirective.new()
GraphQL::SpecifiedByDirective()
# Rails::GraphQL::Directive::SpecifiedByDirective.new()

# Methods
GraphQL.add_dependencies       # Rails::GraphQL.add_dependencies
GraphQL.configure              # Rails::GraphQL.configure
GraphQL.config                 # Rails::GraphQL.config
GraphQL.to_gql                 # Rails::GraphQL.to_gql
GraphQL.to_graphql             # Rails::GraphQL.to_graphql
GraphQL.type_map               # Rails::GraphQL.type_map
GraphQL.request                # Rails::GraphQL::Request.new
GraphQL.execute                # Rails::GraphQL::Request.execute
GraphQL.perform                # Rails::GraphQL::Request.execute
GraphQL.compile                # Rails::GraphQL::Request.compile
GraphQL.valid?                 # Rails::GraphQL::Request.valid?

Introspection Query

Introspection Query
query IntrospectionQuery {
  __schema {
    queryType { name }
    mutationType { name }
    subscriptionType { name }
    types {
      ...FullType
    }
    directives {
      name
      description
      locations
      args {
        ...InputValue
      }
      isRepeatable
    }
  }
}

fragment FullType on __Type {
  kind
  name
  description
  specifiedByURL
  fields(includeDeprecated: true) {
    name
    description
    args {
      ...InputValue
    }
    type {
      ...TypeRef
    }
    isDeprecated
    deprecationReason
  }
  inputFields {
    ...InputValue
  }
  interfaces {
    ...TypeRef
  }
  enumValues(includeDeprecated: true) {
    name
    description
    isDeprecated
    deprecationReason
  }
  possibleTypes {
    ...TypeRef
  }
}

fragment InputValue on __InputValue {
  name
  description
  type { ...TypeRef }
  defaultValue
}

fragment TypeRef on __Type {
  kind
  name
  ofType {
    kind
    name
    ofType {
      kind
      name
      ofType {
        kind
        name
        ofType {
          kind
          name
          ofType {
            kind
            name
            ofType {
              kind
              name
              ofType {
                kind
                name
              }
            }
          }
        }
      }
    }
  }
}

Fresh Schema

Introspection Schema
schema {
  query: _Query
}

scalar Boolean

scalar Float

scalar ID

scalar Int

scalar String

enum __DirectiveLocation {
  QUERY
  MUTATION
  SUBSCRIPTION
  FIELD
  FRAGMENT_DEFINITION
  FRAGMENT_SPREAD
  INLINE_FRAGMENT
  SCHEMA
  SCALAR
  OBJECT
  FIELD_DEFINITION
  ARGUMENT_DEFINITION
  INTERFACE
  UNION
  ENUM
  ENUM_VALUE
  INPUT_OBJECT
  INPUT_FIELD_DEFINITION
}

enum __TypeKind {
  SCALAR
  OBJECT
  INTERFACE
  UNION
  ENUM
  INPUT_OBJECT
  LIST
  NON_NULL
}

type _Query {
  __schema: __Schema!
  __type(name: String!): __Type
}

type __Directive {
  args: [__InputValue!]!
  description: String
  isRepeatable: Boolean!
  locations: [__DirectiveLocation!]!
  name: String!
}

type __EnumValue {
  deprecationReason: String
  description: String
  isDeprecated: Boolean!
  name: String!
}

type __Field {
  args: [__InputValue!]!
  deprecationReason: String
  description: String
  isDeprecated: Boolean!
  name: String!
  type: __Type!
}

type __InputValue {
  defaultValue: String
  description: String
  name: String!
  type: __Type!
}

type __Schema {
  directives: [__Directive!]!
  mutationType: __Type
  queryType: __Type!
  subscriptionType: __Type
  types: [__Type!]!
}

type __Type {
  description: String
  enumValues(includeDeprecated: Boolean = false): [__EnumValue!]
  fields(includeDeprecated: Boolean = false): [__Field!]
  inputFields: [__InputValue!]
  interfaces: [__Type!]
  kind: __TypeKind!
  name: String
  ofType: __Type
  possibleTypes: [__Type!]
  specifiedByURL: String
}

directive @deprecated(reason: String) on FIELD_DEFINITION | ENUM_VALUE

directive @include(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

directive @skip(if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT

directive @specifiedBy(url: String!) on SCALAR

Available Scalars

# Class                                 # Name and aliases
GraphQL::Scalar::IdScalar               [:id, 'ID']
GraphQL::Scalar::IntScalar              [:int, :integer, 'Int']
GraphQL::Scalar::FloatScalar            [:float, 'Float']
GraphQL::Scalar::StringScalar           [:string, 'String']
GraphQL::Scalar::BooleanScalar          [:boolean, :bool, 'Boolean']
# Needs to be loaded as dependencies
GraphQL::Scalar::AnyScalar              [:any, 'Any']
GraphQL::Scalar::BigintScalar           [:bigint, 'Bigint']
GraphQL::Scalar::BinaryScalar           [:binary, :file, 'Binary']
GraphQL::Scalar::DateScalar             [:date, 'Date']
GraphQL::Scalar::DateTimeScalar         [:date_time, :datetime, 'DateTime']
GraphQL::Scalar::DecimalScalar          [:decimal, 'Decimal']
GraphQL::Scalar::JsonScalar             [:json, 'Json', 'JSON']
GraphQL::Scalar::TimeScalar             [:time, 'Time']

Loading Dependencies

# Known dependencies
load_scalars :bigint, :date_time

# Local dependencies
load_directory 'sources'
load_current_directory

# Importing Fields
import_into :query, GraphQL::Queries::Sample
import_all GraphQL::Queries

Schema Fields

# Adding fields            # Typename
query_fields do            # _Query
end
mutation_fields do         # _Mutation
end
subscription_fields do     # _Subscription
end

Field List Methods

# Single form                      Multi form
# The List
#   Accessing
fields                             fields_for(:query)
#   Checking
fields?                            fields_for?(:query)
# Adding Fields
#   Regular
field(:name, :string)              add_field(:query, :name, :string)
#   Safe
safe_field(:name, :string)         safe_add_field(:query, :name, :string)
#   Proxy
proxy_field(other)                 add_proxy_field(:query, other)
#   Importing
#     From Class
import(GraphQL::WithName)          import_into(:query, GraphQL::Queries::Users)
#     From Module
import_all(GraphQL::UserFields)    import_all_into(:query, GraphQL::Queries)
                                   import_all(GraphQL::Queries)
# Changing
#   Simple
change_field(:name, null: true)    change_field(:query, :name, null: true)
#   Block Only
configure_field(:name) { }         configure_field(:query, :name) { }
#   Disable Fields
disable_fields(:field1, :field2)   disable_fields(:query, :field1, :field2)
#   Enable Fields
enable_fields(:field1, :field2)    enable_fields(:query, :field1, :field2)
# Searching
#   Checking
has_field?(:first_name)            has_field?(:query, :first_name)
has_field?('firstName')            has_field?(:query, 'firstName')
#   Finding
find_field(:first_name)            find_field(:query, :first_name)
find_field('firstName')            find_field(:query, 'firstName')
self[:first_name]                  self[:query, :first_name]
self['firstName']                  self[:query, 'firstName']
#   Force Finding
find_field!(:first_name)           find_field!(:query, :first_name)
find_field!('firstName')           find_field!(:query, 'firstName')

Event Accessors

data                      # Any additional data provided to trigger
event                     # The instance of the event
event_name                # The name of the event
last_result               # The last result of the event chain
object                    # The object calling the trigger
source                    # The source of the event

parameter(name)           # Same as try(name) || data[name]
[name]                    # Same as above
parameter?(name)          # Same as respond_to?(name) || data.key?(name)
key?(name)                # Same as above
stop(*result)             # Stop running the event and return *result

Request Event Accessors

context                   # The request context
current                   # The current value in the data stack
current_value             # Same as above
errors                    # The request errors
extensions                # The request extensions
field                     # The current field being resolved
index                     # The index of the current array element
memo                      # The operation memo
operation                 # The operation component being resolved
prepared_data             # The prepared data of a field, when provided
request                   # The request itself
resolver                  # The request data stack
schema                    # The schema of the request
strategy                  # The strategy of the request
subscription_provider     # The subscription provider of the schema

argument(name)            # Get the value of an argument sent to the field
arg(name)                 # Same as above