diff --git a/CHANGELOG.md b/CHANGELOG.md index c552007..0ab032a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # CHANGELOG +## 0.5.0 (2022-07-03) + +- Implement missing logic for `ObjectType.__fields_args__` + + ## 0.4.0 (2022-05-04) - Split logic from `BaseType` into `DefinitionType` and `BindableType`. diff --git a/ariadne_graphql_modules/object_type.py b/ariadne_graphql_modules/object_type.py index cfde52d..9ec6c1c 100644 --- a/ariadne_graphql_modules/object_type.py +++ b/ariadne_graphql_modules/object_type.py @@ -118,3 +118,9 @@ def __bind_to_schema__(cls, schema): for field_name, field_resolver in cls.resolvers.items(): graphql_type.fields[field_name].resolve = field_resolver + + if cls.__fields_args__: + for field_name, field_args_mappings in cls.__fields_args__.items(): + field_args = graphql_type.fields[field_name].args + for arg_name, arg_out_name in field_args_mappings.items(): + field_args[arg_name].out_name = arg_out_name diff --git a/setup.py b/setup.py index 5521fff..f23b655 100755 --- a/setup.py +++ b/setup.py @@ -27,7 +27,7 @@ long_description=README, long_description_content_type="text/markdown", license="BSD", - version="0.4.0", + version="0.5.0", url="https://github.com/mirumee/ariadne-graphql-modules", packages=["ariadne_graphql_modules"], include_package_data=True, diff --git a/tests/test_object_type.py b/tests/test_object_type.py index 3d8f5fe..b9ca048 100644 --- a/tests/test_object_type.py +++ b/tests/test_object_type.py @@ -345,12 +345,15 @@ class QueryType(ObjectType): other: String! firstField: String! secondField: String! + fieldWithArg(someArg: String): String! } """ __aliases__ = { "firstField": "first_field", "secondField": "second_field", + "fieldWithArg": "field_with_arg", } + __fields_args__ = {"fieldWithArg": {"someArg": "some_arg"}} @staticmethod def resolve_other(*_): @@ -360,6 +363,10 @@ def resolve_other(*_): def resolve_second_field(obj, *_): return "Obj: %s" % obj["secondField"] + @staticmethod + def resolve_field_with_arg(*_, some_arg): + return some_arg + schema = make_executable_schema(QueryType) @@ -384,3 +391,8 @@ def test_object_resolves_field_with_aliased_default_resolver(): def test_object_resolves_field_with_aliased_custom_resolver(): result = graphql_sync(schema, "{ secondField }", root_value={"secondField": "Hey!"}) assert result.data["secondField"] == "Obj: Hey!" + + +def test_object_resolves_field_with_arg_out_name_customized(): + result = graphql_sync(schema, '{ fieldWithArg(someArg: "test") }') + assert result.data["fieldWithArg"] == "test"