https://github.com/cult-of-coders/apollo-client-transformers
Bringing the ability to parse data using Apollo Client
https://github.com/cult-of-coders/apollo-client-transformers
Last synced: 5 months ago
JSON representation
Bringing the ability to parse data using Apollo Client
- Host: GitHub
- URL: https://github.com/cult-of-coders/apollo-client-transformers
- Owner: cult-of-coders
- License: mit
- Created: 2018-06-27T16:57:12.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2021-01-27T03:41:06.000Z (about 4 years ago)
- Last Synced: 2024-11-07T04:48:21.698Z (6 months ago)
- Language: TypeScript
- Size: 9.77 KB
- Stars: 31
- Watchers: 4
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Apollo Client Transformers
[](https://travis-ci.org/cult-of-coders/apollo-client-transformers)
[](https://github.com/prettier/prettier)This package is useful for when you have scalars, but you receive them serialized on the client and you don't really want to do the deserialisation in your view layer.
## Install
```
npm i -S apollo-client-transform
```## Usage
```js
import { createTransformerLink } from 'apollo-client-transform';const DateTransformer = {
parseValue(time) {
return new Date(time);
},
};const transformers = {
User: {
createdAt: DateTransformer,
},
};const transformerLink = createTransformerLink(transformers);
// You can now concatenate it with your http link before creating the client like so:
const enhancedHttpLink = transformerLink.concat(httpLink);
```## Usage with subscriptions
```js
import { createTransformerLink, isSubscription } from "apollo-client-transform";
import { split } from "apollo-link";...
const link = split(({ query }) => isSubscription(query), wsLink, httpLink);
const client = new ApolloClient({
...
link: transformerLink.concat(link)
});
```