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 just chatted with @patrick91 about returning custom types in combination with strawberry_django
My mutation looks like this:
mutation UpdateBlockRichText {
updateBlockRichText(data: {id: 5, content: "abc"}) { <<<< using "content" to update, because the db field also is content
id
text <<<<< query field text, but it is hydrated from 'content'
}
}
import strawberry
import strawberry_django
from strawberry import auto
from strawberry_django import mutations
from mypackage.models import Block
class TextBlockModel(Block):
...
blockmodel_ptr_id = models.ForeignKey(...)
content = models.TextField(...)
@strawberry.type # <<<< no strawberry_django.type and therefore no model is set
class BlockRichTextType:
text: str
@strawberry_django.input(TextBlockModel)
class BlockRichTextInput:
content: auto
@strawberry_django.partial(TextBlockModel)
class BlockRichTextInputPartial:
blockmodel_ptr_id: auto = strawberry.field(name="id")
content: auto
@strawberry.type
class Mutation:
create_block_rich_text: BlockRichTextType = mutations.create(BlockRichTextInput)
update_block_rich_text: BlockRichTextType = mutations.update(BlockRichTextInputPartial, key_attr="blockmodel_ptr_id")
delete_block_rich_text: BlockRichTextType = mutations.delete(BlockRichTextInputPartial, key_attr="blockmodel_ptr_id")
But this is leading to exceptions like
File "replaced\venv\Lib\site-packages\strawberry_django\mutations\fields.py", line 291, in resolver
assert model is not None
^^^^^^^^^^^^^^^^^
AssertionError
because I use a custom strawberry.type and not a strawberry_django.type
The core problem is, that update_block_rich_text: BlockRichTextType is statically typed and there is no way to get control over the return type via instances.
A nice solution would be to define a resolver in the create/update/delete functions taking the database object, e.g.:
I just chatted with @patrick91 about returning custom types in combination with strawberry_django
My mutation looks like this:
But this is leading to exceptions like
because I use a custom
strawberry.type
and not astrawberry_django.type
The core problem is, that
update_block_rich_text: BlockRichTextType
is statically typed and there is no way to get control over the return type via instances.A nice solution would be to define a resolver in the create/update/delete functions taking the database object, e.g.:
That would also allow to use inline lambdas:
Upvote & Fund
The text was updated successfully, but these errors were encountered: