Add custom subscription store interface#54
Conversation
palkan
left a comment
There was a problem hiding this comment.
Thanks!
Finally, we can make graphql-anycable Redis-independent! That's a good idea.
However, I'm not sure that we should add Postgres adapter implementation to the core gem. I'd prefer to have it as a standalone plugin (well, tbh, and not to maintain ourself).
Let's keep only the refactoring part with a clear interface for defining and using custom adapters in this PR (so we can release it independently and quicker), and then you can create a standalone graphql-anycable_postgresql-store gem (or whatever).
|
Split it out into it's own gem, should be ready in a bit. I'll take a look at the go lib at the end of the day. |
palkan
left a comment
There was a problem hiding this comment.
Thanks! Almost there.
Left some comments.
Note: this feature deserves a major upgrade (2.0), so introducing minor incompatible changes in the interface is fine.
palkan
left a comment
There was a problem hiding this comment.
Looks good 👍
One more thing we've missed—Cleaner: https://github.com/anycable/graphql-anycable/blob/master/lib/graphql/anycable/cleaner.rb
We should also make it adapter-agnostic.
In the end, I think we should have the following structure for the Redis store:
graphql/anycable/subscription_stores/
redis/
cleaner.rb
stats.rb
redis.rb
That is, let's extract Stats object from the store (just re-organize the code, keep the interface) and add the cleaner object to be used by the Rake tasks.
|
@palkan Done |
|
Ah, sorry about that. We normally explicitly test delegations so it inherited our rules. Should be cleaned up now |
Summary
Adds a custom subscription store interface to
graphql-anycablewhile keeping Redis as the built-in default store.This trims the PR down to the refactoring/interface layer requested in review. The PostgreSQL implementation has been moved to a standalone gem owned under TikiTDO: https://github.com/TikiTDO/graphql-anycable_postgresql-store
What Changed
GraphQL::AnyCable.register_subscription_store(name) { ... }for external store adapters.GraphQL::AnyCable.subscription_store = storefor direct store injection.with_subscription_store.GraphQL::AnyCable::SubscriptionStores::Redis.pgdevelopment dependency, and PostgreSQL-specific core config.Store Interface
A custom store object implements:
stream_for(fingerprint)fingerprints_for_topic(topic)subscription_ids_for_fingerprints(fingerprints)subscription_exists?(subscription_id)write_subscription(subscription_id, channel_id:, data:, events:, expiration_seconds:)read_subscription(subscription_id)delete_channel_subscriptions(channel_id)delete_subscription(subscription_id)Reviewer Focus
GraphQL::AnyCable.Validation
Passed against a temporary isolated Redis container:
REDIS_URL=redis://localhost:56379/6 bundle exec rspecPassed syntax/diff checks:
Related Follow-Up
Checklist