diff --git a/lib/absinthe/relay/connection.ex b/lib/absinthe/relay/connection.ex index a66697c..dcf0bf1 100644 --- a/lib/absinthe/relay/connection.ex +++ b/lib/absinthe/relay/connection.ex @@ -566,7 +566,9 @@ defmodule Absinthe.Relay.Connection do offset = offset || 0 first = offset_to_cursor(offset) edge = build_edge(item, first) - {edges, last} = do_build_cursors(items, offset + 1, [edge], first) + {edges, _} = do_build_cursors(items, offset + 1, [edge], first) + first = edges |> List.first() |> get_in([:cursor]) + last = edges |> List.last() |> get_in([:cursor]) {edges, first, last} end @@ -581,7 +583,7 @@ defmodule Absinthe.Relay.Connection do defp build_edge({item, args}, cursor) do args |> Enum.flat_map(fn - {key, _} when key in [:cursor, :node] -> + {key, _} when key in [:node] -> Logger.warn("Ignoring additional #{key} provided on edge (overriding is not allowed)") [] diff --git a/test/lib/absinthe/relay/connection_test.exs b/test/lib/absinthe/relay/connection_test.exs index 4f6bfe4..6b13371 100644 --- a/test/lib/absinthe/relay/connection_test.exs +++ b/test/lib/absinthe/relay/connection_test.exs @@ -578,20 +578,25 @@ defmodule Absinthe.Relay.ConnectionTest do describe "when provided with a cursor as an edge arg" do setup do - [record: {%{name: "Dan"}, %{role: "contributor", cursor: :bad}}] - end - - test "it will ignore the additional cursor", %{record: record} do - capture_log(fn -> - {:ok, %{edges: [%{cursor: cursor} | _]}} = Connection.from_list([record], %{first: 1}) - assert cursor == "YXJyYXljb25uZWN0aW9uOjA=" - end) - end - - test "it will log a warning", %{record: record} do - assert capture_log(fn -> - Connection.from_list([record], %{first: 1}) - end) =~ "Ignoring additional cursor provided on edge" + [ + records: [ + {%{name: "Dan"}, %{role: "contributor", cursor: "start_cursor"}}, + {%{name: "Bob"}, %{role: "contributor", cursor: "end_cursor"}} + ] + ] + end + + test "it will override the default cursor", %{records: records} do + assert( + {:ok, + %{ + edges: [%{cursor: "start_cursor"}, %{cursor: "end_cursor"}], + page_info: %{ + start_cursor: "start_cursor", + end_cursor: "end_cursor" + } + }} = Connection.from_list(records, %{first: 2}) + ) end end diff --git a/test/lib/absinthe/relay/schema_test.exs b/test/lib/absinthe/relay/schema_test.exs index 8c2429c..2fe3e87 100644 --- a/test/lib/absinthe/relay/schema_test.exs +++ b/test/lib/absinthe/relay/schema_test.exs @@ -155,7 +155,6 @@ defmodule Absinthe.Relay.SchemaTest do end end - defmodule SchemaCustomIdType do use Absinthe.Schema use Absinthe.Relay.Schema, :classic