module GraphQL::Schema::Member::HasArguments::ArgumentObjectLoader
def load_application_object(argument, lookup_as_type, id)
def load_application_object(argument, lookup_as_type, id) # See if any object can be found for this ID loaded_application_object = object_from_id(lookup_as_type, id, context) context.schema.after_lazy(loaded_application_object) do |application_object| if application_object.nil? err = GraphQL::LoadApplicationObjectFailedError.new(argument: argument, id: id, object: application_object) load_application_object_failed(err) end # Double-check that the located object is actually of this type # (Don't want to allow arbitrary access to objects this way) resolved_application_object_type = context.schema.resolve_type(lookup_as_type, application_object, context) context.schema.after_lazy(resolved_application_object_type) do |application_object_type| possible_object_types = context.warden.possible_types(lookup_as_type) if !possible_object_types.include?(application_object_type) err = GraphQL::LoadApplicationObjectFailedError.new(argument: argument, id: id, object: application_object) load_application_object_failed(err) else # This object was loaded successfully # and resolved to the right type, # now apply the `.authorized?` class method if there is one if (class_based_type = application_object_type.type_class) context.schema.after_lazy(class_based_type.authorized?(application_object, context)) do |authed| if authed application_object else raise GraphQL::UnauthorizedError.new( object: application_object, type: class_based_type, context: context, ) end end else application_object end end end end end
def load_application_object_failed(err)
def load_application_object_failed(err) raise err end
def object_from_id(type, id, context)
-
context
(GraphQL::Query::Context
) -- the current context -
id
(String
) -- A client-provided to look up -
type
(Class, Module
) -- A GraphQL type definition
def object_from_id(type, id, context) context.schema.object_from_id(id, context) end