Class: GraphQL::Schema::Directive
- Extended by:
- Member::AcceptsDefinition, Member::CachedGraphQLDefinition::DeprecatedToGraphQL, Member::HasArguments
- Defined in:
- lib/graphql/schema/directive.rb,
 lib/graphql/schema/directive/skip.rb,
 lib/graphql/schema/directive/feature.rb,
 lib/graphql/schema/directive/flagged.rb,
 lib/graphql/schema/directive/include.rb,
 lib/graphql/schema/directive/transform.rb,
 lib/graphql/schema/directive/deprecated.rb
Overview
Subclasses of this can influence how Execution::Interpreter runs queries.
- Directive.include?: if it returns false, the field or fragment will be skipped altogether, as if it were absent
- Directive.resolve: Wraps field resolution (so it should call yieldto continue)
Defined Under Namespace
Classes: Deprecated, Feature, Flagged, Include, Skip, Transform
Constant Summary collapse
- LOCATIONS =
- [ QUERY = :QUERY, MUTATION = :MUTATION, SUBSCRIPTION = :SUBSCRIPTION, FIELD = :FIELD, FRAGMENT_DEFINITION = :FRAGMENT_DEFINITION, FRAGMENT_SPREAD = :FRAGMENT_SPREAD, INLINE_FRAGMENT = :INLINE_FRAGMENT, SCHEMA = :SCHEMA, SCALAR = :SCALAR, OBJECT = :OBJECT, FIELD_DEFINITION = :FIELD_DEFINITION, ARGUMENT_DEFINITION = :ARGUMENT_DEFINITION, INTERFACE = :INTERFACE, UNION = :UNION, ENUM = :ENUM, ENUM_VALUE = :ENUM_VALUE, INPUT_OBJECT = :INPUT_OBJECT, INPUT_FIELD_DEFINITION = :INPUT_FIELD_DEFINITION, VARIABLE_DEFINITION = :VARIABLE_DEFINITION, ] 
- DEFAULT_DEPRECATION_REASON =
- 'No longer supported'
- LOCATION_DESCRIPTIONS =
- { QUERY: 'Location adjacent to a query operation.', MUTATION: 'Location adjacent to a mutation operation.', SUBSCRIPTION: 'Location adjacent to a subscription operation.', FIELD: 'Location adjacent to a field.', FRAGMENT_DEFINITION: 'Location adjacent to a fragment definition.', FRAGMENT_SPREAD: 'Location adjacent to a fragment spread.', INLINE_FRAGMENT: 'Location adjacent to an inline fragment.', SCHEMA: 'Location adjacent to a schema definition.', SCALAR: 'Location adjacent to a scalar definition.', OBJECT: 'Location adjacent to an object type definition.', FIELD_DEFINITION: 'Location adjacent to a field definition.', ARGUMENT_DEFINITION: 'Location adjacent to an argument definition.', INTERFACE: 'Location adjacent to an interface definition.', UNION: 'Location adjacent to a union definition.', ENUM: 'Location adjacent to an enum definition.', ENUM_VALUE: 'Location adjacent to an enum value definition.', INPUT_OBJECT: 'Location adjacent to an input object type definition.', INPUT_FIELD_DEFINITION: 'Location adjacent to an input object field definition.', VARIABLE_DEFINITION: 'Location adjacent to a variable definition.', } 
Constants included from Member::HasArguments
Member::HasArguments::NO_ARGUMENTS
Constants included from Member::HasDirectives
Member::HasDirectives::NO_DIRECTIVES
Constants included from Member::GraphQLTypeNames
Member::GraphQLTypeNames::Boolean, Member::GraphQLTypeNames::ID, Member::GraphQLTypeNames::Int
Instance Attribute Summary collapse
Class Method Summary collapse
- 
  
    
      .default_directive(new_default_directive = nil)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      .default_directive?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      .default_graphql_name  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Return a name based on the class name, but downcase the first letter. 
- 
  
    
      .include?(_object, arguments, context)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    If false, this part of the query won’t be evaluated. 
- 
  
    
      .locations(*new_locations)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      .on_field?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      .on_fragment?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      .on_operation?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      .path  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      .repeatable(new_value)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      .repeatable?  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    
- 
  
    
      .resolve(object, arguments, context)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Continuing is passed as a block; yieldto continue.
- 
  
    
      .resolve_each(object, arguments, context)  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    Continuing is passed as a block, yield to continue. 
- 
  
    
      .static_include?(_arguments, _context)  ⇒ Boolean 
    
    
  
  
  
  
  
  
  
  
  
    Determines whether Execution::Lookahead considers the field to be selected. 
- 
  
    
      .to_graphql  ⇒ Object 
    
    
  
  
  
  
  
  
  
  
  
    
Instance Method Summary collapse
- 
  
    
      #initialize(owner, **arguments)  ⇒ Directive 
    
    
  
  
  
    constructor
  
  
  
  
  
  
  
    A new instance of Directive. 
Methods included from Member::HasArguments
add_argument, all_argument_definitions, argument, argument_class, arguments_statically_coercible?, coerce_arguments, get_argument, own_arguments, validate_directive_argument
Methods included from Member::CachedGraphQLDefinition::DeprecatedToGraphQL
Methods included from Member::CachedGraphQLDefinition
#deprecated_to_graphql, #graphql_definition, #initialize_copy, #type_class
Methods included from Relay::TypeExtensions
#connection_type, #define_connection, #define_edge, #edge_type
Methods included from Member::BaseDSLMethods
#accessible?, #authorized?, #default_graphql_name, #description, #graphql_name, #introspection, #introspection?, #mutation, #name, #overridden_graphql_name, #to_graphql, #visible?
Methods included from Member::BaseDSLMethods::ConfigurationExtension
Methods included from Member::TypeSystemHelpers
#kind, #list?, #non_null?, #to_list_type, #to_non_null_type, #to_type_signature
Methods included from Member::Scoped
Methods included from Member::RelayShortcuts
#connection_type, #connection_type_class, #edge_type, #edge_type_class
Methods included from Member::HasPath
Methods included from Member::HasAstNode
Methods included from Member::HasDirectives
#directive, #directives, #remove_directive
Constructor Details
#initialize(owner, **arguments) ⇒ Directive
Returns a new instance of Directive.
| 125 126 127 128 129 130 131 132 133 134 | # File 'lib/graphql/schema/directive.rb', line 125 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. @arguments = self.class.coerce_arguments(nil, arguments, Query::NullContext) end | 
Instance Attribute Details
#arguments ⇒ GraphQL::Interpreter::Arguments (readonly)
| 123 124 125 | # File 'lib/graphql/schema/directive.rb', line 123 def arguments @arguments end | 
#owner ⇒ GraphQL::Schema::Field, ... (readonly)
| 120 121 122 | # File 'lib/graphql/schema/directive.rb', line 120 def owner @owner end | 
Class Method Details
.default_directive(new_default_directive = nil) ⇒ Object
| 44 45 46 47 48 49 50 51 52 | # File 'lib/graphql/schema/directive.rb', line 44 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 | 
.default_directive? ⇒ Boolean
| 54 55 56 | # File 'lib/graphql/schema/directive.rb', line 54 def default_directive? default_directive end | 
.default_graphql_name ⇒ Object
Return a name based on the class name, but downcase the first letter.
| 23 24 25 26 27 28 29 | # File 'lib/graphql/schema/directive.rb', line 23 def default_graphql_name @default_graphql_name ||= begin camelized_name = super camelized_name[0] = camelized_name[0].downcase camelized_name end end | 
.include?(_object, arguments, context) ⇒ Boolean
If false, this part of the query won’t be evaluated
| 79 80 81 | # File 'lib/graphql/schema/directive.rb', line 79 def include?(_object, arguments, context) static_include?(arguments, context) end | 
.locations(*new_locations) ⇒ Object
| 31 32 33 34 35 36 37 38 39 40 41 42 | # File 'lib/graphql/schema/directive.rb', line 31 def locations(*new_locations) if new_locations.any? new_locations.each do |new_loc| if !LOCATIONS.include?(new_loc.to_sym) raise ArgumentError, "#{self} (#{self.graphql_name}) has an invalid directive location: `locations #{new_loc}` " end end @locations = new_locations else @locations ||= (superclass.respond_to?(:locations) ? superclass.locations : []) end end | 
.on_field? ⇒ Boolean
| 98 99 100 | # File 'lib/graphql/schema/directive.rb', line 98 def on_field? locations.include?(FIELD) end | 
.on_fragment? ⇒ Boolean
| 102 103 104 | # File 'lib/graphql/schema/directive.rb', line 102 def on_fragment? locations.include?(FRAGMENT_SPREAD) && locations.include?(INLINE_FRAGMENT) end | 
.on_operation? ⇒ Boolean
| 106 107 108 | # File 'lib/graphql/schema/directive.rb', line 106 def on_operation? locations.include?(QUERY) && locations.include?(MUTATION) && locations.include?(SUBSCRIPTION) end | 
.path ⇒ Object
| 17 18 19 | # File 'lib/graphql/schema/directive.rb', line 17 def path "@#{super}" end | 
.repeatable(new_value) ⇒ Object
| 114 115 116 | # File 'lib/graphql/schema/directive.rb', line 114 def repeatable(new_value) @repeatable = new_value end | 
.repeatable? ⇒ Boolean
| 110 111 112 | # File 'lib/graphql/schema/directive.rb', line 110 def repeatable? !!@repeatable end | 
.resolve(object, arguments, context) ⇒ Object
Continuing is passed as a block; yield to continue
| 89 90 91 | # File 'lib/graphql/schema/directive.rb', line 89 def resolve(object, arguments, context) yield end | 
.resolve_each(object, arguments, context) ⇒ Object
Continuing is passed as a block, yield to continue.
| 94 95 96 | # File 'lib/graphql/schema/directive.rb', line 94 def resolve_each(object, arguments, context) yield end | 
.static_include?(_arguments, _context) ⇒ Boolean
Determines whether Execution::Lookahead considers the field to be selected
| 84 85 86 | # File 'lib/graphql/schema/directive.rb', line 84 def static_include?(_arguments, _context) true end | 
.to_graphql ⇒ Object
| 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | # File 'lib/graphql/schema/directive.rb', line 60 def to_graphql defn = GraphQL::Directive.new defn.name = self.graphql_name defn.description = self.description defn.locations = self.locations defn.default_directive = self.default_directive defn.ast_node = ast_node defn.[:type_class] = self all_argument_definitions.each do |arg_defn| arg_graphql = arg_defn.to_graphql(silence_deprecation_warning: true) defn.arguments[arg_graphql.name] = arg_graphql # rubocop:disable Development/ContextIsPassedCop -- legacy-related end # Make a reference to a classic-style Arguments class defn.arguments_class = GraphQL::Query::Arguments.construct_arguments_class(defn) defn end |