Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2019-03-03 15:46:42 +0300
committerBob Van Landuyt <bob@vanlanduyt.co>2019-03-06 17:35:30 +0300
commitee4ba6ce38cb3edc426a6323e1ef25b5611a4d04 (patch)
treea48560c090f8b24133858413b8489403c02e1823 /spec/support
parent2e1549427029f3f6635659a1cc0434666bbe9d67 (diff)
Adjust GraphQL helper to query empty fields
These adjustments make sure our GraphQL helpers support rendering queries for empty fields like this: { echo(text: "Hello world") } Instead of like this: { echo(text: "Hello world") { } } The latter would be an invalid query, causing parsing errors.
Diffstat (limited to 'spec/support')
-rw-r--r--spec/support/helpers/graphql_helpers.rb19
1 files changed, 14 insertions, 5 deletions
diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb
index d9529262483..6cdc19ac2e5 100644
--- a/spec/support/helpers/graphql_helpers.rb
+++ b/spec/support/helpers/graphql_helpers.rb
@@ -79,12 +79,21 @@ module GraphqlHelpers
attributes = attributes_to_graphql(attributes)
attributes = "(#{attributes})" if attributes.present?
<<~QUERY
- #{name}#{attributes} {
- #{fields}
- }
+ #{name}#{attributes}
+ #{wrap_fields(fields)}
QUERY
end
+ def wrap_fields(fields)
+ return unless fields.strip.present?
+
+ <<~FIELDS
+ {
+ #{fields}
+ }
+ FIELDS
+ end
+
def all_graphql_fields_for(class_name, parent_types = Set.new)
type = GitlabSchema.types[class_name.to_s]
return "" unless type
@@ -116,8 +125,8 @@ module GraphqlHelpers
end.join(", ")
end
- def post_graphql(query, current_user: nil, variables: nil)
- post api('/', current_user, version: 'graphql'), params: { query: query, variables: variables }
+ def post_graphql(query, current_user: nil, variables: nil, headers: {})
+ post api('/', current_user, version: 'graphql'), params: { query: query, variables: variables }, headers: headers
end
def post_graphql_mutation(mutation, current_user: nil)