A custom scalar type named Date which is an ISO 8601 string is defined in the backend.
In the frontend "GraphQL Code Generator" (https://www.graphql-code-generator.com/) is used to generate typescript types from the schema.
The codegen.yml looks like this:
overwrite: true
schema: 'http://mybackenurl/graphql'
documents: 'src/**/*.graphql'
generates:
src/generated/graphql.ts:
config:
exposeQueryKeys: true
exposeFetcher: true
fetcher: '../GraphQLFetcher#fetcher'
scalars:
Date: Date
plugins:
- 'typescript'
- 'typescript-operations'
- 'typescript-react-query'
This gives types where all fields with the custom scalar type Date in the graphql schema corresponds to the typescript type Date in the generated typescript types. However at runtime it is still a string. If the part with Date: Date under scalars in the configuration is removed, the corresponding type is Any.
The guess is that we need to specify some kind of mapper which converts from the ISO 8601 string we get from the backend to a typescript Date, but I do not understand how this is can be done.