wagtail-grapple icon indicating copy to clipboard operation
wagtail-grapple copied to clipboard

JSONField output is not valid JSON

Open fabienheureux opened this issue 3 years ago • 5 comments

When using a JSONField through Grapple using a GraphQLString type, the output is not valid JSON.

Let's take the example below: image

The stringified version of {"coucou": "youpi"} uses single quote, which is not valid json. Some potential fixes I think of

  • 1️⃣ We consider it is outside of Grapple's scope to handle JSON, and requires the user to handle this on his side (which is 100% doable). It might be worth adding this to the docs
  • 2️⃣ We detect usage of JSONField and output the string properly in GraphQLString
  • 3️⃣ We add a GraphQLJSON type in Grapple

What do you think ? Interesting discussion on this topic: https://github.com/graphql-python/graphene-django/issues/303#issuecomment-440450677

fabienheureux avatar Sep 01 '21 14:09 fabienheureux

While 1️⃣ was my gut feeling (well, it is the easiest 😂), I think 2️⃣ is the more appropriate response. Happy to hear alternatives. e.g. what added benefit would a GraphQLJSON type bring other than being more explicit?

zerolab avatar Sep 03 '21 08:09 zerolab

I don't think 3️⃣has any added benefit other than the one you mentionned. I will fix this in an incoming PR then, thanks for your feedback.

fabienheureux avatar Sep 03 '21 09:09 fabienheureux

@fabienheureux do you remember if fixed this?

dopry avatar May 12 '23 18:05 dopry

Also wondering where we landed on this!

ssyberg avatar Feb 02 '24 18:02 ssyberg

This hasn't happened yet. A PR would be most welcome

zerolab avatar Feb 04 '24 11:02 zerolab