Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
eapache committed May 13, 2021
1 parent d7e8589 commit 30722fb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/graphql/schema/argument.rb
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ def coerce_into_values(parent_object, values, context, argument_values)
elsif values.key?(arg_key)
value = values[arg_key]
elsif default_value?
context.schema.error_handler.with_error_handling(context) do
validate_default_value
end
value = default_value
default_used = true
else
Expand Down Expand Up @@ -297,6 +300,16 @@ def coerce_into_values(parent_object, values, context, argument_values)

private

def validate_default_value
return if @default_validated

coerced_value = default_value.nil? ? nil : type.coerce_isolated_result(default_value)
validation = type.validate_isolated_input(coerced_value)
raise GraphQL::RuntimeTypeError, validation.problems.first["explanation"] unless validation.valid?

@default_validated = true
end

def validate_input_type(input_type)
if input_type.is_a?(String) || input_type.is_a?(GraphQL::Schema::LateBoundType)
# Do nothing; assume this will be validated later
Expand Down
4 changes: 4 additions & 0 deletions lib/graphql/schema/member/validates_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ def valid_isolated_input?(v)
valid_input?(v, GraphQL::Query::NullContext)
end

def validate_isolated_input(v)
validate_input(v, GraphQL::Query::NullContext)
end

def coerce_isolated_input(v)
coerce_input(v, GraphQL::Query::NullContext)
end
Expand Down

0 comments on commit 30722fb

Please sign in to comment.