diff options
author | Phil Hughes <me@iamphill.com> | 2019-05-09 12:27:07 +0300 |
---|---|---|
committer | Bob Van Landuyt <bob@vanlanduyt.co> | 2019-05-28 11:22:02 +0300 |
commit | 11f85ae8c3b8ec5d864edd079e7c420a49cae72e (patch) | |
tree | 8da63219fc0977c7e132f7177bff20f41c997520 /spec/support | |
parent | 2cc6e6ff2628bd71faa71f083646a981ab2bcc11 (diff) |
Enables GraphQL batch requests
Enabling GraphQL batch requests allows for multiple queries
to be sent in 1 request reducing the amount of requests
we send to the server.
Responses come come back in the same order as the queries were
provided.
Diffstat (limited to 'spec/support')
-rw-r--r-- | spec/support/helpers/graphql_helpers.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/spec/support/helpers/graphql_helpers.rb b/spec/support/helpers/graphql_helpers.rb index 44ed9da25fc..e95c7f2a6d6 100644 --- a/spec/support/helpers/graphql_helpers.rb +++ b/spec/support/helpers/graphql_helpers.rb @@ -134,6 +134,10 @@ module GraphqlHelpers end.join(", ") end + def post_multiplex(queries, current_user: nil, headers: {}) + post api('/', current_user, version: 'graphql'), params: { _json: queries }, headers: headers + end + def post_graphql(query, current_user: nil, variables: nil, headers: {}) post api('/', current_user, version: 'graphql'), params: { query: query, variables: variables }, headers: headers end @@ -147,7 +151,14 @@ module GraphqlHelpers end def graphql_errors - json_response['errors'] + case json_response + when Hash # regular query + json_response['errors'] + when Array # multiplexed queries + json_response.map { |response| response['errors'] } + else + raise "Unkown GraphQL response type #{json_response.class}" + end end def graphql_mutation_response(mutation_name) |