Module: GraphQL::Schema::Member::HasArguments::ArgumentObjectLoader Private

Included in:
InputObject
Defined in:
lib/graphql/schema/member/has_arguments.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Instance Method Details

#load_application_object(argument, lookup_as_type, id, context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/graphql/schema/member/has_arguments.rb', line 162

def load_application_object(argument, lookup_as_type, id, context)
  # See if any object can be found for this ID
  if id.nil?
    return nil
  end
  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

#load_application_object_failed(err) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



205
206
207
# File 'lib/graphql/schema/member/has_arguments.rb', line 205

def load_application_object_failed(err)
  raise err
end

#object_from_id(type, id, context) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Look up the corresponding object for a provided ID. By default, it uses Relay-style GraphQL::Schema.object_from_id, override this to find objects another way.

Parameters:

  • type (Class, Module)

    A GraphQL type definition

  • id (String)

    A client-provided to look up

  • context (GraphQL::Query::Context)

    the current context



158
159
160
# File 'lib/graphql/schema/member/has_arguments.rb', line 158

def object_from_id(type, id, context)
  context.schema.object_from_id(id, context)
end