diff options
| author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-07 18:08:32 +0000 |
|---|---|---|
| committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-09-07 18:08:32 +0000 |
| commit | dff0f3475c8dc49daccb1f9fd2399b881e6cc1f0 (patch) | |
| tree | f61feff669dfa72bb8f03e8c3d0d38df45be5263 /doc/development | |
| parent | cf24d183b3f71f091a02f12b211f3001be5b5085 (diff) | |
| download | gitlab-ce-dff0f3475c8dc49daccb1f9fd2399b881e6cc1f0.tar.gz | |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'doc/development')
| -rw-r--r-- | doc/development/api_graphql_styleguide.md | 3 | ||||
| -rw-r--r-- | doc/development/contributing/issue_workflow.md | 2 | ||||
| -rw-r--r-- | doc/development/graphql_guide/pagination.md | 55 |
3 files changed, 58 insertions, 2 deletions
diff --git a/doc/development/api_graphql_styleguide.md b/doc/development/api_graphql_styleguide.md index 1b0a69a4644..c7610996019 100644 --- a/doc/development/api_graphql_styleguide.md +++ b/doc/development/api_graphql_styleguide.md @@ -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 diff --git a/doc/development/contributing/issue_workflow.md b/doc/development/contributing/issue_workflow.md index bde4a2844f2..bb7b4713a5e 100644 --- a/doc/development/contributing/issue_workflow.md +++ b/doc/development/contributing/issue_workflow.md @@ -190,7 +190,7 @@ their color is `#428BCA`. For instance, the "DevOps Report" category is represented by the ~"Category:DevOps Reports" label in the `gitlab-org` group since its -`devops_score.name` value is "DevOps Reports". +`devops_reports.name` value is "DevOps Reports". If a category's label doesn't respect this naming convention, it should be specified with [the `label` attribute](https://about.gitlab.com/handbook/marketing/website/#category-attributes) diff --git a/doc/development/graphql_guide/pagination.md b/doc/development/graphql_guide/pagination.md index f5947bca891..bf9eaa99158 100644 --- a/doc/development/graphql_guide/pagination.md +++ b/doc/development/graphql_guide/pagination.md @@ -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 +``` |
