Skip to content

GraphQL not working with "partial" enabled #3215

Description

@tdel

API Platform version(s) affected: 2.5.*

Description
When enabling partial, GraphQL doesn't work anymore. This is the error returned :
"message": "Collection returned by the collection data provider must implement ApiPlatform\\Core\\DataProvider\\PaginatorInterface"

How to reproduce
Enable partial in api_platform.yaml file :

    collection: 
        pagination: 
            enabled: true
            partial: true

Then try to query a collection resource via GraphQL. It's not working. Disabling partial make things worked again.

Possible Solution
File : src/GraphQl/Resolver/Stage/SerializeStage.php @ line 120
Replace by :

        if (!($collection instanceof PaginatorInterface)) {
            $data = $this->getDefaultPaginatedData();
            $index = $offset = 0;
            foreach ($collection as $object) {
                $data['edges'][$index] = [
                    'node' => $this->normalizer->normalize($object, ItemNormalizer::FORMAT, $normalizationContext),
                    'cursor' => base64_encode((string) ($index)),
                ];
                ++$index;
            }
            return $data;
        }

In this case, $collection is an anonymous class implementing PartialPaginatorInterface and not PaginatorInterface (which extends PartialPaginatorInterface).

How can I use partial with REST but not with GraphQL ?

Thanks a lot,

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Fields

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions