diff options
Diffstat (limited to 'doc/development/graphql_guide/pagination.md')
-rw-r--r-- | doc/development/graphql_guide/pagination.md | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/doc/development/graphql_guide/pagination.md b/doc/development/graphql_guide/pagination.md index 5db9238faed..5fd2179ea9b 100644 --- a/doc/development/graphql_guide/pagination.md +++ b/doc/development/graphql_guide/pagination.md @@ -223,6 +223,26 @@ the `order_due_date_and_labels_priority` method creates a very complex query. These types of queries are not supported. In these instances, you can use offset pagination. +#### Gotchas + +Do not define a collection's order using the string syntax: + +```ruby +# Bad +items.order('created_at DESC') +``` + +Instead, use the hash syntax: + +```ruby +# Good +items.order(created_at: :desc) +``` + +The first example won't correctly embed the sort information (`created_at`, in +the example above) into the pagination cursors, which will result in an +incorrect sort order. + ### Offset pagination There are times when the [complexity of sorting](#limitations-of-query-complexity) @@ -267,7 +287,7 @@ For consistency, we manually set the pagination cursors based on values returned You can see an example implementation in the following files: - [`types/error__tracking/sentry_error_collection_type.rb`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/graphql/types/error_tracking/sentry_error_collection_type.rb) which adds an extension to `field :errors`. -- [`resolvers/error_tracking/sentry_errors_resolver.rb`](https://gitlab.com/gitlab-org/gitlab/blob/master/app/graphql/resolvers/error_tracking/sentry_errors_resolver.rb) which returns the data from the resolver. +- [`resolvers/error_tracking/sentry_errors_resolver.rb`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/graphql/resolvers/error_tracking/sentry_errors_resolver.rb) which returns the data from the resolver. ## Testing |