Open 12tqian opened 2 years ago
@bellini666 do you have any ideas for an API for this use case?
Just thinking out loud, plain strawberry supports this:
def a_resolver(id: UUID) -> ObjectNode:
...
@strawberry.type
class ObjectQuery:
object: ObjectNode = strawberry.field(resolver=a_resolver)
we could maybe have a way to fetch the params from a stub function:
def a_resolver(id: UUID) -> ObjectNode:
...
@strawberry.type
class ObjectQuery:
object: ObjectNode = strawberry.django.field(params_from=a_resolver)
but sounds like it is a bit of work, but it might be useful for additional filtering.
or maybe we can pass a params_override
:
@strawberry.type
class ObjectQuery:
object: ObjectNode = strawberry.django.field(params_override={"pk": UUID})
Hey @patrick91 ,
Although I like your idea, I think we can probably do even better.
That pk
gets created in here. We can probably just change the strawberry.ID
to retrieve it from field_type_map using the pk field from django. That way it will use the correct type for the model's pk (e.g. strawberry.ID
for AutoField
, UUID
for UUIDField
, etc)
What do you think?
Hey @patrick91 ,
Although I like your idea, I think we can probably do even better.
That
pk
gets created in here. We can probably just change thestrawberry.ID
to retrieve it from field_type_map using the pk field from django. That way it will use the correct type for the model's pk (e.g.strawberry.ID
forAutoField
,UUID
forUUIDField
, etc)What do you think?
This approach makes a lot of sense to me and follows strawberry-django's theme of auto sensing field types from the django model.
I am making a query with the following structure:
However, the input for this requires a type of
pk: ID
. Is it possible to change this to be of typepk: UUID
? My current solution for this is just to write a generic custom resolver.Upvote & Fund