-
Notifications
You must be signed in to change notification settings - Fork 124
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
Allow to pass a custom serializer and deserializer #199
Allow to pass a custom serializer and deserializer #199
Conversation
@davidyaha do you think this PR can be merged? Thx. |
Hey @quentinus95! Sorry for the delay. One question, could you explain in one sentence the difference between reviver and deserializer in your implementation? Thanks ahead! |
} | ||
}); | ||
|
||
it('allows to use a custom deserializer', done => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@quentinus95 Please add tests for when serializers or deserializers throws an error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would you expect from such a situation? Current behavior, if I'm not wrong, is that the error would be thrown directly to the subscriber / dispatcher. Do you feel this behavior is wrong?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the deserializer the code just ignores the error and gives back the message unmarshalled:
https://github.com/davidyaha/graphql-redis-subscriptions/pull/199/files#diff-3b3bf6f5369f165d6124779b61832724R162-R166
I feel like that's a behaviour that we can change if such a request arises from the community.
I would much rather have a discussion about that in a dedicated issue rather than change the behaviour.
So for the moment, don't change the package code but regardless, we should have tests demonstrating the behaviour.
Thanks!
@davidyaha if I'm not wrong, a reviver would take a single scalar value and allow to turn it into something else (e.g. a timestamp number to a date instance). The main issue is when you want to create a class instance from a set of properties. The deserializer allows you to use, for instance, https://github.com/typestack/class-transformer to create real class instances from a JSON object. It can be very convenient to dispatch an event represented by a class instance, and re-create it from the serialized object in the subscriber. |
Yeah, I now realize the change in behavior. I think the codebase should reflect that granularity. would you mind changing the code to something of that sort: const deserializer = this.derializer || (msg) => JSON.parse(msg, this.reviver);
try {
parsedMessage = deserializer(message);
} Thanks ahead |
…om serialization/deserialization
hey @quentinus95 I've submitted a PR to address the requested tests, hope that helps. |
added tests related to custom serialization and deserialization errors
@asabhaney many thanks, I've just added your commit to the PR. |
@davidyaha non passing tests are unrelated to the changes. |
@davidyaha any chance of having this PR merged in soon? If there's anything I can do, I'm happy to help move this along. Thanks! |
Hey, @asabhaney and @quentinus95! |
Release version 2.2.0. LMK if anything is wrong there. |
Great, thanks so much @davidyaha @quentinus95! |
Fixes #182.
Allows to pass a custom deserialize function, for instance to retrieve class instances.