andyrichardson / subscriptionless

GraphQL subscriptions (and more) on serverless infrastructure
MIT License
93 stars 3 forks source link

withFilter example & typings #27

Closed oyed closed 3 years ago

oyed commented 3 years ago

Loving the library! I'm trying to add filters to my subscriptions, but can't seem to understand the format.

Would it be possible to have the example in the repo use it?

I also noticed that since it doesn't return an AsyncIterator, typings kinda fail for graphql-codegen generated types

oyed commented 3 years ago

If I'm reading this correctly (https://github.com/andyrichardson/subscriptionless/blob/master/src/pubsub/publish.ts#L66), the filter object defined in withFilter is stored against the subscription in DDB (To remain stateless), however using equals would mean both payloads have to match in their entirety right?

E.g. a subscription payload of:

{
  "user_id": 1,
  "hello": "world"
}

Wouldn't match against a withFilter definition of:

withFilter(subscribe('MY_TOPIC'), (root, args, context, info) => ({
  user_id: args.user_id,
}));

Since withFilter doesn't include a hello key value pair?

oyed commented 3 years ago

My bad - re-read and noticed that it's creating those comparisons per key => value, not the overall object. My context generator wasn't working properly which was the issue.