You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While apollo-link-rest supports outgoing serialization (defaultSerializer, bodySerializers), there doesn't appear to be a way to serialize the incoming response via the responseTransformer. Our need is for an epoch formatted date to be converted to new Date(). It's clear and documented that this returns an empty {}.
GraphQLScalarType seems like a server side solution before the server response.
const restLink = new RestLink({
endpoints:{
someUsers: {
uri: '/api',
responseTransformer: async response => {
const data = await response.json();
return data.map(user => ({
...user,
created_at: someWayToSerializeThis(new Date(user.created_at)), /// What To Do Here??????
role: setIncomingRole(user.role),
}));
},
},
)}
}
The text was updated successfully, but these errors were encountered:
@redmerten -- I've played with this myself, and unfortunately, this is a limitation of Apollo's InMemoryCache and maybe ApolloClient. - Types will get mangled if they're not JSON-compatible.
I don't have the link handy, but somewhere in ApolloClient there's a discussion of "Custom Scalars"
fbartho
changed the title
Conversion of date epoch to new Date() isn't supported in responseTransformer
Custom Scalars & ApolloLinkRest: DateTimeString,DateTimeEpoch-> new Date() support
Apr 19, 2019
While apollo-link-rest supports outgoing serialization (defaultSerializer, bodySerializers), there doesn't appear to be a way to serialize the incoming response via the responseTransformer. Our need is for an epoch formatted date to be converted to new Date(). It's clear and documented that this returns an empty {}.
GraphQLScalarType seems like a server side solution before the server response.
const restLink = new RestLink({
endpoints:{
someUsers: {
uri: '/api',
responseTransformer: async response => {
const data = await response.json();
return data.map(user => ({
...user,
created_at: someWayToSerializeThis(new Date(user.created_at)), /// What To Do Here??????
role: setIncomingRole(user.role),
}));
},
},
)}
}
The text was updated successfully, but these errors were encountered: