-
-
Notifications
You must be signed in to change notification settings - Fork 593
Open
Description
Metadata annotations associated with strawberry.input classes is currently difficult to access. The following program illustrates one way that currently works to access the annotation associated with field my_value
on the strawberry input class MyInput
.
from typing import Annotated
from dataclasses import fields
import strawberry
from strawberry.types.base import get_object_definition
@strawberry.input
class MyInput:
my_value: Annotated[str, strawberry.argument(metadata={"more": "meta"})]
@strawberry.type
class Query:
@strawberry.field
def test(
self,
my_input: Annotated[MyInput, strawberry.argument(metadata={"some": "meta"})],
) -> str:
return "OK"
definition = get_object_definition(Query, strict=True)
print(definition.fields[0].arguments[0].metadata)
print(fields(MyInput)[0].type.__metadata__[0].metadata)
# Does not work
definition = get_object_definition(MyInput, strict=True)
print(len(definition.fields[0].metadata.items())) # zero
print(f"{definition.fields[0].arguments=}") # empty list
Feature Request Type
- Provide a consistent mechanism for accessing metadata annotations that works in this sort of use case
The Discord discussion here provides more context/background https://discord.com/channels/689806334337482765/1424854718076817500/1424854718076817500
Metadata
Metadata
Assignees
Labels
No labels