Class: GraphQL::Stitching::Request::ApplyRuntimeDirectives
- Inherits:
-
Language::Visitor
- Object
- Language::Visitor
- GraphQL::Stitching::Request::ApplyRuntimeDirectives
- Defined in:
- lib/graphql/stitching/request.rb
Instance Method Summary collapse
- #changed? ⇒ Boolean
-
#initialize(document, variables) ⇒ ApplyRuntimeDirectives
constructor
A new instance of ApplyRuntimeDirectives.
- #on_field(node, parent) ⇒ Object
Constructor Details
#initialize(document, variables) ⇒ ApplyRuntimeDirectives
Returns a new instance of ApplyRuntimeDirectives.
10 11 12 13 14 |
# File 'lib/graphql/stitching/request.rb', line 10 def initialize(document, variables) @changed = false @variables = variables super(document) end |
Instance Method Details
#changed? ⇒ Boolean
16 17 18 |
# File 'lib/graphql/stitching/request.rb', line 16 def changed? @changed end |
#on_field(node, parent) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/graphql/stitching/request.rb', line 20 def on_field(node, parent) delete_node = false filtered_directives = if node.directives.any? node.directives.select do |directive| if directive.name == "skip" delete_node = assess_argument_value(directive.arguments.first) false elsif directive.name == "include" delete_node = !assess_argument_value(directive.arguments.first) false else true end end end if delete_node @changed = true super(DELETE_NODE, parent) elsif filtered_directives && filtered_directives.length != node.directives.length @changed = true super(node.merge(directives: filtered_directives), parent) else super end end |