summaryrefslogtreecommitdiff
path: root/spec/support/helpers/graphql_helpers.rb
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2018-05-21 09:52:24 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2018-06-05 20:47:42 +0200
commitaa4b1ae71260720b47695b8a256134f20280f61a (patch)
tree81020f291d634e76fe0a31d906ed73639f634b7d /spec/support/helpers/graphql_helpers.rb
parent287c34ca1f9af4e395493c99623af8437f82d919 (diff)
downloadgitlab-ce-aa4b1ae71260720b47695b8a256134f20280f61a.tar.gz
Add `present_using` to types
By specifying a presenter for the object type, we can keep the logic out of `GitlabSchema`. The presenter gets initialized using the object being presented, and the context (including the `current_user`).
Diffstat (limited to 'spec/support/helpers/graphql_helpers.rb')
-rw-r--r--spec/support/helpers/graphql_helpers.rb33
1 files changed, 31 insertions, 2 deletions
diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb
index 1eaa7603af0..ae29b16e32c 100644
--- a/spec/support/helpers/graphql_helpers.rb
+++ b/spec/support/helpers/graphql_helpers.rb
@@ -9,12 +9,12 @@ module GraphqlHelpers
wrapper = proc do
begin
BatchLoader::Executor.ensure_current
- blk.call
+ yield
ensure
BatchLoader::Executor.clear_current
end
end
-
+
if max_queries
result = nil
expect { result = wrapper.call }.not_to exceed_query_limit(max_queries)
@@ -23,4 +23,33 @@ module GraphqlHelpers
wrapper.call
end
end
+
+ def all_graphql_fields_for(klass)
+ type = GitlabSchema.types[klass.name]
+ return "" unless type
+
+ type.fields.map do |name, field|
+ if scalar?(field)
+ name
+ else
+ "#{name} { #{all_graphql_fields_for(field_type(field))} }"
+ end
+ end.join("\n")
+ end
+
+ def post_graphql(query)
+ post '/api/graphql', query: query
+ end
+
+ def scalar?(field)
+ field_type(field).kind.scalar?
+ end
+
+ def field_type(field)
+ if field.type.respond_to?(:of_type)
+ field.type.of_type
+ else
+ field.type
+ end
+ end
end