On the dashboard, in the collections, there’s an edit button there that allows you to edit the document, however, this can cause errors when you are using graphql, particularly because that edit functionality does not seem to convert values to proper types, example would be when we’re using ToDouble
function → read Graphql custom query error: Can't convert '9' to double - #6 by ptpaterson to find out more
Essentially when you have a field there that’s a Double
, it becomes somehow NOT Double
after the edit, which will cause error in the graphql.
I moved this to Feature Requests. It’s a good follow-up to the previous topic!
To clarify, the issue is that whole numbers written in FQL in the Dashboard are serialized to integers, not that all floats are converted to integers. For example 9.0
gets serialized to 9
and thus saved as an integer in the database. 9.1
will, on the other hand, be serialized as the decimal number an correctly saved as a floating point number in the database.
Proposals
Native schema enforcement: Schema enforcement at the DB level could implement type coercion, keeping your data types in sync whether you use GraphQL or FQL.
Improved data marshaling in the Dashboard fql editors: The reason this happens is that the javascript doesn’t differentiate between integers and floating-point numbers, so the JS driver cannot distinguish between 9.0
and 9
, and they both get serialized as just 9
. This proposal would make sure that the Dashboard would respect the number format the user enters, through an update to the JS driver or otherwise.
Workarounds
- Use
ToDouble
to set the value with FQL
- Set the values in Graphql whenever possible. GraphQL correctly respects the number types when it serializes them and sends to the database
2 Likes
Is this like how we do it in MySQL? Because one thing that I like about FaunaDB is how it’s not enforcing any schema like how we do in MySQL, hopefully the flexibility that we get without schema is not going to be compromised when we start to enforced schema. Another solution is for the dashboard to check if there’s a schema.graphql
uploaded, if so then you probably want to ensure that the data are serialized according to that schema while still allowing for some fields not defined in the schema to be serialized in a default manner, basically:
serialization = {
...defaultSerialization,
...graphqlSchema
};
2 Likes
Definitely! That flexibility is one of Fauna’s strongsuites. The schema enforcement that we’re working on is all opt-in and not required
1 Like