def create_list(self, evaled_type: Any) -> StrawberryList: of_type = StrawberryAnnotation( annotation=evaled_type.__args__[0], namespace=self.namespace, ).resolve() return StrawberryList(of_type)
def test_list_of_lists(): annotation = StrawberryAnnotation(List[List[float]]) resolved = annotation.resolve() assert isinstance(resolved, StrawberryList) assert resolved.of_type == List[float] assert resolved == StrawberryList(of_type=List[float]) assert resolved == List[List[float]]
def test_list_of_optional(): annotation = StrawberryAnnotation(List[Optional[int]]) resolved = annotation.resolve() assert isinstance(resolved, StrawberryList) assert resolved.of_type == Optional[int] assert resolved == StrawberryList(of_type=Optional[int]) assert resolved == List[Optional[int]]
def test_basic_list(): annotation = StrawberryAnnotation(List[str]) resolved = annotation.resolve() assert isinstance(resolved, StrawberryList) assert resolved.of_type is str assert resolved == StrawberryList(of_type=str) assert resolved == List[str]
def test_list_of_string(): annotation = StrawberryAnnotation(List["int"]) resolved = annotation.resolve() assert isinstance(resolved, StrawberryList) assert resolved.of_type is int assert resolved == StrawberryList(of_type=int) assert resolved == List[int]
def test_string_of_list(): namespace = {**locals(), **globals()} annotation = StrawberryAnnotation("List[float]", namespace=namespace) resolved = annotation.resolve() assert isinstance(resolved, StrawberryList) assert resolved.of_type is float assert resolved == StrawberryList(of_type=float) assert resolved == List[float]
def test_list_of_string_of_type(): @strawberry.type class NameGoesHere: foo: bool annotation = StrawberryAnnotation(List["NameGoesHere"], namespace=locals()) resolved = annotation.resolve() assert isinstance(resolved, StrawberryList) assert resolved.of_type is NameGoesHere assert resolved == StrawberryList(of_type=NameGoesHere) assert resolved == List[NameGoesHere]
def test_string_of_list_of_type(): @strawberry.type class BlahBlah: foo: bool namespace = {**locals(), **globals()} annotation = StrawberryAnnotation("List[BlahBlah]", namespace=namespace) resolved = annotation.resolve() assert isinstance(resolved, StrawberryList) assert resolved.of_type is BlahBlah assert resolved == StrawberryList(of_type=BlahBlah) assert resolved == List[BlahBlah]
def test_list_of_union(): @strawberry.type class Animal: feet: bool @strawberry.type class Fungus: spore: bool annotation = StrawberryAnnotation(List[Union[Animal, Fungus]]) resolved = annotation.resolve() assert isinstance(resolved, StrawberryList) assert resolved.of_type == Union[Animal, Fungus] assert resolved == StrawberryList(of_type=Union[Animal, Fungus]) assert resolved == List[Union[Animal, Fungus]]
@strawberry.type class TypeA: name: str @strawberry.type class TypeB: age: int @pytest.mark.parametrize( "types,expected_name", [ ([StrawberryList(str)], "StrListExample"), ([StrawberryList(StrawberryList(str))], "StrListListExample"), ([StrawberryOptional(StrawberryList(str))], "StrListOptionalExample"), ([StrawberryList(StrawberryOptional(str))], "StrOptionalListExample"), ([StrawberryList(Enum)], "EnumListExample"), ([StrawberryUnion("Union", (TypeA, TypeB))], "UnionExample"), # type: ignore ([TypeA], "TypeAExample"), ([CustomInt], "CustomIntExample"), ([TypeA, TypeB], "TypeATypeBExample"), ([TypeA, LazyType["TypeB", "test_names"] ], "TypeATypeBExample"), # type: ignore ], ) def test_name_generation(types, expected_name): config = StrawberryConfig()