Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Manage JSONB fields #87

Open
gmlion opened this issue May 30, 2023 · 2 comments
Open

Manage JSONB fields #87

gmlion opened this issue May 30, 2023 · 2 comments

Comments

@gmlion
Copy link

gmlion commented May 30, 2023

Hi,
we found that JSONB fields are generated as Option properties, and upon insertion they are saved a escaped JSON strings, such as "{\"name\":\"abc\"}"
We're using Hasura as GraphQL backend.
Are JSON fields unsupported?

@Zaid-Ajaj
Copy link
Owner

Hi @gmlion,

Can you please provide a subset of your schema or your full schema from which the types are generated? If they are generated as optional fields, it means the hasura backend annotated them as such.

In postgres databases, assuming that is what you are working with in hasura, jsonb fields are just strings so it makes sense that they are saved as escaped strings. Since the data of JSONB fields can be of any shape, they are always serialized as strings and you are expected to deserialize them on the client side yourself.

@gmlion
Copy link
Author

gmlion commented May 30, 2023

This is the schema portion about a JSONB field

{
              "name": "customData",
              "description": null,
              "args": [
                {
                  "name": "path",
                  "description": "JSON select path",
                  "type": {
                    "kind": "SCALAR",
                    "name": "String",
                    "ofType": null
                  },
                  "defaultValue": null
                }
              ],
              "type": {
                "kind": "NON_NULL",
                "name": null,
                "ofType": {
                  "kind": "SCALAR",
                  "name": "jsonb",
                  "ofType": null
                }
              },
              "isDeprecated": false,
              "deprecationReason": null
            }

Our issue is that inserting values using Snowflaqe they are inserted as json strings, and stored as such. Using other means, we can insert a string representing a json object and have it stored as such.
For example:

query {
  entity {
    json_data
  }
}

// response

{
  "data": {
    "entity": [
      {
        "json_data": {
          "mean": "not-snowflaqe"
        }
      },
      {
        "json_data": "{\"mean\":\"snowflaqe\"}"
      }
    ]
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants