Skip to content

Commit

Permalink
Support Default Field Resolver
Browse files Browse the repository at this point in the history
Support field resolver without redefine graphene field in PydanticObjectType
  • Loading branch information
arunsureshkumar authored Apr 29, 2023
1 parent c3c2eed commit d16d225
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions graphene_pydantic/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d16d225

Please sign in to comment.