Created
March 14, 2022 21:09
-
-
Save mateomurphy/7fc3ae4d10ff447fdb42955f805fbb88 to your computer and use it in GitHub Desktop.
Am Apollo Link for converting `ISO8601DateTime`s in graphql to `Date` objects
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { withScalars } from 'apollo-link-scalars' | |
import { buildClientSchema, IntrospectionQuery } from 'graphql' | |
import introspectionResult from '../graphql/schema.json' | |
const typesMap = { | |
ISO8601DateTime: { | |
serialize: (parsed: any) => parsed && parsed.toISOString(), | |
parseValue: (raw: any) => raw && new Date(raw), | |
}, | |
} | |
const schema = buildClientSchema( | |
(introspectionResult as unknown) as IntrospectionQuery | |
) | |
const scalarsLink = withScalars({ | |
schema, | |
typesMap, | |
}) | |
export default scalarsLink |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment