Skip to content

Commit

Permalink
Fixes #36509 - Fix totalCount handling for GraphQL queries with first…
Browse files Browse the repository at this point in the history
… parameter
  • Loading branch information
kamils-iRonin authored and ofedoren committed Jun 19, 2023
1 parent 59bf491 commit cb88310
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/graphql/connections/base_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ class BaseConnection < GraphQL::Types::Relay::BaseConnection
field :total_count, Integer, null: false

def total_count
object.nodes.size
object.items&.size || 0
end
end
end
13 changes: 7 additions & 6 deletions test/graphql/queries/models_query_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

module Queries
class ModelsQueryTest < GraphQLQueryTestCase
let(:page_size) { 10 }

let(:query) do
<<-GRAPHQL
query {
models {
models(first: #{page_size}) {
totalCount
pageInfo {
startCursor
Expand All @@ -27,17 +29,16 @@ class ModelsQueryTest < GraphQLQueryTestCase
let(:data) { result['data']['models'] }

setup do
FactoryBot.create_list(:model, 2)
FactoryBot.create_list(:model, 20)
end

test 'fetching models attributes' do
assert_empty result['errors']

expected_count = Model.count
expected_total_count = Model.count

assert_not_equal 0, expected_count
assert_equal expected_count, data['totalCount']
assert_equal expected_count, data['edges'].count
assert_equal expected_total_count, data['totalCount']
assert_equal page_size, data['edges'].count
end
end
end

0 comments on commit cb88310

Please sign in to comment.