do you know how can I store arbitrary JSON objects via the GraphQL endpoint?
The doc specifies there are no Union types nor are there Object types for Inputs.
I’ve thought about serializing JSON to a string, but that’s a shame because Fauna already supports Objects at its core.
Besides, it makes it complicated to have operations on the said JSON object such as pushing into an array, as I’ll probably have to update the entire object afterward.
Any ideas of a workaround?
Thanks, It’s a better place for the team to answer this one I believe! (@lregnier? )
I’d say the suggested way of storing arbitrary JSON objects through the GraphQL API at the moment is to serialize them as Strings. On the downside, this would mean that, as you already mentioned, any type advantages would be lost in the process.
This has come up before, and we were considering implementing a JSON Scalar type for doing so. Something similar to graphql-type-json.
Also, since you brought it up in the question, I’m wondering if the use of Interfaces or Unions would be actually the right option for covering your use case. Those might not be as flexible as a JSON Scalar in certain scenarios, but depending on your needs, those might be just what you’re looking for. Although Interfaces and Unions are yet not supported, those are definitely in our plans.
If you could share with us a bit more about your use case, we might identify the most appropriate solution for it in the long term! This would also help us to prioritize the support for Interfaces, Unions and JSON Scalar types.
It’s great to hear you’ve thought about it.
What I like about storing plain JSON is the versatility it offers.
In my case, the data is user-generated and can take multiple forms.
Say a form that has multiple, different, and arbitrary input types for example. All defined by the user.
Right now I opted to serialize both the form schema and the records as strings, although it’s definitely less practical and useful if I want to operate on those, for example being able to search a specific record by a specific type.
For that, graphql-type-json is looking good.
Regarding Unions Types, it could come in handy, But I would still have to declare all possible input types beforehand. This greatly reduces productivity and versatility (although an argument can be made for stability and type safety).
Also, I don’t know what you mean by “Interfaces”
On a more general note, my feedback is that Fauna is powerful, I can feel it, but it needs a little polish to make simple use cases actually simple. For many like me, starting a project is an ever-changing process, and having the flexibility of storing plain arbitrary JSON is a real benefit to move quickly.
Thank you for all of your feedback, @dotlouis!
Yes, according to your use case, it looks like you would need a JSON scalar type for storing that kind of data. We will definitely take your feedback into account when putting this feature together.
Regarding Interfaces, those are just another GraphQL type. They are similar to Unions, but they allow you to define a set of common fields for the types implementing them. Below, you should find more info about them:
We’re putting a great focus on improving the overall development experience (including FQL, GraphQL, Drivers and Console), so hopefully you will find Fauna easier and easier to work with over time!