summaryrefslogtreecommitdiff
path: root/spec/support/helpers
diff options
context:
space:
mode:
authorNick Thomas <nick@gitlab.com>2017-08-16 14:04:41 +0100
committerBob Van Landuyt <bob@vanlanduyt.co>2018-06-05 20:47:42 +0200
commit9c6c17cbcdb8bf8185fc1b873dcfd08f723e4df5 (patch)
tree624dba30e87ed0ea39afa0535d92c37c7718daef /spec/support/helpers
parent67dc43db2f30095cce7fe01d7f475d084be936e8 (diff)
downloadgitlab-ce-9c6c17cbcdb8bf8185fc1b873dcfd08f723e4df5.tar.gz
Add a minimal GraphQL API
Diffstat (limited to 'spec/support/helpers')
-rw-r--r--spec/support/helpers/graphql_helpers.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb
new file mode 100644
index 00000000000..5bb2cf9dd9e
--- /dev/null
+++ b/spec/support/helpers/graphql_helpers.rb
@@ -0,0 +1,29 @@
+module GraphqlHelpers
+ # Run a loader's named resolver
+ def resolve(kls, name, obj: nil, args: {}, ctx: {})
+ kls[name].call(obj, args, ctx)
+ end
+
+ # Runs a block inside a GraphQL::Batch wrapper
+ def batch(max_queries: nil, &blk)
+ wrapper = proc do
+ GraphQL::Batch.batch do
+ result = yield
+
+ if result.is_a?(Array)
+ Promise.all(result)
+ else
+ result
+ end
+ end
+ end
+
+ if max_queries
+ result = nil
+ expect { result = wrapper.call }.not_to exceed_query_limit(max_queries)
+ result
+ else
+ wrapper.call
+ end
+ end
+end