I'd like to get fields resolved by another field.
I have a list generated according to some arguments and would like to update the total field
My approach is probably incorrect.
Obviously, I'm trying to avoid re-running the same database query and passing filter up a level in the query string.
So assume the following ruby type for my query:
Types::PostListType = GraphQL::ObjectType.define do
name 'PostList'
field :total, !types.Int, default_value: 0 # <-- this is what I'd like to update in :posts resolution
field :page, !types.Int, default_value: 0 # <-- this is what I'd like to update in :posts resolution
field :per_page, !types.Int, default_value: 0 # <-- this is what I'd like to update in :posts resolution
field :posts, types[Types::PostType] do
argument :page, types.Int, default_value: 1
argument :per_page, types.Int, default_value: 10 # <-- also need a limit here (hence why I need a field to tell what's been used in the end)
argument :filter, types.String, default_value: ''
resolve ->(user, *_args) {
posts = function_to_filter(args[:filter])
# how do I update total with posts.count here?
posts.paginate(page: args[:page], per_page: args[:per_page])
# how do I update per_page and page?
}
end
end
My query is something like this:
query ProspectList {
posts(filter:"example", page: 2) {
total
page
per_page
posts {
id
...
}
}
}