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
e40eb46d
Commit
e40eb46d
authored
Jun 07, 2021
by
Alexandru Croitor
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle timeframe argument
Ensure resolvers using TimeFrameArguments all can handle timeframe arguments.
parent
b2d828d5
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
111 additions
and
21 deletions
+111
-21
app/graphql/resolvers/concerns/time_frame_arguments.rb
app/graphql/resolvers/concerns/time_frame_arguments.rb
+8
-0
app/graphql/resolvers/milestones_resolver.rb
app/graphql/resolvers/milestones_resolver.rb
+1
-9
ee/app/graphql/resolvers/epic_ancestors_resolver.rb
ee/app/graphql/resolvers/epic_ancestors_resolver.rb
+3
-3
ee/app/graphql/resolvers/epics_resolver.rb
ee/app/graphql/resolvers/epics_resolver.rb
+4
-4
ee/app/graphql/resolvers/iterations_resolver.rb
ee/app/graphql/resolvers/iterations_resolver.rb
+1
-3
ee/spec/graphql/resolvers/epics_resolver_spec.rb
ee/spec/graphql/resolvers/epics_resolver_spec.rb
+8
-0
ee/spec/graphql/resolvers/iterations_resolver_spec.rb
ee/spec/graphql/resolvers/iterations_resolver_spec.rb
+0
-2
ee/spec/requests/api/graphql/milestone_spec.rb
ee/spec/requests/api/graphql/milestone_spec.rb
+79
-0
spec/requests/api/graphql/group/milestones_spec.rb
spec/requests/api/graphql/group/milestones_spec.rb
+7
-0
No files found.
app/graphql/resolvers/concerns/time_frame_arguments.rb
View file @
e40eb46d
...
...
@@ -39,4 +39,12 @@ module TimeFrameArguments
raise
Gitlab
::
Graphql
::
Errors
::
ArgumentError
,
error_message
end
end
def
transform_timeframe_parameters
(
args
)
if
args
[
:timeframe
]
args
[
:timeframe
].
transform_keys
{
|
k
|
:"
#{
k
}
_date"
}
else
args
.
slice
(
:start_date
,
:end_date
)
end
end
end
app/graphql/resolvers/milestones_resolver.rb
View file @
e40eb46d
...
...
@@ -44,15 +44,7 @@ module Resolvers
title:
args
[
:title
],
search_title:
args
[
:search_title
],
containing_date:
args
[
:containing_date
]
}.
merge!
(
timeframe_parameters
(
args
)).
merge!
(
parent_id_parameters
(
args
))
end
def
timeframe_parameters
(
args
)
if
args
[
:timeframe
]
args
[
:timeframe
].
transform_keys
{
|
k
|
:"
#{
k
}
_date"
}
else
args
.
slice
(
:start_date
,
:end_date
)
end
}.
merge!
(
transform_timeframe_parameters
(
args
)).
merge!
(
parent_id_parameters
(
args
))
end
def
parent
...
...
ee/app/graphql/resolvers/epic_ancestors_resolver.rb
View file @
e40eb46d
...
...
@@ -11,10 +11,10 @@ module Resolvers
private
def
set_relative_param
(
args
)
args
[
:child_id
]
=
parent
.
id
if
parent
def
relative_param
return
{}
unless
parent
args
{
child_id:
parent
.
id
}
end
end
end
ee/app/graphql/resolvers/epics_resolver.rb
View file @
e40eb46d
...
...
@@ -104,13 +104,13 @@ module Resolvers
transformed
[
:group_id
]
=
group
transformed
[
:iids
]
||=
[
args
[
:iid
]].
compact
set_relative_param
(
transformed
)
transformed
.
merge
(
transform_timeframe_parameters
(
args
)).
merge
(
relative_param
)
end
def
set_relative_param
(
args
)
args
[
:parent_id
]
=
parent
.
id
if
parent
def
relative_param
return
{}
unless
parent
args
{
parent_id:
parent
.
id
}
end
# `resolver_object` refers to the object we're currently querying on, and is usually a `Group`
...
...
ee/app/graphql/resolvers/iterations_resolver.rb
View file @
e40eb46d
...
...
@@ -58,10 +58,8 @@ module Resolvers
iid:
args
[
:iid
],
iteration_cadence_ids:
args
[
:iteration_cadence_ids
],
state:
args
[
:state
]
||
'all'
,
start_date:
args
.
dig
(
:timeframe
,
:start
)
||
args
[
:start_date
],
end_date:
args
.
dig
(
:timeframe
,
:end
)
||
args
[
:end_date
],
search_title:
args
[
:title
]
}
}
.
merge
(
transform_timeframe_parameters
(
args
))
end
def
parent
...
...
ee/spec/graphql/resolvers/epics_resolver_spec.rb
View file @
e40eb46d
...
...
@@ -72,6 +72,14 @@ RSpec.describe Resolvers::EpicsResolver do
expect
(
epics
).
to
match_array
([
epic1
,
epic2
])
end
end
context
'when timeframe start and end are present'
do
it
'returns epics within timeframe'
do
epics
=
resolve_epics
(
timeframe:
{
start:
'2019-08-13'
,
end:
'2019-08-21'
})
expect
(
epics
).
to
match_array
([
epic1
,
epic2
])
end
end
end
context
'with state'
do
...
...
ee/spec/graphql/resolvers/iterations_resolver_spec.rb
View file @
e40eb46d
...
...
@@ -15,8 +15,6 @@ RSpec.describe Resolvers::IterationsResolver do
iteration_cadence_ids:
nil
,
parent:
nil
,
state:
nil
,
start_date:
nil
,
end_date:
nil
,
search_title:
nil
}
end
...
...
ee/spec/requests/api/graphql/milestone_spec.rb
View file @
e40eb46d
...
...
@@ -7,6 +7,7 @@ RSpec.describe 'Querying a Milestone' do
let_it_be
(
:current_user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
)
}
let_it_be
(
:group
)
{
create
(
:group
)
}
let_it_be
(
:milestone
)
{
create
(
:milestone
,
project:
project
,
start_date:
'2020-01-01'
,
due_date:
'2020-01-15'
)
}
let
(
:query
)
do
...
...
@@ -76,4 +77,82 @@ RSpec.describe 'Querying a Milestone' do
end
end
end
shared_examples
'milestones queried by timeframe'
do
describe
'query for milestones by timeframe'
do
context
'without start'
do
it
'returns error'
do
post_graphql
(
milestones_query
(
parent
,
"timeframe: { end:
\"
#{
3
.
days
.
ago
.
to_date
}
\"
}"
),
current_user:
current_user
)
expect
(
graphql_errors
).
to
include
(
a_hash_including
(
'message'
=>
"Argument 'start' on InputObject 'Timeframe' is required. Expected type Date!"
))
end
end
context
'without end date'
do
it
'returns error'
do
post_graphql
(
milestones_query
(
parent
,
"timeframe: { start:
\"
#{
3
.
days
.
ago
.
to_date
}
\"
}"
),
current_user:
current_user
)
expect
(
graphql_errors
).
to
include
(
a_hash_including
(
'message'
=>
"Argument 'end' on InputObject 'Timeframe' is required. Expected type Date!"
))
end
end
context
'with start and end date'
do
it
'does not have errors'
do
post_graphql
(
milestones_query
(
parent
,
"timeframe: { start:
\"
#{
3
.
days
.
ago
.
to_date
}
\"
, end:
\"
#{
3
.
days
.
from_now
.
to_date
}
\"
}"
),
current_user:
current_user
)
expect
(
graphql_errors
).
to
be_nil
end
end
end
end
context
'group milestones'
do
it_behaves_like
'milestones queried by timeframe'
do
let
(
:parent
)
{
group
}
end
end
context
'project milestones'
do
it_behaves_like
'milestones queried by timeframe'
do
let
(
:parent
)
{
project
}
end
end
def
project_milestones_query
(
project
,
milestone_query
)
<<~
QUERY
query {
project(fullPath: "
#{
project
.
full_path
}
") {
id,
#{
milestone_query
}
}
}
QUERY
end
def
group_milestones_query
(
group
,
milestone_query
)
<<~
QUERY
query {
group(fullPath: "
#{
group
.
full_path
}
") {
id,
#{
milestone_query
}
}
}
QUERY
end
def
milestones_query
(
parent
,
field_queries
)
query
=
<<~
Q
milestones(
#{
field_queries
}
) {
nodes {
id
}
}
Q
if
parent
.
is_a?
(
Group
)
group_milestones_query
(
parent
,
query
)
else
project_milestones_query
(
parent
,
query
)
end
end
end
spec/requests/api/graphql/group/milestones_spec.rb
View file @
e40eb46d
...
...
@@ -40,6 +40,13 @@ RSpec.describe 'Milestones through GroupQuery' do
expect_array_response
(
milestone_2
.
to_global_id
.
to_s
,
milestone_3
.
to_global_id
.
to_s
)
end
it
'fetches milestones between timeframe start and end arguments'
do
today
=
Date
.
today
fetch_milestones
(
user
,
{
timeframe:
{
start:
today
.
to_s
,
end:
(
today
+
2
.
days
).
to_s
}
})
expect_array_response
(
milestone_2
.
to_global_id
.
to_s
,
milestone_3
.
to_global_id
.
to_s
)
end
end
context
'when filtering by state'
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