Skip to content

Commit

Permalink
Merge pull request #85 from strollby/feat/default_field_resolver
Browse files Browse the repository at this point in the history
Support Default Field Resolver
  • Loading branch information
necaris authored Jul 24, 2023
2 parents c3c2eed + d16d225 commit 569aeaf
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 569aeaf

Please sign in to comment.