Skip to content

Exposing a JSON field from SQLModel to Strawberry #1661

Answered by patrick91
martarho asked this question in Q&A
Discussion options

You must be logged in to vote

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 (hopefu…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@martarho
Comment options

Answer selected by patrick91
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants