Method: GraphQL::Schema::Field#authorized?

Defined in:
lib/graphql/schema/field.rb

#authorized?(object, args, context) ⇒ Boolean

Returns:

  • (Boolean)


628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
# File 'lib/graphql/schema/field.rb', line 628

def authorized?(object, args, context)
  if @resolver_class
    # The resolver _instance_ will check itself during `resolve()`
    @resolver_class.authorized?(object, context)
  else
    if args.size > 0
      if (arg_values = context[:current_arguments])
        # ^^ that's provided by the interpreter at runtime, and includes info about whether the default value was used or not.
        using_arg_values = true
        arg_values = arg_values.argument_values
      else
        arg_values = args
        using_arg_values = false
      end

      args = context.types.arguments(self)
      args.each do |arg|
        arg_key = arg.keyword
        if arg_values.key?(arg_key)
          arg_value = arg_values[arg_key]
          if using_arg_values
            if arg_value.default_used?
              # pass -- no auth required for default used
              next
            else
              application_arg_value = arg_value.value
              if application_arg_value.is_a?(GraphQL::Execution::Interpreter::Arguments)
                application_arg_value.keyword_arguments
              end
            end
          else
            application_arg_value = arg_value
          end

          if !arg.authorized?(object, application_arg_value, context)
            return false
          end
        end
      end
    end
    true
  end
end