-
Hi everyone, I'm currently working with a postgresql database which contains a table with a JSONB field. I modelled it with SQLModel, and I'm trying to apply on top Strawberry to explose the data through GraphQL. The problem is dictionaries are not an accepted type on the graphql side. What's the recommended way one should deal with these cases? I'm currently learning both SQLModel and Strawberry, so if someone can show me an example it would be grand!
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
hey @martarho 😊 You'd need to create a custom scalar and then use that in your GraphQL type: JSON = scalar(
NewType("JSON", object), # mypy doesn't like `NewType("name", Any)`
description="The `JSON` scalar type represents JSON values as specified by"
" [ECMA-404](http://www.ecma-international.org"
"/publications/files/ECMA-ST/ECMA-404.pdf).",
specified_by_url="http://www.ecma-international.org"
"/publications/files/ECMA-ST/ECMA-404.pdf",
serialize=lambda v: v,
parse_value=lambda v: v,
)
@strawberry.experimental.pydantic.type(
MyModel
)
class MyModelGQL:
id: auto
name: auto
jsonfield: JSON note, we'll be adding the JSON scalar soon (hopefully later today) see: #1647 |
Beta Was this translation helpful? Give feedback.
hey @martarho 😊 You'd need to create a custom scalar and then use that in your GraphQL type:
note, we'll be adding the JSON scalar soon (hopefu…