Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
phtmgt opened this issue Sep 22, 2022 · 3 comments
Closed

Comments

@phtmgt
Copy link

phtmgt commented Sep 22, 2022

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.

@webda2l
Copy link
Contributor

webda2l commented Sep 22, 2022

The last syntax is the right one.
Try the fork #4930

@phtmgt
Copy link
Author

phtmgt commented Sep 23, 2022

Wow, this is magic. Pasted the changes (since I am using 3.0) and voila, it all works. Thanks!

@phtmgt phtmgt closed this as completed Sep 23, 2022
@webda2l
Copy link
Contributor

webda2l commented Sep 23, 2022

You have this fork of 3.0 (https://github.com/OLYBe/core/tree/fix-graphql-coll-disabledpaginated-type) that I use in production, which include another pending graphql fix (PR still require tests) and another performance fix.
main...OLYBe:core:fix-graphql-coll-disabledpaginated-type

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants