summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessio Caiazza <acaiazza@gitlab.com>2019-09-11 17:50:33 +0200
committerAlessio Caiazza <acaiazza@gitlab.com>2019-09-12 10:04:27 +0200
commit7c369bb6ded8bf3467831218b34cc3156e316037 (patch)
tree51bb11da6b8f0b9f82e73c9a655b0fff104cb198
parentdee0d33f321914c5c9935e3ce4b8c9a8a65b0266 (diff)
downloadgitlab-ce-ac-accelerate-graphql.tar.gz
Test a real GraphQL multipart requestac-accelerate-graphql
-rw-r--r--spec/support/helpers/graphql_helpers.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb
index beb346b2855..4d2ad165fd6 100644
--- a/spec/support/helpers/graphql_helpers.rb
+++ b/spec/support/helpers/graphql_helpers.rb
@@ -172,6 +172,31 @@ module GraphqlHelpers
post_graphql(mutation.query, current_user: current_user, variables: mutation.variables)
end
+ # this implements GraphQL multipart request v2
+ # https://github.com/jaydenseric/graphql-multipart-request-spec/tree/v2.0.0-alpha.2
+ # this is simplified and do not support file deduplication
+ def mutation_to_apollo_uploads_param(mutation, files: [])
+ operations = { 'query' => mutation.query, 'variables' => mutation.variables }
+ map = {}
+ extracted_files = {}
+
+ files.each_with_index do |file_path, idx|
+ apollo_idx = (idx + 1).to_s
+ parent_dig_path = file_path[0..-2]
+ file_key = file_path[-1]
+
+ parent = operations['variables']
+ parent = parent.dig(*parent_dig_path) unless parent_dig_path.empty?
+
+ extracted_files[apollo_idx] = parent[file_key]
+ parent[file_key] = nil
+
+ map[apollo_idx] = ["variables.#{file_path.join('.')}"]
+ end
+
+ { operations: operations.to_json, map: map.to_json }.merge(extracted_files)
+ end
+
# Raises an error if no data is found
def graphql_data
json_response['data'] || (raise NoData, graphql_errors)