Skip to content

Commit

Permalink
Merge pull request #7 from mirumee/fix-args-for-fields
Browse files Browse the repository at this point in the history
Add missing logic for fields_args, bump version to 0.5
  • Loading branch information
rafalp authored Jul 2, 2022
2 parents f95a48f + 61afcd8 commit 05b3042
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
6 changes: 6 additions & 0 deletions ariadne_graphql_modules/object_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
12 changes: 12 additions & 0 deletions tests/test_object_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(*_):
Expand All @@ -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)

Expand All @@ -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"

0 comments on commit 05b3042

Please sign in to comment.