absinthe-graphql / absinthe_ecto

DEPRECATED: Use dataloader
MIT License
130 stars 36 forks source link

pagination macro in many_to_many ? #33

Open mydearxym opened 6 years ago

mydearxym commented 6 years ago

hi guys ~

let's say i have a post type with many started_users field witch resolved by assoc macro, it's great , but how to do pagination in this situation ?

object :post do
   field(:id, non_null(:id))
   field(:title, non_null(:string))
   field(:body, non_null(:string))
   field(:author, :author, resolve: assoc(:author))
>  field(:starred_users, list_of(:user), resolve: assoc(:starredUsers))
end
yordis commented 6 years ago

@mydearxym you couldn't use assoc because pagination strategies depend of your application.

How to do it?

Pretty much create some resolver that send back the data as you need it for be able to send the pagination object back and create the related schema for it

That pagination object depends of the strategy you are using, for example, cursor based vs limit-offset based pagination.

mydearxym commented 6 years ago

@yordis yes i could do the pagination logic my self like :

field :posts, list_of(:post) do
    arg :offset, :integer, default_value: 0
    arg :limit, :integer, default_value: 20
    resolve &Resolver.blabla/3
end 

i love the assoc for both save me a lot of typing and builds a resolution function which calls ecto_batch/4. magic, but what's the point if assoc do not support pagination in many_to_many situation ?

yordis commented 6 years ago

@mydearxym pagination is based on your application strategy, at that moment when absinthe add it, it will dictate how my application works.

Right now assoc is a simple as it should be. That is an application specific details and we will get into the nightmare of convention.

If you want to save time, just write your own resolver that deals with exactly what you always do.

The point of assoc is to be as simple as it gets for the basic uses cases.

mydearxym commented 6 years ago

@yordis i think the solution might be this, i'll give it a try