# frozen_string_literal: truemoduleGraphQLclassSchemaclassArgumentif!String.method_defined?(:-@)usingGraphQL::StringDedupBackportendincludeGraphQL::Schema::Member::CachedGraphQLDefinitionincludeGraphQL::Schema::Member::AcceptsDefinitionincludeGraphQL::Schema::Member::HasPathincludeGraphQL::Schema::Member::HasAstNodeNO_DEFAULT=:__no_default__# @return [String] the GraphQL name for this argument, camelized unless `camelize: false` is providedattr_reader:namealias:graphql_name:name# @return [GraphQL::Schema::Field, Class] The field or input object this argument belongs toattr_reader:owner# @return [Symbol] A method to call to transform this value before sending it to field resolution methodattr_reader:prepare# @return [Symbol] This argument's name in Ruby keyword argumentsattr_reader:keyword# @return [Class, Module, nil] If this argument should load an application object, this is the type of object to loadattr_reader:loads# @return [Boolean] true if a resolver defined this argumentdeffrom_resolver?@from_resolverend# @param arg_name [Symbol]# @param type_expr# @param desc [String]# @param required [Boolean] if true, this argument is non-null; if false, this argument is nullable# @param description [String]# @param default_value [Object]# @param as [Symbol] Override the keyword name when passed to a method# @param prepare [Symbol] A method to call to transform this argument's valuebefore sending it to field resolution# @param camelize [Boolean] if true, the name will be camelized when building the schema# @param from_resolver [Boolean] if true, a Resolver class defined this argument# @param method_access [Boolean] If false, don't build method access on legacy {Query::Arguments} instances.definitialize(arg_name=nil,type_expr=nil,desc=nil,required:,type: nil,name: nil,loads: nil,description: nil,ast_node: nil,default_value: NO_DEFAULT,as: nil,from_resolver: false,camelize: true,prepare: nil,method_access: true,owner:,&definition_block)arg_name||=name@name=-(camelize?Member::BuildType.camelize(arg_name.to_s):arg_name.to_s)@type_expr=type_expr||type@description=desc||description@null=!required@default_value=default_value@owner=owner@as=as@loads=loads@keyword=as||Schema::Member::BuildType.underscore(@name).to_sym@prepare=prepare@ast_node=ast_node@from_resolver=from_resolver@method_access=method_accessifdefinition_blockifdefinition_block.arity==1instance_exec(self,&definition_block)elseinstance_eval(&definition_block)endendend# @return [Object] the value used when the client doesn't provide a value for this argumentattr_reader:default_value# @return [Boolean] True if this argument has a default valuedefdefault_value?@default_value!=NO_DEFAULTendattr_writer:description# @return [String] Documentation for this argumentdefdescription(text=nil)iftext@description=textelse@descriptionendenddefvisible?(context)trueenddefaccessible?(context)trueenddefauthorized?(obj,value,ctx)authorized_as_type?(obj,value,ctx,as_type: type)enddefauthorized_as_type?(obj,value,ctx,as_type:)ifvalue.nil?returntrueendifas_type.kind.non_null?as_type=as_type.of_typeendifas_type.kind.list?value.eachdo|v|if!authorized_as_type?(obj,v,ctx,as_type: as_type.of_type)returnfalseendendelsifas_type.kind.input_object?as_type.arguments.eachdo|_name,input_obj_arg|input_obj_arg=input_obj_arg.type_class# TODO: this skips input objects whose values were alread replaced with application objects.# See: https://github.com/rmosolgo/graphql-ruby/issues/2633ifvalue.respond_to?(:key?)&&value.key?(input_obj_arg.keyword)&&!input_obj_arg.authorized?(obj,value[input_obj_arg.keyword],ctx)returnfalseendendend# None of the early-return conditions were activated,# so this is authorized.trueenddefto_graphqlargument=GraphQL::Argument.newargument.name=@nameargument.type=->{type}argument.description=@descriptionargument.metadata[:type_class]=selfargument.as=@asargument.ast_node=ast_nodeargument.method_access=@method_accessifNO_DEFAULT!=@default_valueargument.default_value=@default_valueendargumentendattr_writer:typedeftype@type||=Member::BuildType.parse_type(@type_expr,null: @null)rescueStandardError=>errraiseArgumentError,"Couldn't build type for Argument #{@owner.name}.#{name}: #{err.class.name}: #{err.message}",err.backtraceend# Apply the {prepare} configuration to `value`, using methods from `obj`.# Used by the runtime.# @api privatedefprepare_value(obj,value,context: nil)ifvalue.is_a?(GraphQL::Schema::InputObject)value=value.prepareendif@prepare.nil?valueelsif@prepare.is_a?(String)||@prepare.is_a?(Symbol)ifobj.nil?# The problem here is, we _used to_ prepare while building variables.# But now we don't have the runtime object there.## This will have to be called later, when the runtime object _is_ available.valueelseobj.public_send(@prepare,value)endelsif@prepare.respond_to?(:call)@prepare.call(value,context||obj.context)elseraise"Invalid prepare for #{@owner.name}.name: #{@prepare.inspect}"endendendendend