Class: GraphQL::Schema::Directive
- Extended by:
- 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/include.rb,
lib/graphql/schema/directive/transform.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
yield
to continue)
Defined Under Namespace
Classes: Feature, 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, ]
- 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.', }
Constants included from Member::GraphQLTypeNames
Member::GraphQLTypeNames::Boolean, Member::GraphQLTypeNames::ID, Member::GraphQLTypeNames::Int
Class Method Summary collapse
-
.default_directive(new_default_directive = nil) ⇒ Object
-
.default_graphql_name ⇒ Object
-
.include?(_object, _arguments, _context) ⇒ Boolean
If false, this part of the query won’t be evaluated.
-
.locations(*new_locations) ⇒ Object
-
.resolve(object, arguments, context) ⇒ Object
Continuing is passed as a block;
yield
to continue. -
.to_graphql ⇒ Object
Methods included from Member::HasArguments
add_argument, argument, argument_class, arguments, own_arguments
Methods included from Member::HasPath
Methods included from Member::RelayShortcuts
#connection_type, #connection_type_class, #edge_type, #edge_type_class
Methods included from Member::Scoped
Methods included from Member::TypeSystemHelpers
#kind, #list?, #non_null?, #to_list_type, #to_non_null_type, #to_type_signature
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 Relay::TypeExtensions
#connection_type, #define_connection, #define_edge, #edge_type
Methods included from Member::CachedGraphQLDefinition
#graphql_definition, #initialize_copy
Class Method Details
.default_directive(new_default_directive = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/graphql/schema/directive.rb', line 24 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_graphql_name ⇒ Object
12 13 14 |
# File 'lib/graphql/schema/directive.rb', line 12 def default_graphql_name super.downcase end |
.include?(_object, _arguments, _context) ⇒ Boolean
If false, this part of the query won’t be evaluated
49 50 51 |
# File 'lib/graphql/schema/directive.rb', line 49 def include?(_object, _arguments, _context) true end |
.locations(*new_locations) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/graphql/schema/directive.rb', line 16 def locations(*new_locations) if new_locations.any? @locations = new_locations else @locations ||= (superclass.respond_to?(:locations) ? superclass.locations : []) end end |
.resolve(object, arguments, context) ⇒ Object
Continuing is passed as a block; yield
to continue
54 55 56 |
# File 'lib/graphql/schema/directive.rb', line 54 def resolve(object, arguments, context) yield end |
.to_graphql ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/graphql/schema/directive.rb', line 34 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.[:type_class] = self arguments.each do |name, arg_defn| arg_graphql = arg_defn.to_graphql defn.arguments[arg_graphql.name] = arg_graphql end defn end |