Commit 0463e32a authored by ivan's avatar ivan

geolocation pagination

parent 0cea1d47
......@@ -112,7 +112,7 @@ type GeolocationQuery {
limit: Int
before: [Cursor]
after: [Cursor]
): [SpatialThingsPage!]
): SpatialThingsPage!
}
type GeolocationMutation {
......
......@@ -3,6 +3,7 @@ defmodule Geolocation.GraphQLTest do
use CommonsPub.Web.ConnCase, async: true
import CommonsPub.Test.Faking
import CommonsPub.Utils.Trendy, only: [some: 2]
import Geolocation.Test.Faking
import Geolocation.Simulate
......@@ -19,6 +20,22 @@ defmodule Geolocation.GraphQLTest do
end
end
describe "spatialThingPages" do
test "fetches a paginated list of geolocations" do
user = fake_user!()
geos = some(5, fn -> fake_geolocation!(user) end)
q = geolocation_pages_query()
conn = user_conn(user)
vars = %{
limit: 2
}
assert geolocations = grumble_post_key(q, conn, :spatial_things_pages, vars)
assert geolocations["totalCount"] == 5
assert Enum.count(geolocations["edges"]) == 2
end
end
describe "geolocation.in_scope_of" do
test "returns the context of the geolocation" do
user = fake_user!()
......
......@@ -44,6 +44,31 @@ defmodule Geolocation.Test.Faking do
gen_subquery(:id, :spatial_thing, &geolocation_query_fields/1, options)
end
def geolocation_pages_subquery(options \\ []) do
args = [
after: var(:after),
before: var(:before),
limit: var(:limit)
]
page_subquery(
:spatial_things_pages,
&geolocation_query_fields/1,
[{:args, args} | options]
)
end
def geolocation_pages_query(options \\ []) do
params =
[
after: list_type(:cursor),
before: list_type(:cursor),
limit: :int
] ++ Keyword.get(options, :params, [])
gen_query(&geolocation_pages_subquery/1, [{:params, params} | options])
end
def create_geolocation_mutation(options \\ []) do
[spatial_thing: type!(:spatial_thing_input)]
|> gen_mutation(&create_geolocation_submutation/1, options)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment