Skip to content

Commit

Permalink
Handle list[str] as a field, etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
dmontagu authored and necaris committed Dec 10, 2024
1 parent ef4dd47 commit 38bd6de
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 6 additions & 1 deletion graphene_pydantic/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
import typing as T
import uuid
from types import GenericAlias
from typing import Type, get_origin

import graphene
Expand Down Expand Up @@ -238,7 +239,11 @@ def find_graphene_type(
return registry.get_type_for_model(type_)
elif registry and (
isinstance(type_, BaseModel)
or (inspect.isclass(type_) and issubclass(type_, BaseModel))
or (
inspect.isclass(type_)
and not isinstance(type_, GenericAlias)
and issubclass(type_, BaseModel)
)
):
# If it's a Pydantic model that hasn't yet been wrapped with a ObjectType,
# we can put a placeholder in and request that `resolve_placeholders()`
Expand Down
4 changes: 4 additions & 0 deletions tests/test_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ def test_iterables():
field = _convert_field_from_spec("attr", (T.List[int], [1, 2]))
assert isinstance(field.type.of_type, graphene.types.List)

if sys.version_info >= (3, 9):
field = _convert_field_from_spec("attr", (list[int], [1, 2]))
assert isinstance(field.type.of_type, graphene.types.List)

field = _convert_field_from_spec("attr", (list, [1, 2]))
assert field.type.of_type == graphene.types.List

Expand Down

0 comments on commit 38bd6de

Please sign in to comment.