Class: GraphQL::Query::DirectiveChain
- Inherits:
-
Object
- Object
- GraphQL::Query::DirectiveChain
- Defined in:
- lib/graphql/query/directive_chain.rb
Overview
TODO: directives on fragments: facebook.github.io/graphql/#sec-Fragment-Directives
Constant Summary collapse
- DIRECTIVE_ON =
{ GraphQL::Language::Nodes::Field => GraphQL::Directive::ON_FIELD, GraphQL::Language::Nodes::InlineFragment => GraphQL::Directive::ON_FRAGMENT, GraphQL::Language::Nodes::FragmentSpread => GraphQL::Directive::ON_FRAGMENT, }
- GET_DIRECTIVES =
{ GraphQL::Language::Nodes::Field => Proc.new { |n, f| n.directives }, GraphQL::Language::Nodes::InlineFragment => Proc.new { |n, f| n.directives }, GraphQL::Language::Nodes::FragmentSpread => Proc.new { |n, f| n.directives + f[n.name].directives }, # get directives from definition too }
Instance Attribute Summary collapse
-
#result ⇒ Object
readonly
Returns the value of attribute result.
Instance Method Summary collapse
-
#initialize(ast_node, query, &block) ⇒ DirectiveChain
constructor
A new instance of DirectiveChain.
Constructor Details
#initialize(ast_node, query, &block) ⇒ DirectiveChain
Returns a new instance of DirectiveChain.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/graphql/query/directive_chain.rb', line 16 def initialize(ast_node, query, &block) directives = query.schema.directives on_what = DIRECTIVE_ON[ast_node.class] ast_directives = GET_DIRECTIVES[ast_node.class].call(ast_node, query.fragments) if contains_skip?(ast_directives) ast_directives = ast_directives.reject { |ast_directive| ast_directive.name == 'include' } end applicable_directives = ast_directives .map { |ast_directive| [ast_directive, directives[ast_directive.name]] } .select { |directive_pair| directive_pair.last.on.include?(on_what) } if applicable_directives.none? @result = block.call else applicable_directives.map do |(ast_directive, directive)| args = GraphQL::Query::Arguments.new(ast_directive.arguments, directive.arguments, query.variables) @result = directive.resolve(args, block) end @result ||= {} end end |
Instance Attribute Details
#result ⇒ Object (readonly)
Returns the value of attribute result.
15 16 17 |
# File 'lib/graphql/query/directive_chain.rb', line 15 def result @result end |