class GraphQL::Schema::Scalar
Public Class Methods
(untyped val, GraphQL::Query::Context ctx) → untyped
Source
# File lib/graphql/schema/scalar.rb, line 11 def coerce_input(val, ctx) val end
(untyped val, GraphQL::Query::Context ctx) → untyped
Source
# File lib/graphql/schema/scalar.rb, line 16 def coerce_result(val, ctx) val end
(?bool? is_default) → bool?
Source
# File lib/graphql/schema/scalar.rb, line 39 def default_scalar(is_default = nil) if !is_default.nil? @default_scalar = is_default #: bool? end @default_scalar end
→ bool
Source
# File lib/graphql/schema/scalar.rb, line 47 def default_scalar? @default_scalar ||= false end
Source
# File lib/graphql/schema/scalar.rb, line 21 def kind GraphQL::TypeKinds::SCALAR end
# File lib/graphql/schema/scalar.rb, line 26 def specified_by_url(new_url = nil) if new_url directive(GraphQL::Schema::Directive::SpecifiedBy, url: new_url) elsif (directive = directives.find { |dir| dir.graphql_name == "specifiedBy" }) directive.arguments[:url] # rubocop:disable Development/ContextIsPassedCop elsif superclass.respond_to?(:specified_by_url) superclass.specified_by_url else nil end end
(untyped value, GraphQL::Query::Context ctx, ?max_errors: Integer?) → GraphQL::Query::InputValidationResult?
Source
# File lib/graphql/schema/scalar.rb, line 68 def validate_non_null_input(value, ctx, max_errors: nil) coerced_result = begin coerce_input(value, ctx) rescue GraphQL::CoercionError => err err rescue StandardError => err ctx.query.handle_or_reraise(err) end if coerced_result.nil? Query::InputValidationResult.from_problem("Could not coerce value #{GraphQL::Language.serialize(value)} to #{graphql_name}") elsif coerced_result.is_a?(GraphQL::CoercionError) Query::InputValidationResult.from_problem(coerced_result.message, message: coerced_result.message, extensions: coerced_result.extensions) else Query::InputValidationResult.coerced(coerced_result) end end
Coerce value with coerce_input and report any problems.
GraphQL-Ruby calls this for variable and literal input values. When the value is valid, it returns a result with coerced_value, which is used as the argument value.
Overrides may return InputValidationResult.coerced(value) to provide a coerced value (including nil). If an override returns a valid result without a coerced value, coerce_input will be called at runtime, and any GraphQL::CoercionError it raises will be added as a field error.
Returns
-
GraphQL::Query::InputValidationResult, nil