class GraphQL::Schema::Directive
Subclasses of this can influence how GraphQL::Execution::Interpreter runs queries.
Constants
- DEFAULT_DEPRECATION_REASON
- LOCATIONS
- LOCATION_DESCRIPTIONS
Attributes
Returns
-
GraphQL::Interpreter::Arguments
Returns
-
GraphQL::Schema::Field, GraphQL::Schema::Argument, Class, Module
Public Class Methods
# File lib/graphql/schema/directive.rb, line 54 def default_directive(new_default_directive = nil) if new_default_directive != nil @default_directive = new_default_directive elsif @default_directive.nil? @default_directive = (superclass.respond_to?(:default_directive) ? superclass.default_directive : false) else !!@default_directive end end
Source
# File lib/graphql/schema/directive.rb, line 64 def default_directive? default_directive end
Source
# File lib/graphql/schema/directive.rb, line 25 def default_graphql_name @default_graphql_name ||= begin camelized_name = super.dup camelized_name[0] = camelized_name[0].downcase -camelized_name end end
Return a name based on the class name, but downcase the first letter.
Calls superclass method
# File lib/graphql/schema/directive.rb, line 69 def include?(_object, arguments, context) static_include?(arguments, context) end
If false, this part of the query wonβt be evaluated
Source
# File lib/graphql/schema/directive.rb, line 33 def locations(*new_locations) if !new_locations.empty? is_runtime = false #: bool new_locations.each do |new_loc| loc_sym = new_loc.to_sym if !LOCATIONS.include?(loc_sym) raise ArgumentError, "#{self} (#{self.graphql_name}) has an invalid directive location: `locations #{new_loc}` " end is_runtime ||= RUNTIME_LOCATIONS.include?(loc_sym) end @locations = new_locations @is_runtime = is_runtime else @locations ||= (superclass.respond_to?(:locations) ? superclass.locations : []) end end
Source
# File lib/graphql/schema/directive.rb, line 144 def initialize(owner, **arguments) @owner = owner assert_valid_owner # It's be nice if we had the real context here, but we don't. What we _would_ get is: # - error handling # - lazy resolution # Probably, those won't be needed here, since these are configuration arguments, # not runtime arguments. context = Query::NullContext.instance self.class.all_argument_definitions.each do |arg_defn| keyword = arg_defn.keyword arg_type = arg_defn.type if arguments.key?(keyword) value = arguments[keyword] # This is a Ruby-land value; convert it to graphql for validation graphql_value = begin coerce_value = value if arg_type.list? && (!coerce_value.nil?) && (!coerce_value.is_a?(Array)) # When validating inputs, GraphQL accepts a single item # and implicitly converts it to a one-item list. # However, we're using result coercion here to go from Ruby value # to GraphQL value, so it doesn't have that feature. # Keep the GraphQL-type behavior but implement it manually: wrap_type = arg_type while wrap_type.list? if wrap_type.non_null? wrap_type = wrap_type.of_type end wrap_type = wrap_type.of_type coerce_value = [coerce_value] end end arg_type.coerce_isolated_result(coerce_value) rescue GraphQL::Schema::Enum::UnresolvedValueError # Let validation handle this value end elsif arg_defn.default_value? value = arg_defn.default_value graphql_value = arg_type.coerce_isolated_result(value) unless value.nil? else value = graphql_value = nil end result = arg_type.validate_input(graphql_value, context) if !result.valid? raise InvalidArgumentError, "@#{graphql_name}.#{arg_defn.graphql_name} on #{owner.path} is invalid (#{value.inspect}): #{result.problems.first["explanation"]}" end end self.class.validate!(arguments, context) @arguments = self.class.coerce_arguments(nil, arguments, context) if @arguments.is_a?(GraphQL::ExecutionError) raise @arguments end end
Source
# File lib/graphql/schema/directive.rb, line 97 def on_field? locations.include?(FIELD) end
Source
# File lib/graphql/schema/directive.rb, line 101 def on_fragment? locations.include?(FRAGMENT_SPREAD) && locations.include?(INLINE_FRAGMENT) end
Source
# File lib/graphql/schema/directive.rb, line 105 def on_operation? locations.include?(QUERY) && locations.include?(MUTATION) && locations.include?(SUBSCRIPTION) end
Source
# File lib/graphql/schema/directive.rb, line 19 def path "@#{super}" end
Calls superclass method
Source
# File lib/graphql/schema/directive.rb, line 113 def repeatable(new_value) @repeatable = new_value end
Source
# File lib/graphql/schema/directive.rb, line 109 def repeatable? !!@repeatable end
# File lib/graphql/schema/directive.rb, line 79 def resolve(object, arguments, context) yield end
Continuing is passed as a block; yield to continue
# File lib/graphql/schema/directive.rb, line 84 def resolve_each(object, arguments, context) yield end
Continuing is passed as a block, yield to continue.
Source
# File lib/graphql/schema/directive.rb, line 88 def resolve_field(...); end
# File lib/graphql/schema/directive.rb, line 89 def resolve_fragment_spread(...); end
# File lib/graphql/schema/directive.rb, line 90 def resolve_inline_fragment(...); end
Source
# File lib/graphql/schema/directive.rb, line 91 def resolve_operation(...); end
# File lib/graphql/schema/directive.rb, line 74 def static_include?(_arguments, _context) true end
Determines whether Execution::Lookahead considers the field to be selected
# File lib/graphql/schema/directive.rb, line 93 def validate!(arguments, context) Schema::Validator.validate!(validators, self, context, arguments) end
Public Instance Methods
Source
# File lib/graphql/schema/directive.rb, line 200 def graphql_name self.class.graphql_name end