How to store arbitrary JSON object via GraphQL?

Hey, @dotlouis & @gahabeen!

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.

Thank you!

4 Likes