Skip to content
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

Custom Scalars & ApolloLinkRest: DateTimeString,DateTimeEpoch-> new Date() support #205

Open
redmerten opened this issue Apr 19, 2019 · 5 comments
Labels
enhancement💡 good first issue Issues that are suitable for first-time contributors. help wanted 🛠

Comments

@redmerten
Copy link

"apollo-cache-inmemory": "^1.4.2",
"apollo-client": "^2.5.0",
"apollo-link": "^1.2.8",
"apollo-link-error": "^1.1.10",
"apollo-link-rest": "^0.7.0",

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),
}));
},
},
)}
}

@fbartho
Copy link
Collaborator

fbartho commented Apr 19, 2019

@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
Copy link
Collaborator

fbartho commented Apr 19, 2019

Oh crap! It may be doable now:
For the backend: https://www.apollographql.com/docs/graphql-tools/scalars

I think we need to figure out if this is usable by ApolloClient!

@fbartho fbartho added enhancement💡 good first issue Issues that are suitable for first-time contributors. help wanted 🛠 labels Apr 19, 2019
@fbartho 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
@redmerten
Copy link
Author

Right - I tried that on the client side. Would be great if you can get that working in the responseTransformer. Thanks!

@fbartho
Copy link
Collaborator

fbartho commented Apr 19, 2019

@redmerten Unfortunately, this is still a requested feature for Apollo Client - Core. I found the root issue here: https://github.com/apollographql/apollo-feature-requests/issues/2

Please go there & upvote it!

@fbartho
Copy link
Collaborator

fbartho commented Jan 5, 2022

Still blocked upstream.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement💡 good first issue Issues that are suitable for first-time contributors. help wanted 🛠
Projects
None yet
Development

No branches or pull requests

2 participants