File tree Expand file tree Collapse file tree 2 files changed +15
-2
lines changed
lib/graphql/relay/connection
test/graphql/relay/connection Expand file tree Collapse file tree 2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ if Code.ensure_loaded?(Ecto) do
30
30
nil -> false
31
31
_ ->
32
32
first_limit = first + 1
33
- has_more_records_query = from things in query , limit: ^ first_limit
33
+ has_more_records_query = remove_select ( from things in query , limit: ^ first_limit )
34
34
has_more_records_query = from things in has_more_records_query , select: count ( things . id )
35
35
repo . one ( has_more_records_query ) > first
36
36
end
@@ -39,7 +39,7 @@ if Code.ensure_loaded?(Ecto) do
39
39
nil -> false
40
40
_ ->
41
41
last_limit = last + 1
42
- has_prev_records_query = from things in query , limit: ^ last_limit
42
+ has_prev_records_query = remove_select ( from things in query , limit: ^ last_limit )
43
43
has_prev_records_query = from things in has_prev_records_query , select: count ( things . id )
44
44
repo . one ( has_prev_records_query ) > last
45
45
end
@@ -114,8 +114,15 @@ if Code.ensure_loaded?(Ecto) do
114
114
end
115
115
116
116
def connection_count ( repo , query ) do
117
+ query = remove_select ( query )
117
118
count_query = from things in query , select: count ( things . id )
118
119
repo . one ( count_query )
119
120
end
121
+
122
+ # Remove select if it exists so that we avoid `only one select
123
+ # expression is allowed in query` Ecto exception
124
+ defp remove_select ( query ) do
125
+ % { query | select: nil }
126
+ end
120
127
end
121
128
end
Original file line number Diff line number Diff line change @@ -59,6 +59,12 @@ defmodule GraphQL.Relay.Connection.EctoTest do
59
59
Enum . at ( letters , 4 )
60
60
end
61
61
62
+ test "querying for counts does not raise exception if select already exists" do
63
+ query = letters_query
64
+ |> select ( [ l ] , % { id: l . id , letter: l . letter } )
65
+ assert ( Connection.Ecto . resolve ( query , % { repo: Repo } ) )
66
+ end
67
+
62
68
test "basic slicing: returns all elements without filters" do
63
69
expected = % {
64
70
edges: [
You can’t perform that action at this time.
0 commit comments