Skip to content

Navigation Menu

Sign in
Sign up

Default value for argument object while reusing #986

Unanswered
scion4581 asked this question in Q&A
Discussion options

Hello!
For example, I have the next two query fields

products:
 type: "[Product]"
 args:
 promotion:
 type: "Int!"
 description: "Promotion ID"
 pager:
 type: "Pager"
 description: "Paginator"
posts:
 type: "[Post]"
 args:
 category:
 type: "Int!"
 description: "Category ID"
 pager:
 type: "Pager"
 description: "Paginator"
 

And simple paginator input object

Pager:
 type: input-object
 config:
 fields:
 offset:
 type: "Int"
 description: "Start from"
 limit:
 type: "Int"
 description: "Items limit"

How can I reuse the paginator field and set different default values for limit and offset fields in products and posts queries?

P.S. Before 0.14 I've used for every pager something like this:

defaultValue: '@=resolver("pagerDefaultValuesResolver", [10, 0])'

And Pager default values resolver class looked like this

class PagerDefaultValuesResolver implements ResolverInterface, AliasedInterface
{
 const DEFAULT_LIMIT = 10;
 const DEFAULT_OFFSET = 0;
 public function resolve(?int $limit = null, ?int $offset = null): ?array
 {
 return [
 'limit' => $limit ?? self::DEFAULT_LIMIT,
 'offset' => $offset ?? self::DEFAULT_OFFSET
 ];
 }
 public static function getAliases(): array
 {
 return ['resolve' => 'pagerDefaultValuesResolver'];
 }
}

Now, this doesn't work :(
I will be grateful for any help
Thanks

You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant

AltStyle によって変換されたページ (->オリジナル) /