Module: GraphQL::StaticValidation::BaseVisitor::ContextMethods
- Defined in:
- lib/graphql/static_validation/base_visitor.rb
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.
- #on_argument(node, parent) ⇒ Object
- #on_directive(node, parent) ⇒ Object
- #on_field(node, parent) ⇒ Object
- #on_fragment_definition(node, parent) ⇒ Object
- #on_fragment_spread(node, parent) ⇒ Object
- #on_inline_fragment(node, parent) ⇒ Object
- #on_input_object(node, parent) ⇒ Object
- #on_operation_definition(node, parent) ⇒ Object
-
#parent_type_definition ⇒ GraphQL::BaseType
The type which the current type came from.
-
#type_definition ⇒ GraphQL::BaseType
The current object type.
Instance Method Details
#argument_definition ⇒ GraphQL::Argument?
Returns The most-recently-entered GraphQL::Argument, if currently inside one.
164 165 166 167 168 |
# File 'lib/graphql/static_validation/base_visitor.rb', line 164 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. @argument_definitions[-2] end |
#directive_definition ⇒ GraphQL::Directive?
Returns The most-recently-entered GraphQL::Directive, if currently inside one.
159 160 161 |
# File 'lib/graphql/static_validation/base_visitor.rb', line 159 def directive_definition @directive_definitions.last end |
#field_definition ⇒ GraphQL::Field?
Returns The most-recently-entered GraphQL::Field, if currently inside one.
154 155 156 |
# File 'lib/graphql/static_validation/base_visitor.rb', line 154 def field_definition @field_definitions.last end |
#on_argument(node, parent) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/graphql/static_validation/base_visitor.rb', line 103 def on_argument(node, parent) argument_defn = if (arg = @argument_definitions.last) arg_type = arg.type.unwrap if arg_type.kind.input_object? @types.argument(arg_type, node.name) else nil end elsif (directive_defn = @directive_definitions.last) @types.argument(directive_defn, node.name) elsif (field_defn = @field_definitions.last) @types.argument(field_defn, node.name) else nil end @argument_definitions.push(argument_defn) @path.push(node.name) super @argument_definitions.pop @path.pop end |
#on_directive(node, parent) ⇒ Object
96 97 98 99 100 101 |
# File 'lib/graphql/static_validation/base_visitor.rb', line 96 def on_directive(node, parent) directive_defn = @context.schema_directives[node.name] @directive_definitions.push(directive_defn) super @directive_definitions.pop end |
#on_field(node, parent) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/graphql/static_validation/base_visitor.rb', line 79 def on_field(node, parent) parent_type = @object_types.last field_definition = @types.field(parent_type, node.name) @field_definitions.push(field_definition) if !field_definition.nil? next_object_type = field_definition.type.unwrap push_type(next_object_type) else push_type(nil) end @path.push(node.alias || node.name) super @field_definitions.pop @object_types.pop @path.pop end |
#on_fragment_definition(node, parent) ⇒ Object
65 66 67 68 69 70 |
# File 'lib/graphql/static_validation/base_visitor.rb', line 65 def on_fragment_definition(node, parent) on_fragment_with_type(node) do @path.push("fragment #{node.name}") super end end |
#on_fragment_spread(node, parent) ⇒ Object
126 127 128 129 130 |
# File 'lib/graphql/static_validation/base_visitor.rb', line 126 def on_fragment_spread(node, parent) @path.push("... #{node.name}") super @path.pop end |
#on_inline_fragment(node, parent) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/graphql/static_validation/base_visitor.rb', line 72 def on_inline_fragment(node, parent) on_fragment_with_type(node) do @path.push("...#{node.type ? " on #{node.type.to_query_string}" : ""}") super end end |
#on_input_object(node, parent) ⇒ Object
132 133 134 135 136 137 138 139 140 141 |
# File 'lib/graphql/static_validation/base_visitor.rb', line 132 def on_input_object(node, parent) arg_defn = @argument_definitions.last if arg_defn && arg_defn.type.list? @path.push(parent.children.index(node)) super @path.pop else super end end |
#on_operation_definition(node, parent) ⇒ Object
56 57 58 59 60 61 62 63 |
# File 'lib/graphql/static_validation/base_visitor.rb', line 56 def on_operation_definition(node, parent) object_type = @schema.root_type_for_operation(node.operation_type) push_type(object_type) @path.push("#{node.operation_type}#{node.name ? " #{node.name}" : ""}") super @object_types.pop @path.pop end |
#parent_type_definition ⇒ GraphQL::BaseType
Returns The type which the current type came from.
149 150 151 |
# File 'lib/graphql/static_validation/base_visitor.rb', line 149 def parent_type_definition @object_types[-2] end |
#type_definition ⇒ GraphQL::BaseType
Returns The current object type.
144 145 146 |
# File 'lib/graphql/static_validation/base_visitor.rb', line 144 def type_definition @object_types.last end |