You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to define a GQL Pydantic model w/ a JSON scalar attribute:
JSONScalar = strawberry.scalar(
NewType("JSONScalar", Any),
serialize=lambda v: v,
parse_value=lambda v: json.loads(v),
description="The GenericScalar scalar type represents a generic GraphQL scalar value that could be: List or Object."
)
class ResourcePyd(PydanticModel):
type: str
# TODO: Figure out how to use `Json` type for this attribute
# spec: Optional[Json]
# spec: Optional[str]
spec: Optional[JSONScalar]
However I can't get Pydantic to comply:
[cloud-app] [Tue Nov 9 17:21:12 2021] Running: pytest --durations=3
[cloud-app] ImportError while loading conftest '/cloud-app/tests/conftest.py'.
[cloud-app] tests/conftest.py:24: in <module>
[cloud-app] import app.gql_mutations as gql_mutations
[cloud-app] app/gql_mutations.py:21: in <module>
[cloud-app] from app.gql_errors import BadRequest, NotAuthorized, InternalError
[cloud-app] app/gql_errors.py:15: in <module>
[cloud-app] from app.models import Error, Errors, ResponseCode
[cloud-app] app/models.py:128: in <module>
[cloud-app] class ResourcePyd(PydanticModel):
[cloud-app] pydantic/main.py:299: in pydantic.main.ModelMetaclass.__new__
[cloud-app] ???
[cloud-app] pydantic/fields.py:411: in pydantic.fields.ModelField.infer
[cloud-app] ???
[cloud-app] pydantic/fields.py:342: in pydantic.fields.ModelField.__init__
[cloud-app] ???
[cloud-app] pydantic/fields.py:456: in pydantic.fields.ModelField.prepare
[cloud-app] ???
[cloud-app] pydantic/fields.py:670: in pydantic.fields.ModelField.populate_validators
[cloud-app] ???
[cloud-app] pydantic/validators.py:710: in find_validators
[cloud-app] ???
[cloud-app] E RuntimeError: error checking inheritance of <strawberry.custom_scalar.ScalarWrapper object at 0x7ff0045537f0> (type: ScalarWrapper)
Additionally when I try to use pydantic.Json or pydantic.JsonWrapper I get an UnsupportedTypeError thrown, which is obvious from reading the code:
Description
I'm trying to define a GQL Pydantic model w/ a JSON scalar attribute:
However I can't get Pydantic to comply:
Additionally when I try to use
pydantic.Json
orpydantic.JsonWrapper
I get anUnsupportedTypeError
thrown, which is obvious from reading the code:https://github.com/strawberry-graphql/strawberry/blob/main/strawberry/experimental/pydantic/fields.py#L42-L43
Maybe it will be obvious to someone what I'm doing wrong here?
Refs
dict
is not considered a type?Upvote & Fund
The text was updated successfully, but these errors were encountered: