class GraphQL::Schema::Object

def authorized_new(object, context)

Raises:
  • (GraphQL::UnauthorizedError) - if the user-provided hook returns `false`

Returns:
  • (GraphQL::Schema::Object, GraphQL::Execution::Lazy) -

Parameters:
  • context (GraphQL::Query::Context) --
  • object (Object) -- The thing wrapped by this object
def authorized_new(object, context)
  maybe_lazy_auth_val = context.query.current_trace.authorized(query: context.query, type: self, object: object) do
    begin
      authorized?(object, context)
    rescue GraphQL::UnauthorizedError => err
      context.schema.unauthorized_object(err)
    rescue StandardError => err
      context.query.handle_or_reraise(err)
    end
  end
  auth_val = if context.schema.lazy?(maybe_lazy_auth_val)
    GraphQL::Execution::Lazy.new do
      context.query.current_trace.authorized_lazy(query: context.query, type: self, object: object) do
        context.schema.sync_lazy(maybe_lazy_auth_val)
      end
    end
  else
    maybe_lazy_auth_val
  end
  context.query.after_lazy(auth_val) do |is_authorized|
    if is_authorized
      self.new(object, context)
    else
      # It failed the authorization check, so go to the schema's authorized object hook
      err = GraphQL::UnauthorizedError.new(object: object, type: self, context: context)
      # If a new value was returned, wrap that instead of the original value
      begin
        new_obj = context.schema.unauthorized_object(err)
        if new_obj
          self.new(new_obj, context)
        else
          nil
        end
      end
    end
  end
end

def const_missing(name)

It should help with debugging and bug tracker integrations.
Set up a type-specific invalid null error to use when this object's non-null fields wrongly return `nil`.
def const_missing(name)
  if name == :InvalidNullError
    custom_err_class = GraphQL::InvalidNullError.subclass_for(self)
    const_set(:InvalidNullError, custom_err_class)
    custom_err_class
  else
    super
  end
end

def dataloader

Returns:
  • (GraphQL::Dataloader) -
def dataloader
  context.dataloader
end

def initialize(object, context)

def initialize(object, context)
  @object = object
  @context = context
end

def kind

def kind
  GraphQL::TypeKinds::OBJECT
end

def raw_value(obj)

without any further handling by GraphQL.
Call this in a field method to return a value that should be returned to the client
def raw_value(obj)
  GraphQL::Execution::Interpreter::RawValue.new(obj)
end

def scoped_new(object, context)

def scoped_new(object, context)
  self.new(object, context)
end

def wrap(object, context)

This is called by the runtime to return an object to call methods on.
def wrap(object, context)
  authorized_new(object, context)
end

def wrap_scoped(object, context)

def wrap_scoped(object, context)
  scoped_new(object, context)
end