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
2ef928ca
Commit
2ef928ca
authored
Dec 13, 2020
by
Alex Kalderimis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add filtering to epic issues resolver
parent
f1f96540
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
1 deletion
+27
-1
app/graphql/resolvers/concerns/caching_array_resolver.rb
app/graphql/resolvers/concerns/caching_array_resolver.rb
+11
-1
ee/app/graphql/resolvers/epic_issues_resolver.rb
ee/app/graphql/resolvers/epic_issues_resolver.rb
+4
-0
ee/spec/graphql/resolvers/epic_issues_resolver_spec.rb
ee/spec/graphql/resolvers/epic_issues_resolver_spec.rb
+12
-0
No files found.
app/graphql/resolvers/concerns/caching_array_resolver.rb
View file @
2ef928ca
...
...
@@ -43,8 +43,10 @@
# (i.e. `resolve(**args).sync == query_for(query_input(**args)).to_a`).
#
# Classes may implement:
# - #item_found(A, R) (return value is ignored)
# - max_union_size Integer (the maximum number of queries to run in any one union)
# - preload -> Preloads|NilClass (a set of preloads to apply to each query)
# - #item_found(A, R) (return value is ignored)
# - allowed?(R) -> Boolean (if this method returns false, the value is not resolved)
module
CachingArrayResolver
MAX_UNION_SIZE
=
50
...
...
@@ -76,6 +78,12 @@ module CachingArrayResolver
end
end
# Override to apply filters on a per-item basis
def
allowed?
(
item
)
true
end
# Override to specify preloads for each query
def
preload
nil
end
...
...
@@ -99,6 +107,8 @@ module CachingArrayResolver
end
def
found
(
loader
,
key
,
value
)
return
unless
allowed?
(
value
)
loader
.
call
(
key
)
do
|
vs
|
item_found
(
key
,
value
)
vs
<<
value
...
...
ee/app/graphql/resolvers/epic_issues_resolver.rb
View file @
2ef928ca
...
...
@@ -12,6 +12,10 @@ module Resolvers
::
Issue
end
def
allowed?
(
issue
)
DeclarativePolicy
.
user_scope
{
issue
.
visible_to_user?
(
current_user
)
}
end
def
query_input
(
**
args
)
epic
.
id
end
...
...
ee/spec/graphql/resolvers/epic_issues_resolver_spec.rb
View file @
2ef928ca
...
...
@@ -39,6 +39,18 @@ RSpec.describe Resolvers::EpicIssuesResolver do
expect
(
result
).
to
eq
[[
issue2
,
issue1
],
[
issue3
,
issue4
]]
end
it
'finds only epic issues that user can read'
do
guest
=
create
(
:user
)
result
=
[
resolve_epic_issues
(
epic1
,
user:
guest
).
to_a
,
resolve_epic_issues
(
epic2
,
user:
guest
).
to_a
]
expect
(
result
).
to
eq
([[
issue1
],
[]])
end
end
def
resolve_epic_issues
(
object
,
user:
current_user
)
...
...
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