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
-
#authorize_application_object(argument, id, context, loaded_application_object) ⇒ Object
private
-
#load_and_authorize_application_object(argument, id, context) ⇒ Object
private
-
#load_application_object(argument, id, context) ⇒ Object
private
-
#load_application_object_failed(err) ⇒ Object
private
-
#object_from_id(type, id, context) ⇒ Object
private
Look up the corresponding object for a provided ID.
Instance Method Details
#authorize_application_object(argument, id, context, loaded_application_object) ⇒ 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.
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/graphql/schema/member/has_arguments.rb', line 351 def (argument, id, context, loaded_application_object) context.query.after_lazy(loaded_application_object) do |application_object| if application_object.nil? err = GraphQL::LoadApplicationObjectFailedError.new(context: context, argument: argument, id: id, object: application_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) if application_object.nil? nil else arg_loads_type = argument.loads maybe_lazy_resolve_type = context.schema.resolve_type(arg_loads_type, application_object, context) context.query.after_lazy(maybe_lazy_resolve_type) do |resolve_type_result| if resolve_type_result.is_a?(Array) && resolve_type_result.size == 2 application_object_type, application_object = resolve_type_result else application_object_type = resolve_type_result # application_object is already assigned end passes_possible_types_check = if context.types.loadable?(arg_loads_type, context) if arg_loads_type.kind.union? # This union is used in `loads:` but not otherwise visible to this query context.types.loadable_possible_types(arg_loads_type, context).include?(application_object_type) else true end else context.types.possible_types(arg_loads_type).include?(application_object_type) end if !passes_possible_types_check err = GraphQL::LoadApplicationObjectFailedError.new(context: context, argument: argument, id: id, object: application_object) application_object = load_application_object_failed(err) end if application_object.nil? nil else # This object was loaded successfully # and resolved to the right type, # now apply the `.authorized?` class method if there is one context.query.after_lazy(application_object_type.(application_object, context)) do |authed| if authed application_object else err = GraphQL::UnauthorizedError.new( object: application_object, type: application_object_type, context: context, ) if self.respond_to?(:unauthorized_object) err.set_backtrace(caller) (err) else raise err end end end end end end end end |
#load_and_authorize_application_object(argument, 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.
346 347 348 349 |
# File 'lib/graphql/schema/member/has_arguments.rb', line 346 def (argument, id, context) loaded_application_object = load_application_object(argument, id, context) (argument, id, context, loaded_application_object) end |
#load_application_object(argument, 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.
338 339 340 341 342 343 344 |
# File 'lib/graphql/schema/member/has_arguments.rb', line 338 def load_application_object(argument, id, context) # See if any object can be found for this ID if id.nil? return nil end object_from_id(argument.loads, id, context) 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.
416 417 418 |
# File 'lib/graphql/schema/member/has_arguments.rb', line 416 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.
334 335 336 |
# File 'lib/graphql/schema/member/has_arguments.rb', line 334 def object_from_id(type, id, context) context.schema.object_from_id(id, context) end |