@currentoor you can use an introspection query for that https://graphql.org/learn/introspection/
ah thanks @pcj
is anyone using cursor based pagination with lacinia? https://graphql.org/learn/pagination/
Yes, it works well for some of our use cases.
cool. is your schema public/open source? curious how to describe it
It’s not public. But here is basically what it looks like:
:PagedFoo
{:fields
{:foo_list {:type (list :Foo)}
:next_page_cursor {:type String}}}
thanks. i was trying to figure out if "Paged" could be a generic type
not sure the concept even exists in lacinia
so that i could have many different types of Paged things
I see in that link you posted, they chose to put PageInfo
in friends
, whereas we chose to wrap our data object in the paging.
yep
I haven’t thought deeply about their approach, but one possible problem I see is that now the Friend type has to know about paging. Maybe that makes sense, but for us at least we have paths to get single Foo objects, so paging wouldn’t make sense in that context
good point
I think also that ours could be written:
:PagedFoo
{:fields
{:foo_list {:type (list :Foo)}
:page_info {:type PageInfo}}}
And then we’d have the re-usable data container at least. 🤷
yep, interesting.
But the details of paging over Foo’s might be different than paging over Bar’s, so it’s possible not much might be shared besides the data type
that makes sense. i need to contemplate how this maps to the "connections" concept. e.g.:
{
hero {
name
friendsConnection(first:2 after:"Y3Vyc29yMQ==") {
totalCount
edges {
node {
name
}
cursor
}
pageInfo {
endCursor
hasNextPage
}
}
}
}
i'll probably model it directly without trying to re-use types first
just to complete my example, here’s the query resolver with the cursor arg:
:list_of_foos
{:type :PagedFoo
:args {:cursor {:type String}
:limit {:type Int :default-value 25}}
:resolve ....}
thanks. that's helpful!
And rather than returning hasNextPage
, we chose to return a null
cursor at the end
Now that I look closer, I think friendsConnection
might be somewhat like PagedFoo
.
yep. and maybe i could model Connection as an interface
friendsConnection.edges.node
vs our direct foo_list
right
We lifted Relay pagination and implemented a subset of it.