I'm learning GraphQL and Apollo for a new project,...
# random
c
I'm learning GraphQL and Apollo for a new project, and found this page about custom scalars https://www.apollographql.com/docs/apollo-server/schema/custom-scalars/. I'm using Postgres with Prisma, and have several models with date
DateTime @db.Date
, date-time
DateTime
, and time
DateTime @db.Time
fields as well as a few fields storing JSON
Json
. Wondering if custom scalars are generally recommended as a best practice? Seems better than just making them all strings. If so, has anyone else created different custom scalars for a date by itself, vs date-time, vs time only?
a
Hey Chris, I would recommend taking a look at graphql-scalars by The Guild. There are Json and DateTime scalars you can make use of 🙂
👍 2
c
I think they generally are a good idea to use, but exercise caution because I’ve run into issues with them when I didn’t fully understand how the serialization worked. For example, a BigInt scalar usually serializes to a string, which can be easy to overlook. They’re generally great because you get free input/output validation and make the schema more expressive, but there’s definitely places where I avoided using them because I wanted more control over the serialization methodology.
🙌🏽 1
🙌 1