strawberry-graphql / strawberry

A GraphQL library for Python that leverages type annotations πŸ“
https://strawberry.rocks
MIT License
3.95k stars 521 forks source link

Property variable_values from class Info returning wrong information #3460

Open ShtykovaAA opened 5 months ago

ShtykovaAA commented 5 months ago

Hi!

I have an example, where I want to update some fields in my entity, here is my example https://play.strawberry.rocks/?gist=67964a59e64b5c3c6bdce477826db9f5

So details: I want to update some fields from frontend, I want to know what exactly fields were sent to backend, but function return all input object with default None value.

It's important because some fields could be null in database.

Upvote & Fund

Fund with Polar

patrick91 commented 5 months ago

@ShtykovaAA you can do that using UNSET: https://play.strawberry.rocks/?gist=a70bc1aa74d5d04a6ceea1be6a7b7575

https://strawberry.rocks/docs/types/input-types#defining-input-types

ShtykovaAA commented 5 months ago

@patrick91 it works! thank you!

ShtykovaAA commented 5 months ago

@patrick91 sorry I checked that it doesn't work for @strawberry.experimental.pydantic.input(PydanticModel) and I want to fix it, do I need another conversation?

patrick91 commented 5 months ago

@ShtykovaAA cab you make an example in the playground? I think pydantic should work there ☺️

ShtykovaAA commented 5 months ago

@patrick91 yes! here an example https://play.strawberry.rocks/?gist=fdff10f784dd786a67d2e74bbab95d77

ShtykovaAA commented 5 months ago

@patrick91 I found the place of mistake: https://github.com/graphql-python/graphql-core/blob/main/src/graphql/utilities/coerce_input_value.py#L102 So if I'm using strawberry.input the default value is Undefined, but than I'm using @strawberry.experimental.pydantic.input(PydanticModel) the default value is None...

patrick91 commented 5 months ago

@ShtykovaAA thanks for checking! I might have some time to fix this during the weekend, or feel free to send a PR if you find a way to fix it!

ShtykovaAA commented 5 months ago

@patrick91 I'm newbie but I really want to take a chance

I think we need to check this condition https://github.com/strawberry-graphql/strawberry/blob/main/strawberry/experimental/pydantic/object_type.py#L76 because it means that we are overwriting our strawberry.input by PydanticField and that's why the default value is None, but not UNSET.

what do you think about it? I think it's a big change in project, but I think that it's supposed to be like that

patrick91 commented 5 months ago

@ShtykovaAA I'm not too sure! Feel free to try and send a draft PR, we should have enough test to make sure this becomes a valid change 😊

ShtykovaAA commented 5 months ago

@patrick91 hi! I added draft pr, tell me if there will be time to look/discuss my changes?

patrick91 commented 5 months ago

@ShtykovaAA can you link the PR here? 😊

ShtykovaAA commented 4 months ago

@patrick91 yes, sure https://github.com/strawberry-graphql/strawberry/pull/3469