diff options
Diffstat (limited to 'app/views/layouts/_startup_js.html.haml')
-rw-r--r-- | app/views/layouts/_startup_js.html.haml | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/app/views/layouts/_startup_js.html.haml b/app/views/layouts/_startup_js.html.haml index 33c759b7a7c..f312e00c394 100644 --- a/app/views/layouts/_startup_js.html.haml +++ b/app/views/layouts/_startup_js.html.haml @@ -1,9 +1,11 @@ -- return unless page_startup_api_calls.present? +- return unless page_startup_api_calls.present? || page_startup_graphql_calls.present? = javascript_tag nonce: true do :plain var gl = window.gl || {}; gl.startup_calls = #{page_startup_api_calls.to_json}; + gl.startup_graphql_calls = #{page_startup_graphql_calls.to_json}; + if (gl.startup_calls && window.fetch) { Object.keys(gl.startup_calls).forEach(apiCall => { // fetch won’t send cookies in older browsers, unless you set the credentials init option. @@ -14,3 +16,21 @@ }; }); } + if (gl.startup_graphql_calls && window.fetch) { + const url = `#{api_graphql_url}` + + const opts = { + method: "POST", + headers: { "Content-Type": "application/json", 'X-CSRF-Token': "#{form_authenticity_token}" }, + }; + + gl.startup_graphql_calls = gl.startup_graphql_calls.map(call => ({ + operationName: call.query.match(/^query (.+)\(/)[1], + fetchCall: fetch(url, { + ...opts, + credentials: 'same-origin', + body: JSON.stringify(call) + }) + })) + } + |