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
8d7d7acf
Commit
8d7d7acf
authored
Jun 02, 2020
by
Bob Van Landuyt
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ajk-full-path-resolver' into 'master'
Add full-path loader See merge request gitlab-org/gitlab!33299
parents
f6d1e7d2
56b2638f
Changes
17
Show whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
99 additions
and
66 deletions
+99
-66
app/finders/issuable_finder/params.rb
app/finders/issuable_finder/params.rb
+7
-3
app/graphql/mutations/alert_management/base.rb
app/graphql/mutations/alert_management/base.rb
+1
-1
app/graphql/mutations/branches/create.rb
app/graphql/mutations/branches/create.rb
+1
-1
app/graphql/mutations/commits/create.rb
app/graphql/mutations/commits/create.rb
+1
-1
app/graphql/mutations/concerns/mutations/resolves_issuable.rb
...graphql/mutations/concerns/mutations/resolves_issuable.rb
+5
-2
app/graphql/mutations/concerns/mutations/resolves_project.rb
app/graphql/mutations/concerns/mutations/resolves_project.rb
+0
-15
app/graphql/mutations/jira_import/start.rb
app/graphql/mutations/jira_import/start.rb
+1
-1
app/graphql/mutations/merge_requests/create.rb
app/graphql/mutations/merge_requests/create.rb
+1
-1
app/graphql/mutations/snippets/create.rb
app/graphql/mutations/snippets/create.rb
+1
-1
app/graphql/resolvers/concerns/resolves_project.rb
app/graphql/resolvers/concerns/resolves_project.rb
+15
-0
app/graphql/resolvers/full_path_resolver.rb
app/graphql/resolvers/full_path_resolver.rb
+1
-6
ee/app/graphql/mutations/requirements_management/create_requirement.rb
...l/mutations/requirements_management/create_requirement.rb
+1
-1
ee/app/graphql/mutations/requirements_management/update_requirement.rb
...l/mutations/requirements_management/update_requirement.rb
+1
-1
lib/gitlab/graphql/loaders/full_path_model_loader.rb
lib/gitlab/graphql/loaders/full_path_model_loader.rb
+26
-0
spec/graphql/mutations/concerns/mutations/resolves_project_spec.rb
...hql/mutations/concerns/mutations/resolves_project_spec.rb
+0
-22
spec/graphql/resolvers/concerns/resolves_project_spec.rb
spec/graphql/resolvers/concerns/resolves_project_spec.rb
+37
-0
spec/support/shared_examples/graphql/resolves_issuable_shared_examples.rb
...red_examples/graphql/resolves_issuable_shared_examples.rb
+0
-10
No files found.
app/finders/issuable_finder/params.rb
View file @
8d7d7acf
...
...
@@ -105,7 +105,7 @@ class IssuableFinder
end
def
project?
p
arams
[
:project_id
]
.
present?
p
roject_id
.
present?
end
def
group
...
...
@@ -132,15 +132,19 @@ class IssuableFinder
def
project
strong_memoize
(
:project
)
do
next
nil
unless
p
arams
[
:project_id
].
presen
t?
next
nil
unless
p
rojec
t?
project
=
Project
.
find
(
params
[
:project_id
]
)
project
=
project_id
.
is_a?
(
Project
)
?
project_id
:
Project
.
find
(
project_id
)
project
=
nil
unless
Ability
.
allowed?
(
current_user
,
:"read_
#{
klass
.
to_ability_name
}
"
,
project
)
project
end
end
def
project_id
params
[
:project_id
]
end
def
projects
strong_memoize
(
:projects
)
do
next
[
project
]
if
project?
...
...
app/graphql/mutations/alert_management/base.rb
View file @
8d7d7acf
...
...
@@ -3,7 +3,7 @@
module
Mutations
module
AlertManagement
class
Base
<
BaseMutation
include
Mutations
::
ResolvesProject
include
ResolvesProject
argument
:project_path
,
GraphQL
::
ID_TYPE
,
required:
true
,
...
...
app/graphql/mutations/branches/create.rb
View file @
8d7d7acf
...
...
@@ -3,7 +3,7 @@
module
Mutations
module
Branches
class
Create
<
BaseMutation
include
Mutations
::
ResolvesProject
include
ResolvesProject
graphql_name
'CreateBranch'
...
...
app/graphql/mutations/commits/create.rb
View file @
8d7d7acf
...
...
@@ -3,7 +3,7 @@
module
Mutations
module
Commits
class
Create
<
BaseMutation
include
Mutations
::
ResolvesProject
include
ResolvesProject
graphql_name
'CommitCreate'
...
...
app/graphql/mutations/concerns/mutations/resolves_issuable.rb
View file @
8d7d7acf
...
...
@@ -3,7 +3,10 @@
module
Mutations
module
ResolvesIssuable
extend
ActiveSupport
::
Concern
include
Mutations
::
ResolvesProject
included
do
include
ResolvesProject
end
def
resolve_issuable
(
type
:,
parent_path
:,
iid
:)
parent
=
resolve_issuable_parent
(
type
,
parent_path
)
...
...
@@ -29,7 +32,7 @@ module Mutations
def
resolve_issuable_parent
(
type
,
parent_path
)
return
unless
type
==
:issue
||
type
==
:merge_request
resolve_project
(
full_path:
parent_path
)
resolve_project
(
full_path:
parent_path
)
if
parent_path
.
present?
end
end
end
...
...
app/graphql/mutations/concerns/mutations/resolves_project.rb
deleted
100644 → 0
View file @
f6d1e7d2
# frozen_string_literal: true
module
Mutations
module
ResolvesProject
extend
ActiveSupport
::
Concern
def
resolve_project
(
full_path
:)
project_resolver
.
resolve
(
full_path:
full_path
)
end
def
project_resolver
Resolvers
::
ProjectResolver
.
new
(
object:
nil
,
context:
context
,
field:
nil
)
end
end
end
app/graphql/mutations/jira_import/start.rb
View file @
8d7d7acf
...
...
@@ -3,7 +3,7 @@
module
Mutations
module
JiraImport
class
Start
<
BaseMutation
include
Mutations
::
ResolvesProject
include
ResolvesProject
graphql_name
'JiraImportStart'
...
...
app/graphql/mutations/merge_requests/create.rb
View file @
8d7d7acf
...
...
@@ -3,7 +3,7 @@
module
Mutations
module
MergeRequests
class
Create
<
BaseMutation
include
Mutations
::
ResolvesProject
include
ResolvesProject
graphql_name
'MergeRequestCreate'
...
...
app/graphql/mutations/snippets/create.rb
View file @
8d7d7acf
...
...
@@ -3,7 +3,7 @@
module
Mutations
module
Snippets
class
Create
<
BaseMutation
include
Mutations
::
ResolvesProject
include
ResolvesProject
graphql_name
'CreateSnippet'
...
...
app/graphql/resolvers/concerns/resolves_project.rb
0 → 100644
View file @
8d7d7acf
# frozen_string_literal: true
module
ResolvesProject
def
resolve_project
(
full_path:
nil
,
project_id:
nil
)
unless
full_path
.
present?
^
project_id
.
present?
raise
::
Gitlab
::
Graphql
::
Errors
::
ArgumentError
,
'Incompatible arguments: projectId, projectPath.'
end
if
full_path
.
present?
::
Gitlab
::
Graphql
::
Loaders
::
FullPathModelLoader
.
new
(
Project
,
full_path
).
find
else
::
GitlabSchema
.
object_from_id
(
project_id
,
expected_type:
Project
)
end
end
end
app/graphql/resolvers/full_path_resolver.rb
View file @
8d7d7acf
...
...
@@ -11,12 +11,7 @@ module Resolvers
end
def
model_by_full_path
(
model
,
full_path
)
BatchLoader
::
GraphQL
.
for
(
full_path
).
batch
(
key:
model
)
do
|
full_paths
,
loader
,
args
|
# `with_route` avoids an N+1 calculating full_path
args
[
:key
].
where_full_path_in
(
full_paths
).
with_route
.
each
do
|
model_instance
|
loader
.
call
(
model_instance
.
full_path
,
model_instance
)
end
end
::
Gitlab
::
Graphql
::
Loaders
::
FullPathModelLoader
.
new
(
model
,
full_path
).
find
end
end
end
ee/app/graphql/mutations/requirements_management/create_requirement.rb
View file @
8d7d7acf
...
...
@@ -3,7 +3,7 @@
module
Mutations
module
RequirementsManagement
class
CreateRequirement
<
BaseMutation
include
Mutations
::
ResolvesProject
include
ResolvesProject
graphql_name
'CreateRequirement'
...
...
ee/app/graphql/mutations/requirements_management/update_requirement.rb
View file @
8d7d7acf
...
...
@@ -3,7 +3,7 @@
module
Mutations
module
RequirementsManagement
class
UpdateRequirement
<
BaseMutation
include
Mutations
::
ResolvesProject
include
ResolvesProject
graphql_name
'UpdateRequirement'
...
...
lib/gitlab/graphql/loaders/full_path_model_loader.rb
0 → 100644
View file @
8d7d7acf
# frozen_string_literal: true
module
Gitlab
module
Graphql
module
Loaders
# Suitable for use to find resources that expose `where_full_path_in`,
# such as Project, Group, Namespace
class
FullPathModelLoader
attr_reader
:model_class
,
:full_path
def
initialize
(
model_class
,
full_path
)
@model_class
,
@full_path
=
model_class
,
full_path
end
def
find
BatchLoader
::
GraphQL
.
for
(
full_path
).
batch
(
key:
model_class
)
do
|
full_paths
,
loader
,
args
|
# `with_route` avoids an N+1 calculating full_path
args
[
:key
].
where_full_path_in
(
full_paths
).
with_route
.
each
do
|
model_instance
|
loader
.
call
(
model_instance
.
full_path
,
model_instance
)
end
end
end
end
end
end
end
spec/graphql/mutations/concerns/mutations/resolves_project_spec.rb
deleted
100644 → 0
View file @
f6d1e7d2
# frozen_string_literal: true
require
'spec_helper'
describe
Mutations
::
ResolvesProject
do
let
(
:mutation_class
)
do
Class
.
new
(
Mutations
::
BaseMutation
)
do
include
Mutations
::
ResolvesProject
end
end
let
(
:context
)
{
double
}
subject
(
:mutation
)
{
mutation_class
.
new
(
object:
nil
,
context:
context
,
field:
nil
)
}
it
'uses the ProjectsResolver to resolve projects by path'
do
project
=
create
(
:project
)
expect
(
Resolvers
::
ProjectResolver
).
to
receive
(
:new
).
with
(
object:
nil
,
context:
context
,
field:
nil
).
and_call_original
expect
(
mutation
.
resolve_project
(
full_path:
project
.
full_path
).
sync
).
to
eq
(
project
)
end
end
spec/graphql/resolvers/concerns/resolves_project_spec.rb
0 → 100644
View file @
8d7d7acf
# frozen_string_literal: true
require
'spec_helper'
describe
ResolvesProject
do
include
GraphqlHelpers
let
(
:implementing_class
)
do
Class
.
new
do
include
ResolvesProject
end
end
subject
(
:instance
)
{
implementing_class
.
new
}
let_it_be
(
:project
)
{
create
(
:project
)
}
it
'can resolve projects by path'
do
expect
(
sync
(
instance
.
resolve_project
(
full_path:
project
.
full_path
))).
to
eq
(
project
)
end
it
'can resolve projects by id'
do
expect
(
sync
(
instance
.
resolve_project
(
project_id:
global_id_of
(
project
)))).
to
eq
(
project
)
end
it
'complains when both are present'
do
expect
do
instance
.
resolve_project
(
full_path:
project
.
full_path
,
project_id:
global_id_of
(
project
))
end
.
to
raise_error
(
::
Gitlab
::
Graphql
::
Errors
::
ArgumentError
)
end
it
'complains when neither is present'
do
expect
do
instance
.
resolve_project
(
full_path:
nil
,
project_id:
nil
)
end
.
to
raise_error
(
::
Gitlab
::
Graphql
::
Errors
::
ArgumentError
)
end
end
spec/support/shared_examples/graphql/resolves_issuable_shared_examples.rb
View file @
8d7d7acf
...
...
@@ -29,16 +29,6 @@ RSpec.shared_examples 'resolving an issuable in GraphQL' do |type|
subject
end
it
'uses correct Resolver to resolve issuable parent'
do
resolver_class
=
type
==
:epic
?
'Resolvers::GroupResolver'
:
'Resolvers::ProjectResolver'
expect
(
resolver_class
.
constantize
).
to
receive
(
:new
)
.
with
(
object:
nil
,
context:
context
,
field:
nil
)
.
and_call_original
subject
end
it
'returns nil if issuable is not found'
do
result
=
mutation
.
resolve_issuable
(
type:
type
,
parent_path:
parent
.
full_path
,
iid:
"100"
)
result
=
result
.
respond_to?
(
:sync
)
?
result
.
sync
:
result
...
...
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