Skip to content

NonNull type for data in pagination and NonNull ListOf type #872

@do6po

Description

@do6po

Versions:

  • graphql-laravel Version: all with current
  • Laravel Version: 8.77.1
  • PHP Version:8.0

Description:

I want to make the list (data) and type inside the paginator to be required. But there is a problem with the possible selectable fields. This is due to the lack of a recursion parameter when calling the getWrappedType method in the SelectFields class on line 188. If you pass an argument to the getWrappedType method to retrieve data recursively, everything will work correctly.

like this

                if (is_a($parentType, Config::get('graphql.pagination_type', PaginationType::class)) ||
                    is_a($parentType, Config::get('graphql.simple_pagination_type', SimplePaginationType::class))) {
                    /* @var GraphqlType $fieldType */
                    $fieldType = $fieldObject->config['type'];
                    static::handleFields(
                        $queryArgs,
                        $field,
                        $fieldType->getWrappedType(true), //<---
                        $select,
                        $with,
                        $ctx
                    );
                }

Steps To Reproduce:

    public function type(): Type
    {
        return GraphQL::paginate(
            Type::nonNull(
                GraphQL::type('someType')
            )
        );
    }

and inside extends PaginationType

    protected function getPaginationFields(string $typeName): array
    {
        return [
            'data' => [
                'type' => Type::nonNull(
                    Type::listOf(
                        GraphQL::type($typeName)
                    )
                ),
...

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions