Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
91e9e50a
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
91e9e50a
编写于
1月 31, 2019
作者:
L
Lin Jen-Shin
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add field mergeRequests for project in GraphQL
And fix the tests so that it won't run into circular paths.
上级
1322146b
变更
7
显示空白变更内容
内联
并排
Showing
7 changed file
with
54 addition
and
12 deletion
+54
-12
app/graphql/mutations/merge_requests/base.rb
app/graphql/mutations/merge_requests/base.rb
+2
-1
app/graphql/resolvers/base_resolver.rb
app/graphql/resolvers/base_resolver.rb
+7
-0
app/graphql/resolvers/merge_requests_resolver.rb
app/graphql/resolvers/merge_requests_resolver.rb
+15
-4
app/graphql/types/project_type.rb
app/graphql/types/project_type.rb
+8
-1
changelogs/unreleased/56485-implement-graphql-mergerequestsresolver.yml
...eleased/56485-implement-graphql-mergerequestsresolver.yml
+5
-0
spec/graphql/resolvers/merge_requests_resolver_spec.rb
spec/graphql/resolvers/merge_requests_resolver_spec.rb
+6
-4
spec/support/helpers/graphql_helpers.rb
spec/support/helpers/graphql_helpers.rb
+11
-2
未找到文件。
app/graphql/mutations/merge_requests/base.rb
浏览文件 @
91e9e50a
...
@@ -25,7 +25,8 @@ module Mutations
...
@@ -25,7 +25,8 @@ module Mutations
def
find_object
(
project_path
:,
iid
:)
def
find_object
(
project_path
:,
iid
:)
project
=
resolve_project
(
full_path:
project_path
)
project
=
resolve_project
(
full_path:
project_path
)
resolver
=
Resolvers
::
MergeRequestResolver
.
new
(
object:
project
,
context:
context
)
resolver
=
Resolvers
::
MergeRequestsResolver
.
single
.
new
(
object:
project
,
context:
context
)
resolver
.
resolve
(
iid:
iid
)
resolver
.
resolve
(
iid:
iid
)
end
end
...
...
app/graphql/resolvers/base_resolver.rb
浏览文件 @
91e9e50a
...
@@ -2,5 +2,12 @@
...
@@ -2,5 +2,12 @@
module
Resolvers
module
Resolvers
class
BaseResolver
<
GraphQL
::
Schema
::
Resolver
class
BaseResolver
<
GraphQL
::
Schema
::
Resolver
def
self
.
single
@single
||=
Class
.
new
(
self
)
do
def
resolve
(
**
args
)
super
.
first
end
end
end
end
end
end
end
app/graphql/resolvers/merge_request_resolver.rb
→
app/graphql/resolvers/merge_request
s
_resolver.rb
浏览文件 @
91e9e50a
# frozen_string_literal: true
# frozen_string_literal: true
module
Resolvers
module
Resolvers
class
MergeRequestResolver
<
BaseResolver
class
MergeRequest
s
Resolver
<
BaseResolver
argument
:iid
,
GraphQL
::
ID_TYPE
,
argument
:iid
,
GraphQL
::
ID_TYPE
,
required:
tru
e
,
required:
fals
e
,
description:
'The IID of the merge request, e.g., "1"'
description:
'The IID of the merge request, e.g., "1"'
argument
:iids
,
[
GraphQL
::
ID_TYPE
],
required:
false
,
description:
'The list of IIDs of issues, e.g., [1, 2]'
type
Types
::
MergeRequestType
,
null:
true
type
Types
::
MergeRequestType
,
null:
true
alias_method
:project
,
:object
alias_method
:project
,
:object
# rubocop: disable CodeReuse/ActiveRecord
def
resolve
(
**
args
)
def
resolve
(
iid
:)
return
unless
project
.
present?
return
unless
project
.
present?
args
[
:iids
]
||=
[
args
[
:iid
]]
args
[
:iids
].
map
(
&
method
(
:batch_load
))
.
select
(
&
:itself
)
# .compact doesn't work on BatchLoader
end
# rubocop: disable CodeReuse/ActiveRecord
def
batch_load
(
iid
)
BatchLoader
.
for
(
iid
.
to_s
).
batch
(
key:
project
)
do
|
iids
,
loader
,
args
|
BatchLoader
.
for
(
iid
.
to_s
).
batch
(
key:
project
)
do
|
iids
,
loader
,
args
|
args
[
:key
].
merge_requests
.
where
(
iid:
iids
).
each
do
|
mr
|
args
[
:key
].
merge_requests
.
where
(
iid:
iids
).
each
do
|
mr
|
loader
.
call
(
mr
.
iid
.
to_s
,
mr
)
loader
.
call
(
mr
.
iid
.
to_s
,
mr
)
...
...
app/graphql/types/project_type.rb
浏览文件 @
91e9e50a
...
@@ -66,10 +66,17 @@ module Types
...
@@ -66,10 +66,17 @@ module Types
field
:only_allow_merge_if_all_discussions_are_resolved
,
GraphQL
::
BOOLEAN_TYPE
,
null:
true
field
:only_allow_merge_if_all_discussions_are_resolved
,
GraphQL
::
BOOLEAN_TYPE
,
null:
true
field
:printing_merge_request_link_enabled
,
GraphQL
::
BOOLEAN_TYPE
,
null:
true
field
:printing_merge_request_link_enabled
,
GraphQL
::
BOOLEAN_TYPE
,
null:
true
field
:merge_requests
,
Types
::
MergeRequestType
.
connection_type
,
null:
true
,
resolver:
Resolvers
::
MergeRequestsResolver
do
# authorize :read_merge_request
end
field
:merge_request
,
field
:merge_request
,
Types
::
MergeRequestType
,
Types
::
MergeRequestType
,
null:
true
,
null:
true
,
resolver:
Resolvers
::
MergeRequest
Resolver
do
resolver:
Resolvers
::
MergeRequest
sResolver
.
single
do
authorize
:read_merge_request
authorize
:read_merge_request
end
end
...
...
changelogs/unreleased/56485-implement-graphql-mergerequestsresolver.yml
0 → 100644
浏览文件 @
91e9e50a
---
title
:
Add field mergeRequests for project in GraphQL
merge_request
:
24805
author
:
type
:
added
spec/graphql/resolvers/merge_request_resolver_spec.rb
→
spec/graphql/resolvers/merge_request
s
_resolver_spec.rb
浏览文件 @
91e9e50a
require
'spec_helper'
require
'spec_helper'
describe
Resolvers
::
MergeRequestResolver
do
describe
Resolvers
::
MergeRequest
s
Resolver
do
include
GraphqlHelpers
include
GraphqlHelpers
set
(
:project
)
{
create
(
:project
,
:repository
)
}
set
(
:project
)
{
create
(
:project
,
:repository
)
}
...
@@ -18,7 +18,7 @@ describe Resolvers::MergeRequestResolver do
...
@@ -18,7 +18,7 @@ describe Resolvers::MergeRequestResolver do
describe
'#resolve'
do
describe
'#resolve'
do
it
'batch-resolves merge requests by target project full path and IID'
do
it
'batch-resolves merge requests by target project full path and IID'
do
result
=
batch
(
max_queries:
2
)
do
result
=
batch
(
max_queries:
2
)
do
[
resolve_mr
(
project
,
iid_1
),
resolve_mr
(
project
,
iid_2
)]
resolve_mr
(
project
,
iid_1
)
+
resolve_mr
(
project
,
iid_2
)
end
end
expect
(
result
).
to
contain_exactly
(
merge_request_1
,
merge_request_2
)
expect
(
result
).
to
contain_exactly
(
merge_request_1
,
merge_request_2
)
...
@@ -26,7 +26,9 @@ describe Resolvers::MergeRequestResolver do
...
@@ -26,7 +26,9 @@ describe Resolvers::MergeRequestResolver do
it
'can batch-resolve merge requests from different projects'
do
it
'can batch-resolve merge requests from different projects'
do
result
=
batch
(
max_queries:
3
)
do
result
=
batch
(
max_queries:
3
)
do
[
resolve_mr
(
project
,
iid_1
),
resolve_mr
(
project
,
iid_2
),
resolve_mr
(
other_project
,
other_iid
)]
resolve_mr
(
project
,
iid_1
)
+
resolve_mr
(
project
,
iid_2
)
+
resolve_mr
(
other_project
,
other_iid
)
end
end
expect
(
result
).
to
contain_exactly
(
merge_request_1
,
merge_request_2
,
other_merge_request
)
expect
(
result
).
to
contain_exactly
(
merge_request_1
,
merge_request_2
,
other_merge_request
)
...
@@ -35,7 +37,7 @@ describe Resolvers::MergeRequestResolver do
...
@@ -35,7 +37,7 @@ describe Resolvers::MergeRequestResolver do
it
'resolves an unknown iid to nil'
do
it
'resolves an unknown iid to nil'
do
result
=
batch
{
resolve_mr
(
project
,
-
1
)
}
result
=
batch
{
resolve_mr
(
project
,
-
1
)
}
expect
(
result
).
to
be_
nil
expect
(
result
).
to
be_
empty
end
end
end
end
...
...
spec/support/helpers/graphql_helpers.rb
浏览文件 @
91e9e50a
...
@@ -84,7 +84,7 @@ module GraphqlHelpers
...
@@ -84,7 +84,7 @@ module GraphqlHelpers
QUERY
QUERY
end
end
def
all_graphql_fields_for
(
class_name
)
def
all_graphql_fields_for
(
class_name
,
parent_types
=
Set
.
new
)
type
=
GitlabSchema
.
types
[
class_name
.
to_s
]
type
=
GitlabSchema
.
types
[
class_name
.
to_s
]
return
""
unless
type
return
""
unless
type
...
@@ -92,8 +92,17 @@ module GraphqlHelpers
...
@@ -92,8 +92,17 @@ module GraphqlHelpers
# We can't guess arguments, so skip fields that require them
# We can't guess arguments, so skip fields that require them
next
if
required_arguments?
(
field
)
next
if
required_arguments?
(
field
)
singular_field_type
=
field_type
(
field
)
# If field type is the same as parent type, then we're hitting into
# mutual dependency. Break it from infinite recursion
next
if
parent_types
.
include?
(
singular_field_type
)
if
nested_fields?
(
field
)
if
nested_fields?
(
field
)
"
#{
name
}
{
#{
all_graphql_fields_for
(
field_type
(
field
))
}
}"
fields
=
all_graphql_fields_for
(
singular_field_type
,
parent_types
|
[
type
])
"
#{
name
}
{
#{
fields
}
}"
else
else
name
name
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录