getName()}{$suffix}!]"); $this->directives([ 'sortCustom' => [ 'columns' => json_encode($this->resolveColumns()), ], ]); } /** * Resolve the columns parameter for the sortCustom directive. * * @return array> */ private function resolveColumns(): array { return collect($this->type->fields()) ->filter(fn (Field $field) => $field instanceof SortableField) ->map(fn (Field&SortableField $field) => [ SortCustomDirective::INPUT_COLUMN => $field->getColumn(), SortCustomDirective::INPUT_VALUE => Str::of($field->getName())->snake()->upper()->__toString(), SortCustomDirective::INPUT_SORT_TYPE => $field->sortType()->value, SortCustomDirective::INPUT_RELATION => method_exists($field, 'relation') ? $field->{'relation'}() : null, ]) // @phpstan-ignore-next-line ->push([ SortCustomDirective::INPUT_VALUE => RandomSort::CASE, ]) ->toArray(); } }