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
ba9abda3
Commit
ba9abda3
authored
Mar 05, 2021
by
Nicolò Maria Mezzopera
Committed by
Alex Kalderimis
Mar 05, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new group_packages_resolver
- source - tests
parent
8361d840
Changes
12
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
201 additions
and
61 deletions
+201
-61
app/graphql/resolvers/group_packages_resolver.rb
app/graphql/resolvers/group_packages_resolver.rb
+27
-0
app/graphql/resolvers/project_packages_resolver.rb
app/graphql/resolvers/project_packages_resolver.rb
+1
-1
app/graphql/types/group_type.rb
app/graphql/types/group_type.rb
+4
-0
app/graphql/types/project_type.rb
app/graphql/types/project_type.rb
+1
-1
changelogs/unreleased/285467-package-registry-graphql-api.yml
...gelogs/unreleased/285467-package-registry-graphql-api.yml
+5
-0
doc/api/graphql/reference/index.md
doc/api/graphql/reference/index.md
+1
-0
spec/graphql/resolvers/group_packages_resolver_spec.rb
spec/graphql/resolvers/group_packages_resolver_spec.rb
+18
-0
spec/graphql/resolvers/project_packages_resolver_spec.rb
spec/graphql/resolvers/project_packages_resolver_spec.rb
+1
-1
spec/graphql/types/group_type_spec.rb
spec/graphql/types/group_type_spec.rb
+1
-0
spec/requests/api/graphql/group/packages_spec.rb
spec/requests/api/graphql/group/packages_spec.rb
+78
-0
spec/requests/api/graphql/project/packages_spec.rb
spec/requests/api/graphql/project/packages_spec.rb
+13
-58
spec/support/shared_examples/requests/api/graphql/packages/group_and_project_packages_list_shared_examples.rb
...ckages/group_and_project_packages_list_shared_examples.rb
+51
-0
No files found.
app/graphql/resolvers/group_packages_resolver.rb
0 → 100644
View file @
ba9abda3
# frozen_string_literal: true
module
Resolvers
class
GroupPackagesResolver
<
BaseResolver
type
Types
::
Packages
::
PackageType
.
connection_type
,
null:
true
def
ready?
(
**
args
)
context
[
self
.
class
]
||=
{
executions:
0
}
context
[
self
.
class
][
:executions
]
+=
1
raise
GraphQL
::
ExecutionError
,
"Packages can be requested only for one group at a time"
if
context
[
self
.
class
][
:executions
]
>
1
super
end
def
resolve
(
**
args
)
return
unless
packages_available?
::
Packages
::
GroupPackagesFinder
.
new
(
current_user
,
object
).
execute
end
private
def
packages_available?
::
Gitlab
.
config
.
packages
.
enabled
end
end
end
app/graphql/resolvers/packages_resolver.rb
→
app/graphql/resolvers/p
roject_p
ackages_resolver.rb
View file @
ba9abda3
# frozen_string_literal: true
module
Resolvers
class
PackagesResolver
<
BaseResolver
class
P
rojectP
ackagesResolver
<
BaseResolver
type
Types
::
Packages
::
PackageType
.
connection_type
,
null:
true
def
resolve
(
**
args
)
...
...
app/graphql/types/group_type.rb
View file @
ba9abda3
...
...
@@ -95,6 +95,10 @@ module Types
field
:container_repositories_count
,
GraphQL
::
INT_TYPE
,
null:
false
,
description:
'Number of container repositories in the group.'
field
:packages
,
description:
'Packages of the group.'
,
resolver:
Resolvers
::
GroupPackagesResolver
def
label
(
title
:)
BatchLoader
::
GraphQL
.
for
(
title
).
batch
(
key:
group
)
do
|
titles
,
loader
,
args
|
LabelsFinder
...
...
app/graphql/types/project_type.rb
View file @
ba9abda3
...
...
@@ -181,7 +181,7 @@ module Types
field
:packages
,
description:
'Packages of the project.'
,
resolver:
Resolvers
::
PackagesResolver
resolver:
Resolvers
::
P
rojectP
ackagesResolver
field
:pipelines
,
null:
true
,
...
...
changelogs/unreleased/285467-package-registry-graphql-api.yml
0 → 100644
View file @
ba9abda3
---
title
:
Add package list to group graphql type
merge_request
:
54672
author
:
type
:
added
doc/api/graphql/reference/index.md
View file @
ba9abda3
...
...
@@ -2215,6 +2215,7 @@ Autogenerated return type of GitlabSubscriptionActivate.
|
`milestones`
| MilestoneConnection | Milestones of the group. |
|
`name`
| String! | Name of the namespace. |
|
`packageSettings`
| PackageSettings | The package settings for the namespace. |
|
`packages`
| PackageConnection | Packages of the group. |
|
`parent`
| Group | Parent group. |
|
`path`
| String! | Path of the namespace. |
|
`projectCreationLevel`
| String | The permission level required to create projects in the group. |
...
...
spec/graphql/resolvers/group_packages_resolver_spec.rb
0 → 100644
View file @
ba9abda3
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Resolvers
::
GroupPackagesResolver
do
include
GraphqlHelpers
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:group
)
{
create
(
:group
,
:public
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:public
,
group:
group
)
}
let_it_be
(
:package
)
{
create
(
:package
,
project:
project
)
}
describe
'#resolve'
do
subject
(
:packages
)
{
resolve
(
described_class
,
ctx:
{
current_user:
user
},
obj:
group
)
}
it
{
is_expected
.
to
contain_exactly
(
package
)
}
end
end
spec/graphql/resolvers/packages_resolver_spec.rb
→
spec/graphql/resolvers/p
roject_p
ackages_resolver_spec.rb
View file @
ba9abda3
...
...
@@ -2,7 +2,7 @@
require
'spec_helper'
RSpec
.
describe
Resolvers
::
PackagesResolver
do
RSpec
.
describe
Resolvers
::
P
rojectP
ackagesResolver
do
include
GraphqlHelpers
let_it_be
(
:user
)
{
create
(
:user
)
}
...
...
spec/graphql/types/group_type_spec.rb
View file @
ba9abda3
...
...
@@ -18,6 +18,7 @@ RSpec.describe GitlabSchema.types['Group'] do
two_factor_grace_period auto_devops_enabled emails_disabled
mentions_disabled parent boards milestones group_members
merge_requests container_repositories container_repositories_count
packages
]
expect
(
described_class
).
to
include_graphql_fields
(
*
expected_fields
)
...
...
spec/requests/api/graphql/group/packages_spec.rb
0 → 100644
View file @
ba9abda3
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
'getting a package list for a group'
do
include
GraphqlHelpers
let_it_be
(
:resource
)
{
create
(
:group
,
:private
)
}
let_it_be
(
:group_two
)
{
create
(
:group
,
:private
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:repository
,
group:
resource
)
}
let_it_be
(
:another_project
)
{
create
(
:project
,
:repository
,
group:
resource
)
}
let_it_be
(
:group_two_project
)
{
create
(
:project
,
:repository
,
group:
group_two
)
}
let_it_be
(
:current_user
)
{
create
(
:user
)
}
let_it_be
(
:package
)
{
create
(
:package
,
project:
project
)
}
let_it_be
(
:npm_package
)
{
create
(
:npm_package
,
project:
group_two_project
)
}
let_it_be
(
:maven_package
)
{
create
(
:maven_package
,
project:
project
)
}
let_it_be
(
:debian_package
)
{
create
(
:debian_package
,
project:
another_project
)
}
let_it_be
(
:composer_package
)
{
create
(
:composer_package
,
project:
another_project
)
}
let_it_be
(
:composer_metadatum
)
do
create
(
:composer_metadatum
,
package:
composer_package
,
target_sha:
'afdeh'
,
composer_json:
{
name:
'x'
,
type:
'y'
,
license:
'z'
,
version:
1
})
end
let
(
:package_names
)
{
graphql_data_at
(
:group
,
:packages
,
:nodes
,
:name
)
}
let
(
:target_shas
)
{
graphql_data_at
(
:group
,
:packages
,
:nodes
,
:metadata
,
:target_sha
)
}
let
(
:packages
)
{
graphql_data_at
(
:group
,
:packages
,
:nodes
)
}
let
(
:fields
)
do
<<~
QUERY
nodes {
#{
all_graphql_fields_for
(
'packages'
.
classify
,
excluded:
[
'project'
])
}
metadata {
#{
query_graphql_fragment
(
'ComposerMetadata'
)
}
}
}
QUERY
end
let
(
:query
)
do
graphql_query_for
(
'group'
,
{
'fullPath'
=>
resource
.
full_path
},
query_graphql_field
(
'packages'
,
{},
fields
)
)
end
it_behaves_like
'group and project packages query'
context
'with a batched query'
do
let
(
:batch_query
)
do
<<~
QUERY
{
a: group(fullPath: "
#{
resource
.
full_path
}
") { packages { nodes { name } } }
b: group(fullPath: "
#{
group_two
.
full_path
}
") { packages { nodes { name } } }
}
QUERY
end
let
(
:a_packages_names
)
{
graphql_data_at
(
:a
,
:packages
,
:nodes
,
:name
)
}
before
do
resource
.
add_reporter
(
current_user
)
group_two
.
add_reporter
(
current_user
)
post_graphql
(
batch_query
,
current_user:
current_user
)
end
it
'returns an error for the second group and data for the first'
do
expect
(
a_packages_names
).
to
contain_exactly
(
package
.
name
,
maven_package
.
name
,
debian_package
.
name
,
composer_package
.
name
)
expect_graphql_errors_to_include
[
/Packages can be requested only for one group at a time/
]
expect
(
graphql_data_at
(
:b
,
:packages
)).
to
be
(
nil
)
end
end
end
spec/requests/api/graphql/project/packages_spec.rb
View file @
ba9abda3
...
...
@@ -5,84 +5,39 @@ require 'spec_helper'
RSpec
.
describe
'getting a package list for a project'
do
include
GraphqlHelpers
let_it_be
(
:
project
)
{
create
(
:project
,
:repository
)
}
let_it_be
(
:
resource
)
{
create
(
:project
,
:repository
)
}
let_it_be
(
:current_user
)
{
create
(
:user
)
}
let_it_be
(
:package
)
{
create
(
:package
,
project:
project
)
}
let_it_be
(
:maven_package
)
{
create
(
:maven_package
,
project:
project
)
}
let_it_be
(
:debian_package
)
{
create
(
:debian_package
,
project:
project
)
}
let_it_be
(
:composer_package
)
{
create
(
:composer_package
,
project:
project
)
}
let_it_be
(
:package
)
{
create
(
:package
,
project:
resource
)
}
let_it_be
(
:maven_package
)
{
create
(
:maven_package
,
project:
resource
)
}
let_it_be
(
:debian_package
)
{
create
(
:debian_package
,
project:
resource
)
}
let_it_be
(
:composer_package
)
{
create
(
:composer_package
,
project:
resource
)
}
let_it_be
(
:composer_metadatum
)
do
create
(
:composer_metadatum
,
package:
composer_package
,
target_sha:
'afdeh'
,
composer_json:
{
name:
'x'
,
type:
'y'
,
license:
'z'
,
version:
1
})
end
let
(
:package_names
)
{
graphql_data_at
(
:project
,
:packages
,
:edges
,
:node
,
:name
)
}
let
(
:package_names
)
{
graphql_data_at
(
:project
,
:packages
,
:nodes
,
:name
)
}
let
(
:target_shas
)
{
graphql_data_at
(
:project
,
:packages
,
:nodes
,
:metadata
,
:target_sha
)
}
let
(
:packages
)
{
graphql_data_at
(
:project
,
:packages
,
:nodes
)
}
let
(
:fields
)
do
<<~
QUERY
edges {
node {
nodes {
#{
all_graphql_fields_for
(
'packages'
.
classify
,
excluded:
[
'project'
])
}
metadata {
#{
query_graphql_fragment
(
'ComposerMetadata'
)
}
}
}
}
QUERY
end
let
(
:query
)
do
graphql_query_for
(
'project'
,
{
'fullPath'
=>
project
.
full_path
},
{
'fullPath'
=>
resource
.
full_path
},
query_graphql_field
(
'packages'
,
{},
fields
)
)
end
context
'when user has access to the project'
do
before
do
project
.
add_reporter
(
current_user
)
post_graphql
(
query
,
current_user:
current_user
)
end
it_behaves_like
'a working graphql query'
it
'returns packages successfully'
do
expect
(
package_names
).
to
contain_exactly
(
package
.
name
,
maven_package
.
name
,
debian_package
.
name
,
composer_package
.
name
)
end
it
'deals with metadata'
do
target_shas
=
graphql_data_at
(
:project
,
:packages
,
:edges
,
:node
,
:metadata
,
:target_sha
)
expect
(
target_shas
).
to
contain_exactly
(
composer_metadatum
.
target_sha
)
end
end
context
'when the user does not have access to the project/packages'
do
before
do
post_graphql
(
query
,
current_user:
current_user
)
end
it_behaves_like
'a working graphql query'
it
'returns nil'
do
expect
(
graphql_data
[
'project'
]).
to
be_nil
end
end
context
'when the user is not authenticated'
do
before
do
post_graphql
(
query
)
end
it_behaves_like
'a working graphql query'
it
'returns nil'
do
expect
(
graphql_data
[
'project'
]).
to
be_nil
end
end
it_behaves_like
'group and project packages query'
end
spec/support/shared_examples/requests/api/graphql/packages/group_and_project_packages_list_shared_examples.rb
0 → 100644
View file @
ba9abda3
# frozen_string_literal: true
RSpec
.
shared_examples
'group and project packages query'
do
include
GraphqlHelpers
context
'when user has access to the resource'
do
before
do
resource
.
add_reporter
(
current_user
)
post_graphql
(
query
,
current_user:
current_user
)
end
it_behaves_like
'a working graphql query'
it
'returns packages successfully'
do
expect
(
package_names
).
to
contain_exactly
(
package
.
name
,
maven_package
.
name
,
debian_package
.
name
,
composer_package
.
name
)
end
it
'deals with metadata'
do
expect
(
target_shas
).
to
contain_exactly
(
composer_metadatum
.
target_sha
)
end
end
context
'when the user does not have access to the resource'
do
before
do
post_graphql
(
query
,
current_user:
current_user
)
end
it_behaves_like
'a working graphql query'
it
'returns nil'
do
expect
(
packages
).
to
be_nil
end
end
context
'when the user is not authenticated'
do
before
do
post_graphql
(
query
)
end
it_behaves_like
'a working graphql query'
it
'returns nil'
do
expect
(
packages
).
to
be_nil
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