Skip to content
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

Relax PaginationType getPaginationFields typehint #1132

Merged
merged 7 commits into from
Mar 6, 2024
Merged

Relax PaginationType getPaginationFields typehint #1132

merged 7 commits into from
Mar 6, 2024

Conversation

jasonvarga
Copy link
Contributor

@jasonvarga jasonvarga commented Mar 5, 2024

Summary

When upgrading a project from 8.0 to 9.0, I began to see errors around pagination:

TypeError: Rebing\GraphQL\Support\PaginationType::getPaginationFields(): Argument #1 ($underlyingType) must be of type GraphQL\Type\Definition\ObjectType, GraphQL\Type\Definition\InterfaceType given, called in /path/to/rebing/graphql-laravel/src/Support/PaginationType.php on line 22

We have queries where the type is a paginator with interfaces:

class EntriesQuery extends Query
{
    public function type(): Type
    {
        return GraphQL::paginate(GraphQL::type('EntryInterface'));
    }
}

This has worked fine until v9 (specifically #1033) since the typehint of PaginationType::getPaginationFields() was changed to ObjectType.

This PR changes the typehint from an ObjectType definition to the parent Type definition, which covers both ObjectType and InterfaceType.

I'm not sure if there's a specific reason ObjectType was used, but this fixes our issue and all of this package's tests continue to pass.

Also, I'm sorry but I don't understand what's up with the phpstan stuff. 😊


Type of change:

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Misc. change (internal, infrastructure, maintenance, etc.)

Checklist:

  • Existing tests have been adapted and/or new tests have been added
  • Add a CHANGELOG.md entry
  • Update the README.md
  • Code style has been fixed via composer fix-style

@mfn mfn self-assigned this Mar 6, 2024
Copy link
Collaborator

@mfn mfn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the change is ok!

Also relaxing should not be a breaking change, so we would not need to do a major version bump, WDYT?

Can you please add a dedicated test, i.e. one which covers what you needed it for (support for interface type)?

(I can take care of the phpstan once all is done here)

@jasonvarga
Copy link
Contributor Author

Also relaxing should not be a breaking change, so we would not need to do a major version bump, WDYT?

Nah I don't think it needs to be breaking.

Can you please add a dedicated test, i.e. one which covers what you needed it for (support for interface type)?

Can do 👍 Thanks!

@jasonvarga
Copy link
Contributor Author

jasonvarga commented Mar 6, 2024

I've added/modified tests where the existing pagination test was.

There's an assertion on the generated sql that doesn't currently pass because of an unrelated issue, so I've left it in there but commented out: 392c17d (#1132)

The sql should be select "posts"."id" but is currently select * - I believe this is the same or similar issue as #683.

I think it's out of scope of this PR to fix it.

Anyway, the tests in this class would fail without the typehint change in getPaginationFields.

@jasonvarga jasonvarga mentioned this pull request Mar 6, 2024
6 tasks
Copy link
Collaborator

@mfn mfn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Solid work, thank you!

Will roll a release right after merge.

@mfn mfn merged commit cea7c78 into rebing:master Mar 6, 2024
17 checks passed
@jasonvarga
Copy link
Contributor Author

Thank you!

@jasonvarga jasonvarga deleted the get-pagination-fields-typehint branch March 6, 2024 20:28
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

Successfully merging this pull request may close these issues.

2 participants