diff options
author | Nick Thomas <nick@gitlab.com> | 2019-07-01 19:48:49 +0300 |
---|---|---|
committer | Nick Thomas <nick@gitlab.com> | 2019-07-01 19:48:49 +0300 |
commit | 402255c290e4bb96386bc1ff3fd8c4f10669f6b2 (patch) | |
tree | 6865fd63f69c18bc316b78cd43917a32b79a69b4 /lib | |
parent | 01a978593952456f8ff97cc3d415b3dfc5e421e8 (diff) | |
parent | dae02286ba942d3783ff13c4f74f34f72d20b68d (diff) |
Merge branch '9491-graphql-view-design-board-at-version-ce' into 'master'
CE backport for "Show design boards at previous versions in GraphQL"
See merge request gitlab-org/gitlab-ce!30151
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/graphql/find_argument_in_parent.rb | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/lib/gitlab/graphql/find_argument_in_parent.rb b/lib/gitlab/graphql/find_argument_in_parent.rb new file mode 100644 index 00000000000..1f83f8fce7a --- /dev/null +++ b/lib/gitlab/graphql/find_argument_in_parent.rb @@ -0,0 +1,32 @@ +# frozen_string_literal: true + +module Gitlab + module Graphql + module FindArgumentInParent + # Searches up the GraphQL AST and returns the first matching argument + # passed to a node + def self.find(parent, argument, limit_depth: nil) + argument = argument.to_s.camelize(:lower).to_sym + depth = 0 + + while parent.respond_to?(:parent) + args = node_args(parent) + return args[argument] if args.key?(argument) + + depth += 1 + return if limit_depth && depth >= limit_depth + + parent = parent.parent + end + end + + class << self + private + + def node_args(node) + node.irep_node.arguments + end + end + end + end +end |