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
927eb3fd
Commit
927eb3fd
authored
Oct 01, 2020
by
Natalia Tepluhina
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
POC: GraphQL Startup.js
parent
84bd4dff
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
107 additions
and
15 deletions
+107
-15
app/assets/javascripts/repository/index.js
app/assets/javascripts/repository/index.js
+42
-14
app/assets/javascripts/repository/queries/path_last_commit.query.graphql
...scripts/repository/queries/path_last_commit.query.graphql
+9
-0
app/helpers/startupjs_helper.rb
app/helpers/startupjs_helper.rb
+13
-0
app/views/layouts/_startup_js.html.haml
app/views/layouts/_startup_js.html.haml
+21
-1
app/views/projects/tree/show.html.haml
app/views/projects/tree/show.html.haml
+2
-0
spec/helpers/startupjs_helper_spec.rb
spec/helpers/startupjs_helper_spec.rb
+20
-0
No files found.
app/assets/javascripts/repository/index.js
View file @
927eb3fd
...
...
@@ -12,12 +12,17 @@ import { setTitle } from './utils/title';
import
{
updateFormAction
}
from
'
./utils/dom
'
;
import
{
convertObjectPropsToCamelCase
,
parseBoolean
}
from
'
../lib/utils/common_utils
'
;
import
{
__
}
from
'
../locale
'
;
import
PathLastCommitQuery
from
'
./queries/path_last_commit.query.graphql
'
;
export
default
function
setupVueRepositoryList
()
{
const
el
=
document
.
getElementById
(
'
js-tree-list
'
);
const
{
dataset
}
=
el
;
const
{
projectPath
,
projectShortPath
,
ref
,
escapedRef
,
fullName
}
=
dataset
;
const
router
=
createRouter
(
projectPath
,
escapedRef
);
const
pathRegex
=
/-
\/
tree
\/[^/]
+
\/(
.+$
)
/
;
const
matches
=
window
.
location
.
href
.
match
(
pathRegex
);
const
currentRoutePath
=
matches
?
matches
[
1
]
:
''
;
apolloProvider
.
clients
.
defaultClient
.
cache
.
writeData
({
data
:
{
...
...
@@ -29,6 +34,43 @@ export default function setupVueRepositoryList() {
},
});
const
initLastCommitApp
=
()
=>
new
Vue
({
el
:
document
.
getElementById
(
'
js-last-commit
'
),
router
,
apolloProvider
,
render
(
h
)
{
return
h
(
LastCommit
,
{
props
:
{
currentPath
:
this
.
$route
.
params
.
path
,
},
});
},
});
if
(
window
.
gl
.
startup_graphql_calls
)
{
const
query
=
window
.
gl
.
startup_graphql_calls
.
find
(
call
=>
call
.
operationName
===
'
pathLastCommit
'
,
);
query
.
fetchCall
.
then
(
res
=>
res
.
json
())
.
then
(
res
=>
{
apolloProvider
.
clients
.
defaultClient
.
writeQuery
({
query
:
PathLastCommitQuery
,
data
:
res
.
data
,
variables
:
{
projectPath
,
ref
,
path
:
currentRoutePath
,
},
});
})
.
catch
(()
=>
{})
.
finally
(()
=>
initLastCommitApp
());
}
else
{
initLastCommitApp
();
}
router
.
afterEach
(({
params
:
{
path
}
})
=>
{
setTitle
(
path
,
ref
,
fullName
);
});
...
...
@@ -77,20 +119,6 @@ export default function setupVueRepositoryList() {
});
}
// eslint-disable-next-line no-new
new
Vue
({
el
:
document
.
getElementById
(
'
js-last-commit
'
),
router
,
apolloProvider
,
render
(
h
)
{
return
h
(
LastCommit
,
{
props
:
{
currentPath
:
this
.
$route
.
params
.
path
,
},
});
},
});
const
treeHistoryLinkEl
=
document
.
getElementById
(
'
js-tree-history-link
'
);
const
{
historyLink
}
=
treeHistoryLinkEl
.
dataset
;
...
...
app/assets/javascripts/repository/queries/path_last_commit.query.graphql
View file @
927eb3fd
query
pathLastCommit
(
$projectPath
:
ID
!,
$path
:
String
,
$ref
:
String
!)
{
project
(
fullPath
:
$projectPath
)
{
__typename
repository
{
__typename
tree
(
path
:
$path
,
ref
:
$ref
)
{
__typename
lastCommit
{
__typename
sha
title
titleHtml
...
...
@@ -13,15 +17,20 @@ query pathLastCommit($projectPath: ID!, $path: String, $ref: String!) {
authorName
authorGravatar
author
{
__typename
name
avatarUrl
webPath
}
signatureHtml
pipelines
(
ref
:
$ref
,
first
:
1
)
{
__typename
edges
{
__typename
node
{
__typename
detailedStatus
{
__typename
detailsPath
icon
tooltip
...
...
app/helpers/startupjs_helper.rb
0 → 100644
View file @
927eb3fd
# frozen_string_literal: true
module
StartupjsHelper
def
page_startup_graphql_calls
@graphql_startup_calls
end
def
add_page_startup_graphql_call
(
query
,
variables
=
{})
@graphql_startup_calls
||=
[]
query_str
=
File
.
read
(
File
.
join
(
Rails
.
root
,
"app/assets/javascripts/
#{
query
}
.query.graphql"
))
@graphql_startup_calls
<<
{
query:
query_str
,
variables:
variables
}
end
end
app/views/layouts/_startup_js.html.haml
View file @
927eb3fd
-
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)
})
}))
}
app/views/projects/tree/show.html.haml
View file @
927eb3fd
-
current_route_path
=
request
.
fullpath
.
match
(
/-\/tree\/[^\/]+\/(.+$)/
).
to_a
[
1
]
-
add_page_startup_graphql_call
(
'repository/queries/path_last_commit'
,
{
projectPath:
@project
.
full_path
,
ref:
current_ref
,
currentRoutePath:
current_route_path
})
-
breadcrumb_title
_
(
"Repository"
)
-
@content_class
=
"limit-container-width"
unless
fluid_layout
...
...
spec/helpers/startupjs_helper_spec.rb
0 → 100644
View file @
927eb3fd
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
StartupjsHelper
do
describe
'#page_startup_graphql_calls'
do
let
(
:query_location
)
{
'repository/queries/path_last_commit'
}
let
(
:query_content
)
do
File
.
read
(
File
.
join
(
Rails
.
root
,
'app/assets/javascripts'
,
"
#{
query_location
}
.query.graphql"
))
end
it
'returns an array containing GraphQL Page Startup Calls'
do
helper
.
add_page_startup_graphql_call
(
query_location
,
{
ref:
'foo'
})
startup_graphql_calls
=
helper
.
page_startup_graphql_calls
expect
(
startup_graphql_calls
).
to
include
({
query:
query_content
,
variables:
{
ref:
'foo'
}
})
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