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
4e36caa5
Commit
4e36caa5
authored
Nov 19, 2021
by
Vitali Tatarintev
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'ajk-base-edge' into 'master'
Add BaseEdge base class See merge request gitlab-org/gitlab!71476
parents
e8c59dbe
28e7d8c2
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
113 additions
and
7 deletions
+113
-7
app/graphql/types/base_edge.rb
app/graphql/types/base_edge.rb
+7
-0
app/graphql/types/base_field.rb
app/graphql/types/base_field.rb
+2
-0
app/graphql/types/base_object.rb
app/graphql/types/base_object.rb
+1
-0
app/graphql/types/ci/runner_web_url_edge.rb
app/graphql/types/ci/runner_web_url_edge.rb
+1
-1
ee/spec/requests/api/graphql/project/pipelines/dast_profile_spec.rb
...quests/api/graphql/project/pipelines/dast_profile_spec.rb
+1
-1
rubocop/cop/graphql/authorize_types.rb
rubocop/cop/graphql/authorize_types.rb
+1
-1
spec/graphql/types/base_edge_spec.rb
spec/graphql/types/base_edge_spec.rb
+76
-0
spec/requests/api/graphql/packages/package_spec.rb
spec/requests/api/graphql/packages/package_spec.rb
+1
-1
spec/support/helpers/graphql_helpers.rb
spec/support/helpers/graphql_helpers.rb
+7
-2
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
+1
-1
spec/support_specs/helpers/graphql_helpers_spec.rb
spec/support_specs/helpers/graphql_helpers_spec.rb
+15
-0
No files found.
app/graphql/types/base_edge.rb
0 → 100644
View file @
4e36caa5
# frozen_string_literal: true
module
Types
class
BaseEdge
<
GraphQL
::
Types
::
Relay
::
BaseEdge
field_class
Types
::
BaseField
end
end
app/graphql/types/base_field.rb
View file @
4e36caa5
...
...
@@ -78,6 +78,8 @@ module Types
attr_reader
:feature_flag
def
field_authorized?
(
object
,
ctx
)
object
=
object
.
node
if
object
.
is_a?
(
GraphQL
::
Pagination
::
Connection
::
Edge
)
authorization
.
ok?
(
object
,
ctx
[
:current_user
])
end
...
...
app/graphql/types/base_object.rb
View file @
4e36caa5
...
...
@@ -7,6 +7,7 @@ module Types
prepend
Gitlab
::
Graphql
::
MarkdownField
field_class
Types
::
BaseField
edge_type_class
Types
::
BaseEdge
def
self
.
accepts
(
*
types
)
@accepts
||=
[]
...
...
app/graphql/types/ci/runner_web_url_edge.rb
View file @
4e36caa5
...
...
@@ -3,7 +3,7 @@
module
Types
module
Ci
# rubocop: disable Graphql/AuthorizeTypes
class
RunnerWebUrlEdge
<
GraphQL
::
Types
::
Relay
::
BaseEdge
class
RunnerWebUrlEdge
<
::
Types
::
BaseEdge
include
FindClosest
field
:web_url
,
GraphQL
::
Types
::
String
,
null:
true
,
...
...
ee/spec/requests/api/graphql/project/pipelines/dast_profile_spec.rb
View file @
4e36caa5
...
...
@@ -85,7 +85,7 @@ RSpec.describe 'Query.project(fullPath).pipelines.dastProfile' do
subject
expect
(
dast_profile_data
).
to
be_empty
expect
(
dast_profile_data
).
to
contain_exactly
(
nil
)
end
end
end
...
...
rubocop/cop/graphql/authorize_types.rb
View file @
4e36caa5
...
...
@@ -8,7 +8,7 @@ module RuboCop
'https://docs.gitlab.com/ee/development/api_graphql_styleguide.html#type-authorization'
# We want to exclude our own basetypes and scalars
ALLOWED_TYPES
=
%w[BaseEnum BaseScalar BasePermissionType MutationType SubscriptionType
ALLOWED_TYPES
=
%w[BaseEnum Base
Edge Base
Scalar BasePermissionType MutationType SubscriptionType
QueryType GraphQL::Schema BaseUnion BaseInputObject]
.
freeze
def_node_search
:authorize?
,
<<~
PATTERN
...
...
spec/graphql/types/base_edge_spec.rb
0 → 100644
View file @
4e36caa5
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Types
::
BaseEdge
do
include
GraphqlHelpers
let_it_be
(
:test_schema
)
do
project_edge_type
=
Class
.
new
(
described_class
)
do
field
:proof_of_admin_rights
,
String
,
null:
true
,
authorize: :admin_project
def
proof_of_admin_rights
'ok'
end
end
project_type
=
Class
.
new
(
::
Types
::
BaseObject
)
do
graphql_name
'Project'
authorize
:read_project
edge_type_class
project_edge_type
field
:name
,
String
,
null:
false
end
Class
.
new
(
GraphQL
::
Schema
)
do
lazy_resolve
::
Gitlab
::
Graphql
::
Lazy
,
:force
use
::
GraphQL
::
Pagination
::
Connections
use
::
Gitlab
::
Graphql
::
Pagination
::
Connections
query
(
Class
.
new
(
::
Types
::
BaseObject
)
do
graphql_name
'Query'
field
:projects
,
project_type
.
connection_type
,
null:
false
def
projects
context
[
:projects
]
end
end
)
end
end
def
document
GraphQL
.
parse
(
<<~
GQL
)
query {
projects {
edges {
proofOfAdminRights
node { name }
}
}
}
GQL
end
it
'supports field authorization on edge fields'
do
user
=
create
(
:user
)
private_project
=
create
(
:project
,
:private
)
member_project
=
create
(
:project
,
:private
)
maintainer_project
=
create
(
:project
,
:private
)
public_project
=
create
(
:project
,
:public
)
member_project
.
add_developer
(
user
)
maintainer_project
.
add_maintainer
(
user
)
projects
=
[
private_project
,
member_project
,
maintainer_project
,
public_project
]
data
=
{
current_user:
user
,
projects:
projects
}
query
=
GraphQL
::
Query
.
new
(
test_schema
,
document:
document
,
context:
data
)
result
=
query
.
result
.
to_h
expect
(
graphql_dig_at
(
result
,
'data'
,
'projects'
,
'edges'
,
'node'
,
'name'
))
.
to
contain_exactly
(
member_project
.
name
,
maintainer_project
.
name
,
public_project
.
name
)
expect
(
graphql_dig_at
(
result
,
'data'
,
'projects'
,
'edges'
,
'proofOfAdminRights'
))
.
to
contain_exactly
(
nil
,
'ok'
,
nil
)
end
end
spec/requests/api/graphql/packages/package_spec.rb
View file @
4e36caa5
...
...
@@ -68,7 +68,7 @@ RSpec.describe 'package details' do
subject
expect
(
graphql_data_at
(
:package
,
:versions
,
:nodes
,
:version
)).
to
be_present
expect
(
graphql_data_at
(
:package
,
:versions
,
:nodes
,
:versions
,
:nodes
)).
to
be_empty
expect
(
graphql_data_at
(
:package
,
:versions
,
:nodes
,
:versions
,
:nodes
)).
to
eq
[
nil
,
nil
]
end
end
end
...
...
spec/support/helpers/graphql_helpers.rb
View file @
4e36caa5
...
...
@@ -514,8 +514,13 @@ module GraphqlHelpers
# Allows for array indexing, like this
# ['project', 'boards', 'edges', 0, 'node', 'lists']
keys
.
reduce
(
data
)
do
|
memo
,
key
|
if
memo
.
is_a?
(
Array
)
key
.
is_a?
(
Integer
)
?
memo
[
key
]
:
memo
.
flat_map
{
|
e
|
Array
.
wrap
(
e
[
key
])
}
if
memo
.
is_a?
(
Array
)
&&
key
.
is_a?
(
Integer
)
memo
[
key
]
elsif
memo
.
is_a?
(
Array
)
memo
.
compact
.
flat_map
do
|
e
|
x
=
e
[
key
]
x
.
nil?
?
[
x
]
:
Array
.
wrap
(
x
)
end
else
memo
&
.
dig
(
key
)
end
...
...
spec/support/shared_examples/requests/api/graphql/packages/group_and_project_packages_list_shared_examples.rb
View file @
4e36caa5
...
...
@@ -55,7 +55,7 @@ RSpec.shared_examples 'group and project packages query' do
end
it
'deals with metadata'
do
expect
(
target_shas
).
to
contain_exactly
(
composer_metadatum
.
target_sha
)
expect
(
target_shas
.
compact
).
to
contain_exactly
(
composer_metadatum
.
target_sha
)
end
it
'returns the count of the packages'
do
...
...
spec/support_specs/helpers/graphql_helpers_spec.rb
View file @
4e36caa5
...
...
@@ -43,6 +43,21 @@ RSpec.describe GraphqlHelpers do
expect
(
graphql_dig_at
(
data
,
:foo
,
:nodes
,
:bar
,
:nodes
,
:id
)).
to
eq
([
1
,
2
,
3
,
4
])
end
it
'does not omit nils at the leaves'
do
data
=
{
'foo'
=>
{
'nodes'
=>
[
{
'bar'
=>
{
'nodes'
=>
[{
'id'
=>
nil
},
{
'id'
=>
2
}]
}
},
{
'bar'
=>
{
'nodes'
=>
[{
'id'
=>
3
},
{
'id'
=>
nil
}]
}
},
{
'bar'
=>
nil
}
]
},
'irrelevant'
=>
'the field is a red-herring'
}
expect
(
graphql_dig_at
(
data
,
:foo
,
:nodes
,
:bar
,
:nodes
,
:id
)).
to
eq
([
nil
,
2
,
3
,
nil
])
end
end
describe
'var'
do
...
...
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