Skip to content

Commit

Permalink
resolve lazy types when converting arguments (#1350)
Browse files Browse the repository at this point in the history
* resolve lazy types when converting arguments

* add test for lazy type conversion

* add release.md
  • Loading branch information
lukesmurray authored Oct 13, 2021
1 parent e97784f commit 4546436
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
3 changes: 3 additions & 0 deletions RELEASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Release type: patch

Add logic to convert arguments of type LazyType.
6 changes: 6 additions & 0 deletions strawberry/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from strawberry.annotation import StrawberryAnnotation
from strawberry.custom_scalar import ScalarDefinition, ScalarWrapper
from strawberry.enum import EnumDefinition
from strawberry.lazy_type import LazyType
from strawberry.type import StrawberryList, StrawberryOptional, StrawberryType
from strawberry.utils.mixins import GraphQLNameMixin

Expand Down Expand Up @@ -124,6 +125,11 @@ def convert_argument(
if isinstance(type_, EnumDefinition):
return type_.wrapped_cls(value)

if isinstance(type_, LazyType):
return convert_argument(
value, type_.resolve_type(), scalar_registry, auto_camel_case
)

if hasattr(type_, "_type_definition"): # TODO: Replace with StrawberryInputObject
type_definition: TypeDefinition = type_._type_definition # type: ignore

Expand Down
26 changes: 26 additions & 0 deletions tests/utils/test_arguments_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import strawberry
from strawberry.annotation import StrawberryAnnotation
from strawberry.arguments import UNSET, StrawberryArgument, convert_arguments
from strawberry.lazy_type import LazyType
from strawberry.schema.types.scalar import DEFAULT_SCALAR_REGISTRY


Expand Down Expand Up @@ -70,6 +71,31 @@ def test_list():
}


@strawberry.input
class LaziestType:
something: bool


def test_lazy():
LazierType = LazyType["LaziestType", __name__]

args = {
"lazyArg": {"something": True},
}

arguments = [
StrawberryArgument(
graphql_name="lazyArg",
python_name="lazy_arg",
type_annotation=StrawberryAnnotation(LazierType),
),
]

assert convert_arguments(
args, arguments, scalar_registry=DEFAULT_SCALAR_REGISTRY
) == {"lazy_arg": LaziestType(something=True)}


def test_input_types():
@strawberry.input
class MyInput:
Expand Down

0 comments on commit 4546436

Please sign in to comment.