lib/graphql/pagination/relation_connection.rb in graphql-1.10.4 vs lib/graphql/pagination/relation_connection.rb in graphql-1.10.5
- old
+ new
@@ -42,11 +42,11 @@
def cursor_for(item)
load_nodes
# index in nodes + existing offset + 1 (because it's offset, not index)
offset = nodes.index(item) + 1 + (@paged_nodes_offset || 0) + (relation_offset(items) || 0)
- context.schema.cursor_encoder.encode(offset.to_s)
+ encode(offset.to_s)
end
private
# @param relation [Object] A database query object
@@ -135,11 +135,12 @@
# Apply `first` and `last` to `sliced_nodes`,
# returning a new relation
def limited_nodes
@limited_nodes ||= begin
paginated_nodes = sliced_nodes
+ previous_limit = relation_limit(paginated_nodes)
- if first && (relation_limit(paginated_nodes).nil? || relation_limit(paginated_nodes) > first) && last.nil?
+ if first && (previous_limit.nil? || previous_limit > first)
# `first` would create a stricter limit that the one already applied, so add it
paginated_nodes = set_limit(paginated_nodes, first)
end
if last