strawberry
strawberry copied to clipboard
TypeError: fields cannot be resolved. Unexpected type 'typing.Any'
Hey Everyone,
I am using FastAPI with strawberry GraphQL & I have a pydantic model that uses typing.Any which causes problems.
import strawberry
from pydantic import BaseModel
from typing import Optional, Any
class Model(BaseModel):
name: str
dataset: Optional[Any] = None
@strawberry.experimental.pydantic.input(model=Model, all_fields=True)
class ModeltStrawberry:
pass
@strawberry.type
class Query:
@strawberry.field
def model_test(
self,
model: Optional[ModeltStrawberry] = None,
) -> str:
pass
schema = strawberry.Schema(query=Query)
causes:
...
File "python3.7/site-packages/strawberry/schema/schema_converter.py", line 586, in from_type
raise TypeError(f"Unexpected type '{type_}'")
TypeError: Unexpected type 'typing.Any'
What am I doing wrong? How to use typing.Any with strawberry and FastAPI? I am using strawberry-graphql version 0.123.2.
Thanks!!!
@hjilke hi there, in graphql, there isn't a notion of an "Any" type. all objects must have a type
Thanks @thejaminator
If it is defined as Any, please emit String as GraphQL schema and serialize it with str()?
For my case, I am not making a class for Strawberry, I am converting a Pydantic class, and I have to use Any when I use Python because of some library. Could you please reconsider this?
If it is defined as
Any, please emitStringas GraphQL schema and serialize it withstr()?For my case, I am not making a class for Strawberry, I am converting a Pydantic class, and I have to use
Anywhen I use Python because of some library. Could you please reconsider this?
Hi, I'm cleaning up old issues. Please open a new issue with a code sample if you're still affected by this :)