summaryrefslogtreecommitdiff
path: root/lib/gitlab/graphql
diff options
context:
space:
mode:
authorLuke Duncalfe <lduncalfe@eml.cc>2019-06-28 14:28:43 +1200
committerLuke Duncalfe <lduncalfe@eml.cc>2019-06-28 17:02:03 +1200
commitdae02286ba942d3783ff13c4f74f34f72d20b68d (patch)
tree2ee82014af45653a91d1260f37e82bc5f13ccf88 /lib/gitlab/graphql
parent62a40c5170cbecfc77dcb5fc97a23f3e93898a53 (diff)
downloadgitlab-ce-dae02286ba942d3783ff13c4f74f34f72d20b68d.tar.gz
CE backport for changes in EE MR 142929491-graphql-view-design-board-at-version-ce
EE MR https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/14292 https://gitlab.com/gitlab-org/gitlab-ee/issues/9491
Diffstat (limited to 'lib/gitlab/graphql')
-rw-r--r--lib/gitlab/graphql/find_argument_in_parent.rb32
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