Skip to content

Instantly share code, notes, and snippets.

@mateomurphy
Created March 14, 2022 21:09
Show Gist options
  • Select an option

  • Save mateomurphy/7fc3ae4d10ff447fdb42955f805fbb88 to your computer and use it in GitHub Desktop.

Select an option

Save mateomurphy/7fc3ae4d10ff447fdb42955f805fbb88 to your computer and use it in GitHub Desktop.

Revisions

  1. mateomurphy revised this gist Mar 14, 2022. No changes.
  2. mateomurphy created this gist Mar 14, 2022.
    22 changes: 22 additions & 0 deletions apolloScalarsLink.ts
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    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