From d16d225a3f763d8eefccd759af851bb5a779dc7a Mon Sep 17 00:00:00 2001 From: Arun Suresh Kumar Date: Sat, 29 Apr 2023 17:29:00 +0530 Subject: [PATCH] Support Default Field Resolver Support field resolver without redefine graphene field in PydanticObjectType --- graphene_pydantic/converters.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/graphene_pydantic/converters.py b/graphene_pydantic/converters.py index b12eab6..8e93afe 100644 --- a/graphene_pydantic/converters.py +++ b/graphene_pydantic/converters.py @@ -135,9 +135,16 @@ def convert_pydantic_field( field_type = field_kwargs.pop("type", field_kwargs.pop("type_", None)) if field_type is None: raise ValueError("No field type could be determined.") + + resolver_function = getattr(parent_type, + "resolve_" + field.name, + None) + if resolver_function and callable(resolver_function): + field_resolver = resolver_function + else: + field_resolver = get_attr_resolver(field.name) - return Field(field_type, resolver=get_attr_resolver(field.name), **field_kwargs) - + return Field(field_type, resolver=field_resolver, **field_kwargs) def convert_pydantic_type( type_: T.Type,