-
I have a float field, but sometimes, in actual MongoDB, it has a value of NaN, undefined, so Prisma will throw an error. My solution is to declare it as a string in Prisma and process it in the resolve function. Please take a look at the code below. Is this the best way?
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
This looks reasonable to me. I think having resolvers for cases where your data isn't already in the format you want in your schema makes sense, are you running into any issues with this pattern? |
Beta Was this translation helpful? Give feedback.
-
You can technically set up your own Float scalar rather than using the built in one that can convert strings to the right value. This would work the same as adding a custom scalar, and you would just use string | number as the output type. You'd need to implement a serialize function that parses the strings to numbers of the vue is a string |
Beta Was this translation helpful? Give feedback.
That's pretty subjective. Personally I'd put it in a resolver, but if you are doing it a lot, doing it in a scalar might make more sense, since you won't need to repeat it all over the place. The downside is that any string will be accepted as a valid value for any float field, which reduces type safety a bit.