Support Ukraine 🇺🇦Help Ukrainian ArmyHumanitarian Assistance to Ukrainians

Relay compiler provides no type for the DateTime scalar

thoughtful

Jan 12 2020 at 17:09 GMT

I have some fields like createdAt that are typed as the custom DateTime scalar type (provided by the graphql-iso-date npm package) in my GraphQL schema.

The problem is that when the Relay compiler generates TypeScript types, the type specified for the DateTime fields is unknown.

Since DateTime fields are just strings representing an ISO date, can we make the Relay compiler specify string as the type of those fields instead of unknown?

1 Answer

john

Jan 12 2020 at 17:22 GMT

You can specify the type for any custom scalar type that you might have in your GraphQL schema by providing the following command line argument to the relay-compiler:

--customScalars.<ScalarName>=<ScalarType>

Where <ScalarName> is the name of your custom scalar type, e.g., DateTime, and <ScalarType> is one of the built-in GraphQL scalar types, e.g., String or Int.

So, in your case, you would specify

--customScalars.DateTime=String

If you have more than one scalar type, just specify the --customScalars argument multiple times.

claritician © 2022