Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pagination macro in many_to_many ? #33

Open
mydearxym opened this issue Dec 29, 2017 · 4 comments
Open

pagination macro in many_to_many ? #33

mydearxym opened this issue Dec 29, 2017 · 4 comments

Comments

@mydearxym
Copy link

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
@mydearxym mydearxym changed the title pagination macro ? pagination macro in many_to_many ? Dec 29, 2017
@yordis
Copy link

yordis commented Dec 29, 2017

@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
Copy link
Author

@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
Copy link

yordis commented Dec 29, 2017

@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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants