module GraphQL::Rails

Constants

NodeIdentification

Implements globally-unique object IDs for Relay compatibility.

VERSION

Public Class Methods

check_authorization(options = {}) click to toggle source
# File lib/graphql/rails/extensions/cancan.rb, line 12
def self.check_authorization(options = {})
  self.after_filter(options.slice(:only, :except)) do |instance|
    next if instance.instance_variable_defined?(:@authorized)
    next if options[:if] && !instance.send(options[:if])
    next if options[:unless] && instance.send(options[:unless])
    raise 'This operation failed to perform an authorization check'
  end
end
skip_authorization_check(*args) click to toggle source
# File lib/graphql/rails/extensions/cancan.rb, line 21
def self.skip_authorization_check(*args)
  self.before_filter(*args) do |instance|
    instance.instance_variable_set(:@authorized, true)
  end
end

Public Instance Methods

authorize!(*args) click to toggle source
# File lib/graphql/rails/extensions/cancan.rb, line 27
def authorize!(*args)
  begin
    @authorized = true
    current_ability.authorize!(*args)
  rescue ::CanCan::AccessDenied
    raise 'You are not authorized to perform this operation'
  end
end
config() click to toggle source

Configuration for this gem.

# File lib/graphql/rails/config.rb, line 11
def config
  @config ||= OpenStruct.new({
    # Should graphql-ruby be placed into debug mode?
    :debug => ::Rails.env.development?,

    # Should the GraphiQL web interface be served?
    :graphiql => ::Rails.env.development?,

    # Should names be converted to lowerCamelCase per GraphQL convention?
    # For example, should :get_user_tasks become 'getUserTasks'?
    :camel_case => true,

    # Should object IDs be globally unique?
    # This is necessary to conform to the Relay Global Object ID spec.
    :global_ids => true,

    # Maximum nesting for GraphQL queries.
    # Specify nil for unlimited nesting depth.
    :max_depth => 8,

    # Should the following extensions be loaded?
    :mongoid => defined?(::Mongoid),
    :cancan => defined?(::CanCan),
  })
end
configure() { |config| ... } click to toggle source

Yields the configuration object to a block, per convention.

# File lib/graphql/rails/config.rb, line 6
def configure
  yield config
end
current_ability() click to toggle source
# File lib/graphql/rails/extensions/cancan.rb, line 36
def current_ability
  @current_ability ||= ::Ability.new(current_user)
end
current_user() click to toggle source
# File lib/graphql/rails/extensions/cancan.rb, line 40
def current_user
  context[:current_user]
end