Skip to content

Commit

Permalink
Add pydantic conversion compatibility with specialized list class
Browse files Browse the repository at this point in the history
- Modified `StrawberryAnnotation._is_list` to check if the `annotation` extends from the `list` type, enabling it to be considered a list.
- in `StrawberryAnnotation` Moved the `_is_list` check before the `_is_generic` check in `resolve` to avoid `unsupported` error in `_is_generic` before it checked `_is_list`.
  • Loading branch information
tjeerddie committed Aug 10, 2023
1 parent ea33e17 commit bf5b6df
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions strawberry/annotation.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ def resolve(self) -> Union[StrawberryType, type]:

if self._is_lazy_type(evaled_type):
return evaled_type
if self._is_list(evaled_type):
return self.create_list(evaled_type)

if self._is_generic(evaled_type):
if any(is_type_var(type_) for type_ in get_args(evaled_type)):
Expand All @@ -151,8 +153,6 @@ def resolve(self) -> Union[StrawberryType, type]:
# a StrawberryType
if self._is_enum(evaled_type):
return self.create_enum(evaled_type)
if self._is_list(evaled_type):
return self.create_list(evaled_type)
elif self._is_optional(evaled_type, args):
return self.create_optional(evaled_type)
elif self._is_union(evaled_type, args):
Expand Down Expand Up @@ -298,8 +298,14 @@ def _is_list(cls, annotation: Any) -> bool:
"""Returns True if annotation is a List"""

annotation_origin = get_origin(annotation)
annotation_mro = getattr(annotation, "__mro__", [])
is_list = any(x is list for x in annotation_mro)

return (annotation_origin in (list, tuple)) or annotation_origin is abc.Sequence
return (
(annotation_origin in (list, tuple))
or annotation_origin is abc.Sequence
or is_list
)

@classmethod
def _is_strawberry_type(cls, evaled_type: Any) -> bool:
Expand Down

0 comments on commit bf5b6df

Please sign in to comment.