Skip to content

3.0 / GraphQL: is paginationEnabled supposed to propagate to subresources? #5001

Description

@phtmgt

API Platform version(s) affected: 3.0

Description
I am trying to get a subresource collection w/out pagination and in the same time I want the parent resource to have pagination.

Pagination is enabled globally.

I was left with the impression that disabling for a specific resource by doing

#[ApiResource(paginationEnabled: false)]

does not allow querying for a paginated collection with that resource.

However, I've been banging my head against the wall for a whole day. What basically happens is the paginationEnabled setting propagates to the child (or I've got something completely wrong).

How to reproduce

Case 1 - pagination enabled globally, parent has no pagination setting (i.e., defaults to enabled), child has paginationEnabled set to false:

Parent:

#[ApiResource()]

Child (ManyToMany):

#[ApiResource( paginationEnabled: false)]
#[ApiResource(
    uriTemplate: '/parents/{id}/children.{_format}',
    uriVariables: [
        'id' => new Link(
            fromClass: Parent::class,
            fromProperty: 'children'
        )
    ],
    operations: [new GetCollection()],
)]

Result: pagination is enabled on Child when queried for through parent.

Case 2 (complete opposite) - pagination enabled globally, parent has pagination disabled, child has paginationEnabled set to true:

Parent:

#[ApiResource(paginationEnabled: false)]

Child (ManyToMany):

#[ApiResource(paginationEnabled: true)]
#[ApiResource(
    uriTemplate: '/parents/{id}/children.{_format}',
    uriVariables: [
        'id' => new Link(
            fromClass: Parent::class,
            fromProperty: 'children'
        )
    ],
    operations: [new GetCollection()],
)]

Result: Child is NOT paginated.

Case 3 (control) - pagination disabled globally, parent has no explicit setting, child has paginationEnabled set to true:

Parent:

#[ApiResource()]

Child (ManyToMany):

#[ApiResource(paginationEnabled: true)]
#[ApiResource(
    uriTemplate: '/parents/{id}/children.{_format}',
    uriVariables: [
        'id' => new Link(
            fromClass: Parent::class,
            fromProperty: 'children'
        )
    ],
    operations: [new GetCollection()],
)]

Result: Child is NOT paginated.

Possible Solution

Am I reading the docs wrong? Pagination settings on an ApiResource should only affect this resource, not propagate down to sub resources (at least this is how I remember things worked in 2.6.x). Or maybe I am not using the correct syntax? I believe I tried everything I could think of.

Additional Context

Is this the intended operation? Seems completely counterintuitive to have pagination settings propagate to subresources. Is it even supposed to propagate? I thought the paginationEnabled setting is supposed to apply to the ApiResource / Class, not affect subresources? From the control case I can see that basically this setting only applies to sub resources. If this is the intended effect, documentation needs to be more verbose, as this is completely different from how I remember 2.6 worked.

I also tried putting the paginationEnabled directive here:

#[ApiResource(
    uriTemplate: '/parents/{id}/children.{_format}',
    uriVariables: [
        'id' => new Link(
            fromClass: Parent::class,
            fromProperty: 'children'
        )
    ],
    paginationEnabled: false,
    operations: [new GetCollection()],
)]

Same results.

Finally, I triple-checked and in production on 2.6.x the 'pagination_enabled' setting set through annotations (via 'attributes') works as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions