Add support for custom event serialization (Was: Serialization is breaking Dates)
See original GitHub issueI’m using the Date type as in this documentation page https://www.apollographql.com/docs/graphql-tools/scalars.html
Date: new GraphQLScalarType({
name: 'Date',
description: 'Date custom scalar type',
parseValue(value) {
return new Date(value); // value from the client
},
serialize(value) {
return value.getTime(); // value sent to the client
},
parseLiteral(ast) {
if (ast.kind === Kind.INT) {
return parseInt(ast.value, 10); // ast value is always in string format
}
return null;
},
}),
I’m doing a findOne with Mongoose, and pass the returned document to the pubsub like this:
pubsub.publish('bookUpdated', { bookUpdated: book });
In my network tab, in the websocket, I’m getting the following error:
value.getTime is not a function in ["bookUpdated", "events", 1, "timestamp"]
The same code works without problem with the in-memory PubSub. This bug only affects RedisPubSub. Certainly because of the use of JSON.stringify and JSON.parse. See https://stackoverflow.com/questions/4511705/how-to-parse-json-to-receive-a-date-object-in-javascript
So I’m not sure if this can be considered a graphql-redis-subscriptions bug, but both PubSub are supposed to give the same result, I think.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:5 (5 by maintainers)
Top Results From Across the Web
CA2229: Implement serialization constructors (code analysis)
A type supports custom serialization if it implements the ISerializable interface. The serialization constructor is required to deserialize, or ...
Read more >json - Jackson SerializationFeature ...
Date fields from being serialised into timestamps when converting to JSON responses in my @RestController. However I cannot get it to work. All...
Read more >Solved: event serialization using custom code
Solved: I am new to event serialization and could use some helpful tips from the community. I read that to implement event serialization,...
Read more >Sitecore Serialization Guide
For more information about using event handlers, see the Serializing Items Using Event. Handlers section. •. You can use the Sitecore service page...
Read more >Everything You Need to Know About Java Serialization ...
Customizing Serialization and Deserialization With writeObject and readObject Methods. The JVM has full control for serializing the object in ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I thought about this some more and made this a configurable option instead. Probably don’t want to make all users suffer a performance hit. Not setting the reviver defaults to existing functionality.
I think, in the future, better serialization and deserialization support is ideal (flattening the json object, handling custom constructors, etc.) but this works for our use case right now and has minimal impact.
Hey @awwong1! Sorry for the delay, just published graphql-redis-subscriptions@1.5.0 Let me know if there are any problems with the new release.