Class: GraphQL::StaticValidation::Validator::Context
- Inherits:
-
Object
- Object
- GraphQL::StaticValidation::Validator::Context
- Defined in:
- lib/graphql/static_validation/validator.rb
Overview
The validation context gets passed to each validator.
It exposes a Language::Visitor where validators may add hooks. (Visitor#visit is called in #validate)
It provides access to the schema & fragments which validators may read from.
It holds a list of errors which each validator may add to.
It also provides limited access to the TypeStack instance, which tracks state as you climb in and out of different fields.
Instance Attribute Summary collapse
-
#document ⇒ Object
readonly
Returns the value of attribute document.
-
#errors ⇒ Object
readonly
Returns the value of attribute errors.
-
#fragments ⇒ Object
readonly
Returns the value of attribute fragments.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#visitor ⇒ Object
readonly
Returns the value of attribute visitor.
Instance Method Summary collapse
-
#argument_definition ⇒ GraphQL::Argument?
The most-recently-entered GraphQL::Argument, if currently inside one.
-
#directive_definition ⇒ GraphQL::Directive?
The most-recently-entered GraphQL::Directive, if currently inside one.
-
#field_definition ⇒ GraphQL::Field?
The most-recently-entered GraphQL::Field, if currently inside one.
-
#initialize(schema, document) ⇒ Context
constructor
A new instance of Context.
- #object_types ⇒ Object
-
#skip_field?(field_name) ⇒ Boolean
Don’t try to validate dynamic fields since they aren’t defined by the type system.
Constructor Details
#initialize(schema, document) ⇒ Context
Returns a new instance of Context.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/graphql/static_validation/validator.rb', line 42 def initialize(schema, document) @schema = schema @document = document @fragments = document.parts.each_with_object({}) do |part, memo| part.is_a?(GraphQL::Language::Nodes::FragmentDefinition) && memo[part.name] = part end @errors = [] @visitor = GraphQL::Language::Visitor.new @type_stack = GraphQL::StaticValidation::TypeStack.new(schema, visitor) end |
Instance Attribute Details
#document ⇒ Object (readonly)
Returns the value of attribute document.
41 42 43 |
# File 'lib/graphql/static_validation/validator.rb', line 41 def document @document end |
#errors ⇒ Object (readonly)
Returns the value of attribute errors.
41 42 43 |
# File 'lib/graphql/static_validation/validator.rb', line 41 def errors @errors end |
#fragments ⇒ Object (readonly)
Returns the value of attribute fragments.
41 42 43 |
# File 'lib/graphql/static_validation/validator.rb', line 41 def fragments @fragments end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
41 42 43 |
# File 'lib/graphql/static_validation/validator.rb', line 41 def schema @schema end |
#visitor ⇒ Object (readonly)
Returns the value of attribute visitor.
41 42 43 |
# File 'lib/graphql/static_validation/validator.rb', line 41 def visitor @visitor end |
Instance Method Details
#argument_definition ⇒ GraphQL::Argument?
Returns The most-recently-entered GraphQL::Argument, if currently inside one.
68 69 70 71 72 |
# File 'lib/graphql/static_validation/validator.rb', line 68 def argument_definition # Don't get the _last_ one because that's the current one. # Get the second-to-last one, which is the parent of the current one. @type_stack.argument_definitions[-2] end |
#directive_definition ⇒ GraphQL::Directive?
Returns The most-recently-entered GraphQL::Directive, if currently inside one.
63 64 65 |
# File 'lib/graphql/static_validation/validator.rb', line 63 def directive_definition @type_stack.directive_definitions.last end |
#field_definition ⇒ GraphQL::Field?
Returns The most-recently-entered GraphQL::Field, if currently inside one.
58 59 60 |
# File 'lib/graphql/static_validation/validator.rb', line 58 def field_definition @type_stack.field_definitions.last end |
#object_types ⇒ Object
53 54 55 |
# File 'lib/graphql/static_validation/validator.rb', line 53 def object_types @type_stack.object_types end |
#skip_field?(field_name) ⇒ Boolean
Don’t try to validate dynamic fields since they aren’t defined by the type system
76 77 78 |
# File 'lib/graphql/static_validation/validator.rb', line 76 def skip_field?(field_name) GraphQL::Schema::DYNAMIC_FIELDS.include?(field_name) end |