Skip to content
GitLab
菜单
为什么选择 GitLab
定价
联系销售
探索
为什么选择 GitLab
定价
联系销售
探索
登录
获取免费试用
主导航
搜索或转到…
项目
GitLab
管理
动态
成员
标记
计划
议题
议题看板
里程碑
迭代
需求
代码
合并请求
仓库
分支
提交
标签
仓库图
比较修订版本
代码片段
锁定的文件
构建
流水线
作业
流水线计划
测试用例
产物
部署
发布
Package registry
容器镜像库
模型注册表
运维
环境
Terraform 模块
监控
事件
服务台
分析
价值流分析
贡献者分析
CI/CD 分析
仓库分析
代码评审分析
议题分析
洞察
模型实验
效能分析
帮助
帮助
支持
GitLab 文档
比较 GitLab 各版本
社区论坛
为极狐GitLab 提交贡献
提交反馈
隐私声明
快捷键
?
新增功能
4
代码片段
群组
项目
显示更多面包屑
gitlab-cn
GitLab
提交
7719f579
提交
7719f579
编辑于
4 years ago
作者:
Brett Walker
提交者:
Marcin Sedlak-Jakubowski
4 years ago
浏览文件
操作
下载
补丁
差异文件
Docs review edits
- Format filenames as code - Simplify some sentences - Decrease code indent in samples
上级
500437d7
No related branches found
No related tags found
无相关合并请求
变更
2
隐藏空白变更内容
行内
左右并排
显示
2 个更改的文件
doc/development/api_graphql_styleguide.md
+3
-0
3 个添加, 0 个删除
doc/development/api_graphql_styleguide.md
doc/development/graphql_guide/pagination.md
+54
-1
54 个添加, 1 个删除
doc/development/graphql_guide/pagination.md
有
57 个添加
和
1 个删除
doc/development/api_graphql_styleguide.md
+
3
−
0
浏览文件 @
7719f579
...
...
@@ -1244,6 +1244,9 @@ Using the `GraphqlHelpers#all_graphql_fields_for`-helper, a query
including all available fields can be constructed. This makes it easy
to add a test rendering all possible fields for a query.
If you're adding a field to a query that supports pagination and sorting,
visit
[
Testing
](
graphql_guide/pagination.md#testing
)
for details.
To test GraphQL mutation requests,
`GraphqlHelpers`
provides 2
helpers:
`graphql_mutation`
which takes the name of the mutation, and
a hash with the input for the mutation. This will return a struct with
...
...
此差异已折叠。
点击以展开。
doc/development/graphql_guide/pagination.md
+
54
−
1
浏览文件 @
7719f579
...
...
@@ -86,4 +86,57 @@ sorting by label priority in issues, due to the complexity of the sort.
<!-- ### External pagination -->
<!-- ### Pagination testing -->
## Testing
Any GraphQL field that supports pagination and sorting should be tested
using the sorted paginated query shared example found in
[
`graphql/sorted_paginated_query_shared_examples.rb`
](
https://gitlab.com/gitlab-org/gitlab/-/blob/master/spec/support/shared_examples/graphql/sorted_paginated_query_shared_examples.rb
)
.
It helps verify that your sort keys are compatible and that cursors
work properly.
This is particularly important when using keyset pagination, as some sort keys might not be supported.
Add a section to your request specs like this:
```
ruby
describe
'sorting and pagination'
do
...
end
```
You can then use
[
`issues_spec.rb`
](
https://gitlab.com/gitlab-org/gitlab/-/blob/master/spec/requests/api/graphql/project/issues_spec.rb
)
as an example to construct your tests.
[
`graphql/sorted_paginated_query_shared_examples.rb`
](
https://gitlab.com/gitlab-org/gitlab/-/blob/master/spec/support/shared_examples/graphql/sorted_paginated_query_shared_examples.rb
)
also contains some documentation on how to use the shared examples.
The shared example requires certain
`let`
variables and methods to be set up:
```
ruby
describe
'sorting and pagination'
do
let
(
:sort_project
)
{
create
(
:project
,
:public
)
}
let
(
:data_path
)
{
[
:project
,
:issues
]
}
def
pagination_query
(
params
,
page_info
)
graphql_query_for
(
'project'
,
{
'fullPath'
=>
sort_project
.
full_path
},
query_graphql_field
(
'issues'
,
params
,
"
#{
page_info
}
edges { node { id } }"
)
)
end
def
pagination_results_data
(
data
)
data
.
map
{
|
issue
|
issue
.
dig
(
'node'
,
'iid'
).
to_i
}
end
context
'when sorting by weight'
do
...
context
'when ascending'
do
it_behaves_like
'sorted paginated query'
do
let
(
:sort_param
)
{
'WEIGHT_ASC'
}
let
(
:first_param
)
{
2
}
let
(
:expected_results
)
{
[
weight_issue3
.
iid
,
weight_issue5
.
iid
,
weight_issue1
.
iid
,
weight_issue4
.
iid
,
weight_issue2
.
iid
]
}
end
end
```
此差异已折叠。
点击以展开。
预览
0%
加载中
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
保存评论
取消
想要评论请
注册
或
登录