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
- #directive_definition ⇒ Object
- #field_definition ⇒ Object
-
#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
#directive_definition ⇒ Object
61 62 63 |
# File 'lib/graphql/static_validation/validator.rb', line 61 def directive_definition @type_stack.directive_definitions.last end |
#field_definition ⇒ Object
57 58 59 |
# File 'lib/graphql/static_validation/validator.rb', line 57 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
67 68 69 |
# File 'lib/graphql/static_validation/validator.rb', line 67 def skip_field?(field_name) GraphQL::Schema::DYNAMIC_FIELDS.include?(field_name) end |