Open thejaminator opened 2 years ago
I have a similar issue:
@strawberry.experimental.pydantic.type(
model= UserCreate, all_fields=True
)
class UserCreateType:
@strawberry.field
async def domain(self) -> str:
return self.email.split('@')[1]
This gives the mypy error: "UserCreateType" has no attribute "email"
I have a similar issue:
@strawberry.experimental.pydantic.type( model= UserCreate, all_fields=True ) class UserCreateType: @strawberry.field async def domain(self) -> str: return self.email.split('@')[1]
This gives the mypy
error: "UserCreateType" has no attribute "email"
@bugzpodder could i understand abit more of your usecase? could domain be a property on the pydantic type instead? or is that just an example, and domain would actually send a request.
@thejaminator
This is just an example. In my case, I have two microservices A and B.
The main object is fetched from microservice A. I've attached a new field to the graphql type (in this case UserCreatedType) that would make a call to microservice B and fetch this piece of additional data if requested.
I might have a way around this by putting email: strawberry.auto
in UserCreateType I think so it might be ok.
I do get a UserWarning: Using all_fields overrides any explicitly defined fields in the model, using both is likely a bug
warning though.
Same issue here.
class CurrentUser(pydantic.BaseModel):
email: str
@strawberry.experimental.pydantic.type(model=CurrentUserPyd, all_fields=True)
class CurrentUser:
pass
assert isinstance(registered_user, CurrentUser)
result: ExecutionResult = await schema.execute(
mutation,
variable_values={"form": {"email": registered_user.email}},
context_value={"request": request, "response": response, "username": None},
)
Pyright complains it doesn't know the CurrentUser
has an attribute email
:
/home/mcampbell/code/coreweave/cloud-console/tests/gql/resolvers/test_password.py
/home/mcampbell/code/coreweave/cloud-console/tests/gql/resolvers/test_password.py:227:60 - error: Cannot access attribute "email" for class "StrawberryTypeFromPydantic[CurrentUserPyd]"
Attribute "email" is unknown (reportAttributeAccessIssue)
/home/mcampbell/code/coreweave/cloud-console/tests/gql/resolvers/test_password.py:236:53 - error: Cannot access attribute "email" for class "StrawberryTypeFromPydantic[CurrentUserPyd]"
Attribute "email" is unknown (reportAttributeAccessIssue)
2 errors, 0 warnings, 0 informations
@mecampbellsoup I don't think we can fix this unfortunately :(
This might be fixed/worked-around by supporting this (which we want to do in #2181)
@strawberry.pydantic.type
class CurrentUser(pydantic.BaseModel):
email: str
it only works with fields that are defined, so yeah, let's do it in another issue :)
Originally posted by @patrick91 in https://github.com/strawberry-graphql/strawberry/issues/1832#issuecomment-1105318146
Upvote & Fund