Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
f6e74e25
Commit
f6e74e25
authored
Oct 08, 2021
by
Paul Slaughter
Committed by
Mayra Cabrera
Oct 08, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add x-gitlab-feature-category header to startup gql calls
parent
b74d155c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
33 additions
and
1 deletion
+33
-1
app/helpers/startupjs_helper.rb
app/helpers/startupjs_helper.rb
+7
-0
app/views/layouts/_startup_js.html.haml
app/views/layouts/_startup_js.html.haml
+4
-1
spec/helpers/startupjs_helper_spec.rb
spec/helpers/startupjs_helper_spec.rb
+22
-0
No files found.
app/helpers/startupjs_helper.rb
View file @
f6e74e25
...
...
@@ -5,6 +5,13 @@ module StartupjsHelper
@graphql_startup_calls
end
def
page_startup_graphql_headers
{
'X-CSRF-Token'
=>
form_authenticity_token
,
'x-gitlab-feature-category'
=>
::
Gitlab
::
ApplicationContext
.
current_context_attribute
(
:feature_category
).
presence
||
''
}
end
def
add_page_startup_graphql_call
(
query
,
variables
=
{})
@graphql_startup_calls
||=
[]
file_location
=
File
.
join
(
Rails
.
root
,
"app/graphql/queries/
#{
query
}
.query.graphql"
)
...
...
app/views/layouts/_startup_js.html.haml
View file @
f6e74e25
...
...
@@ -17,11 +17,14 @@
});
}
if (gl.startup_graphql_calls && window.fetch) {
const headers =
#{
page_startup_graphql_headers
.
to_json
}
;
const url = `
#{
api_graphql_url
}
`
const opts = {
method: "POST",
headers: { "Content-Type": "application/json", 'X-CSRF-Token': "
#{
form_authenticity_token
}
" },
headers: {
"Content-Type": "application/json",
...headers,
};
gl.startup_graphql_calls = gl.startup_graphql_calls.map(call => ({
...
...
spec/helpers/startupjs_helper_spec.rb
View file @
f6e74e25
...
...
@@ -3,6 +3,8 @@
require
'spec_helper'
RSpec
.
describe
StartupjsHelper
do
using
RSpec
::
Parameterized
::
TableSyntax
describe
'#page_startup_graphql_calls'
do
let
(
:query_location
)
{
'repository/path_last_commit'
}
let
(
:query_content
)
do
...
...
@@ -17,4 +19,24 @@ RSpec.describe StartupjsHelper do
expect
(
startup_graphql_calls
).
to
include
({
query:
query_content
,
variables:
{
ref:
'foo'
}
})
end
end
describe
'#page_startup_graphql_headers'
do
where
(
:csrf_token
,
:feature_category
,
:expected
)
do
'abc'
|
'web_ide'
|
{
'X-CSRF-Token'
=>
'abc'
,
'x-gitlab-feature-category'
=>
'web_ide'
}
''
|
''
|
{
'X-CSRF-Token'
=>
''
,
'x-gitlab-feature-category'
=>
''
}
'abc'
|
nil
|
{
'X-CSRF-Token'
=>
'abc'
,
'x-gitlab-feature-category'
=>
''
}
'something'
|
' '
|
{
'X-CSRF-Token'
=>
'something'
,
'x-gitlab-feature-category'
=>
''
}
end
with_them
do
before
do
allow
(
helper
).
to
receive
(
:form_authenticity_token
).
and_return
(
csrf_token
)
::
Gitlab
::
ApplicationContext
.
push
(
feature_category:
feature_category
)
end
it
'returns hash of headers for GraphQL requests'
do
expect
(
helper
.
page_startup_graphql_headers
).
to
eq
(
expected
)
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment