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
875267ed
Commit
875267ed
authored
Dec 02, 2020
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove use of `resolve: ->` from specs
and add new `simple_resolver` helper to GraphqlHelpers
parent
7757f7e8
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
14 deletions
+26
-14
spec/graphql/features/authorization_spec.rb
spec/graphql/features/authorization_spec.rb
+10
-12
spec/graphql/features/feature_flag_spec.rb
spec/graphql/features/feature_flag_spec.rb
+1
-1
spec/graphql/types/permission_types/base_permission_type_spec.rb
...aphql/types/permission_types/base_permission_type_spec.rb
+5
-1
spec/lib/gitlab/graphql/markdown_field_spec.rb
spec/lib/gitlab/graphql/markdown_field_spec.rb
+2
-0
spec/support/helpers/graphql_helpers.rb
spec/support/helpers/graphql_helpers.rb
+8
-0
No files found.
spec/graphql/features/authorization_spec.rb
View file @
875267ed
...
...
@@ -55,7 +55,7 @@ RSpec.describe 'Gitlab::Graphql::Authorization' do
describe
'with a single permission'
do
let
(
:query_type
)
do
query_factory
do
|
query
|
query
.
field
:item
,
type
,
null:
true
,
resolve
:
->
(
obj
,
args
,
ctx
)
{
test_object
}
,
authorize:
permission_single
query
.
field
:item
,
type
,
null:
true
,
resolve
r:
simple_resolver
(
test_object
)
,
authorize:
permission_single
end
end
...
...
@@ -66,7 +66,7 @@ RSpec.describe 'Gitlab::Graphql::Authorization' do
let
(
:query_type
)
do
permissions
=
permission_collection
query_factory
do
|
qt
|
qt
.
field
:item
,
type
,
null:
true
,
resolve
:
->
(
obj
,
args
,
ctx
)
{
test_object
}
do
qt
.
field
:item
,
type
,
null:
true
,
resolve
r:
simple_resolver
(
test_object
)
do
authorize
permissions
end
end
...
...
@@ -79,7 +79,7 @@ RSpec.describe 'Gitlab::Graphql::Authorization' do
describe
'Field authorizations when field is a built in type'
do
let
(
:query_type
)
do
query_factory
do
|
query
|
query
.
field
:item
,
type
,
null:
true
,
resolve
:
->
(
obj
,
args
,
ctx
)
{
test_object
}
query
.
field
:item
,
type
,
null:
true
,
resolve
r:
simple_resolver
(
test_object
)
end
end
...
...
@@ -132,7 +132,7 @@ RSpec.describe 'Gitlab::Graphql::Authorization' do
describe
'Type authorizations'
do
let
(
:query_type
)
do
query_factory
do
|
query
|
query
.
field
:item
,
type
,
null:
true
,
resolve
:
->
(
obj
,
args
,
ctx
)
{
test_object
}
query
.
field
:item
,
type
,
null:
true
,
resolve
r:
simple_resolver
(
test_object
)
end
end
...
...
@@ -169,7 +169,7 @@ RSpec.describe 'Gitlab::Graphql::Authorization' do
let
(
:query_type
)
do
query_factory
do
|
query
|
query
.
field
:item
,
type
,
null:
true
,
resolve
:
->
(
obj
,
args
,
ctx
)
{
test_object
}
,
authorize:
permission_2
query
.
field
:item
,
type
,
null:
true
,
resolve
r:
simple_resolver
(
test_object
)
,
authorize:
permission_2
end
end
...
...
@@ -188,7 +188,7 @@ RSpec.describe 'Gitlab::Graphql::Authorization' do
let
(
:query_type
)
do
query_factory
do
|
query
|
query
.
field
:item
,
type
.
connection_type
,
null:
true
,
resolve
:
->
(
obj
,
args
,
ctx
)
{
[
test_object
,
second_test_object
]
}
query
.
field
:item
,
type
.
connection_type
,
null:
true
,
resolve
r:
simple_resolver
([
test_object
,
second_test_object
])
end
end
...
...
@@ -208,9 +208,7 @@ RSpec.describe 'Gitlab::Graphql::Authorization' do
describe
'limiting connections with multiple objects'
do
let
(
:query_type
)
do
query_factory
do
|
query
|
query
.
field
:item
,
type
.
connection_type
,
null:
true
,
resolve:
->
(
obj
,
args
,
ctx
)
do
[
test_object
,
second_test_object
]
end
query
.
field
:item
,
type
.
connection_type
,
null:
true
,
resolver:
simple_resolver
([
test_object
,
second_test_object
])
end
end
...
...
@@ -234,7 +232,7 @@ RSpec.describe 'Gitlab::Graphql::Authorization' do
let
(
:query_type
)
do
query_factory
do
|
query
|
query
.
field
:item
,
[
type
],
null:
true
,
resolve
:
->
(
obj
,
args
,
ctx
)
{
[
test_object
]
}
query
.
field
:item
,
[
type
],
null:
true
,
resolve
r:
simple_resolver
([
test_object
])
end
end
...
...
@@ -262,13 +260,13 @@ RSpec.describe 'Gitlab::Graphql::Authorization' do
type_factory
do
|
type
|
type
.
graphql_name
'FakeProjectType'
type
.
field
:test_issues
,
issue_type
.
connection_type
,
null:
false
,
resolve
:
->
(
_
,
_
,
_
)
{
Issue
.
where
(
project:
[
visible_project
,
other_project
]).
order
(
id: :asc
)
}
resolve
r:
simple_resolver
(
Issue
.
where
(
project:
[
visible_project
,
other_project
]).
order
(
id: :asc
))
end
end
let
(
:query_type
)
do
query_factory
do
|
query
|
query
.
field
:test_project
,
project_type
,
null:
false
,
resolve
:
->
(
_
,
_
,
_
)
{
visible_project
}
query
.
field
:test_project
,
project_type
,
null:
false
,
resolve
r:
simple_resolver
(
visible_project
)
end
end
...
...
spec/graphql/features/feature_flag_spec.rb
View file @
875267ed
...
...
@@ -23,7 +23,7 @@ RSpec.describe 'Graphql Field feature flags' do
let
(
:query_type
)
do
query_factory
do
|
query
|
query
.
field
:item
,
type
,
null:
true
,
feature_flag:
feature_flag
,
resolve
:
->
(
obj
,
args
,
ctx
)
{
test_object
}
query
.
field
:item
,
type
,
null:
true
,
feature_flag:
feature_flag
,
resolve
r:
simple_resolver
(
test_object
)
end
end
...
...
spec/graphql/types/permission_types/base_permission_type_spec.rb
View file @
875267ed
...
...
@@ -11,9 +11,13 @@ RSpec.describe Types::PermissionTypes::BasePermissionType do
Class
.
new
(
described_class
)
do
graphql_name
'TestClass'
permission_field
:do_stuff
,
resolve:
->
(
_
,
_
,
_
)
{
true
}
permission_field
:do_stuff
ability_field
(
:read_issue
)
abilities
:admin_issue
define_method
:do_stuff
do
true
end
end
end
...
...
spec/lib/gitlab/graphql/markdown_field_spec.rb
View file @
875267ed
...
...
@@ -22,6 +22,8 @@ RSpec.describe Gitlab::Graphql::MarkdownField do
.
to
raise_error
(
expected_error
)
end
# TODO: remove as part of https://gitlab.com/gitlab-org/gitlab/-/merge_requests/27536
# so that until that time, the developer check is there
it
'raises when passing a resolve block'
do
expect
{
class_with_markdown_field
(
:test_html
,
null:
true
,
resolve:
->
(
_
,
_
,
_
)
{
'not really'
}
)
}
.
to
raise_error
(
expected_error
)
...
...
spec/support/helpers/graphql_helpers.rb
View file @
875267ed
...
...
@@ -150,6 +150,14 @@ module GraphqlHelpers
field
.
resolve_field
(
instance
,
args
,
context
)
end
def
simple_resolver
(
resolved_value
=
'Resolved value'
)
Class
.
new
(
Resolvers
::
BaseResolver
)
do
define_method
:resolve
do
|**
_args
|
resolved_value
end
end
end
# Recursively convert a Hash with Ruby-style keys to GraphQL fieldname-style keys
#
# prepare_input_for_mutation({ 'my_key' => 1 })
...
...
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