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

Add DSL compiler for Kaminari #2100

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Add DSL compiler for Kaminari #2100

wants to merge 2 commits into from

Conversation

rzane
Copy link
Contributor

@rzane rzane commented Nov 28, 2024

Motivation

Closes #1859

Kaminari is one of the most popular gems in the Rails ecosystem.

Kaminari's .page scope is defined dynamically and not detected by Tapioca's scopes compiler. Also, .page uses .extending to extend the relation with more methods (e.g. .per, .total_count, .total_pages, .current_page).

See issue #1859 for more details.

Implementation

This PR adds a compiler for Kaminari that adds the .page method to GeneratedRelationMethods. The return type is a union:

T.all(PrivateRelation, Kaminari::PageScopeMethods, Kaminari::ActiveRecordRelationMethods)

If the ActiveRecordRelations compiler is not enabled, this compiler will take that into account.

Tests

Tests are included.

@rzane rzane requested a review from a team as a code owner November 28, 2024 16:34
@KaanOzkan
Copy link
Contributor

I think we want to reduce the number of external gem compilers in tapioca. So ideally this would live inside Kaminari repo and be maintained by the gem maintainers. I also remember https://github.com/angellist/boba which aimed to host tapioca compilers. cc @stathis-alexander

@stathis-alexander
Copy link
Contributor

stathis-alexander commented Nov 28, 2024

I think we want to reduce the number of external gem compilers in tapioca. So ideally this would live inside Kaminari repo and be maintained by the gem maintainers.

The idea of gem maintainers hosting their own compilers is a nice future to look forward to!

I also remember https://github.com/angellist/boba which aimed to host tapioca compilers. cc @stathis-alexander

We'd be happy to accept this as part of Boba. We don't use Kaminari (we use graphql), but it fits the concept of the Boba
gem perfectly. We also host compilers for other common gems / DSLs: AttrJson, Paperclip, MoneyRails, etc.

@rzane
Copy link
Contributor Author

rzane commented Nov 28, 2024

Thanks all, I totally missed this note at the bottom of the README: https://github.com/Shopify/tapioca?tab=readme-ov-file#dsl-compilers.

I'll send a PR over to Boba soon.

@rzane rzane closed this Nov 28, 2024
@rzane rzane deleted the kaminari branch November 28, 2024 17:13
@amomchilov amomchilov changed the title Kaminari Add DSL compiler for Kaminari Dec 4, 2024
@andyw8
Copy link
Contributor

andyw8 commented Dec 4, 2024

@rzane 👋 We discussed this a bit more internally and are updating our policy. Could you please try first try asking if Kaminari's maintainers will accept a PR adding this into the gem. If they don't, we will accept it into Tapioca, since it's a gem that Shopify uses.

@rzane rzane restored the kaminari branch December 4, 2024 21:38
@rzane
Copy link
Contributor Author

rzane commented Dec 4, 2024

Submitted an issue here: kaminari/kaminari#1139

@stathis-alexander
Copy link
Contributor

@andyw8 The new policy makes more sense (since you already host non-rails compilers like GQL). Appreciate you including Boba!

How do submitters know whether Shopify uses a particular gem or not? Is the process just:

  1. Open issue with gem
  2. If no or unfavorable response, submit PR to Tapioca
  3. Get feedback from Tapioca maintainers on whether it is acceptable or not?

Additionally, have y'all attempted (recently) to get Rails or GraphQL to accept Tapioca compilers?

@andyw8
Copy link
Contributor

andyw8 commented Dec 5, 2024

Hi @stathis-alexander, yes that process makes sense.

And we'll consider if we can submit compilers to any gems. 👍

@amomchilov
Copy link
Contributor

Looks like this got merged in Boba 👍 angellist/boba#2

@rzane
Copy link
Contributor Author

rzane commented Dec 18, 2024

Yes, that happened prior to @andyw8's suggestion to merge it into Tapioca. I'm sure we can move it here if folks are still interested in doing that.

@rzane
Copy link
Contributor Author

rzane commented Jan 8, 2025

@andyw8, just checking in. I haven't heard a response back from the maintainer of Kaminari. Do we want to continue waiting until we receive a response?

@rzane rzane reopened this Jan 8, 2025
@stathis-alexander
Copy link
Contributor

Is Yuki24 not a maintainer?

kaminari/kaminari#1139 (comment)

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.

Kaminari pagination is not supported by Tapioca
5 participants