Skip to content

Commit d5b3be1

Browse files
authored
Update README.md
Explain how to use custom resolve functions
1 parent a744fce commit d5b3be1

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,24 @@ result = schema.execute(mutation)
110110
print(result.data['createPerson']['firstName'])
111111
```
112112

113+
### Custom resolve functions
114+
115+
Since `PydanticObjectType` inherits from `graphene.ObjectType` you can add custom resolve functions as explained [here](https://docs.graphene-python.org/en/stable/api/#object-types). For instance:
116+
117+
```python
118+
class Person(PydanticObjectType):
119+
class Meta:
120+
model = PersonModel
121+
# exclude specified fields
122+
exclude_fields = ("id",)
123+
124+
full_name = graphene.String()
125+
126+
def resolve_full_name(self, info, **kwargs):
127+
return self.first_name + ' ' + self.last_name
128+
```
129+
130+
113131
### Forward declarations and circular references
114132

115133
`graphene_pydantic` supports forward declarations and circular references, but you will need to call the `resolve_placeholders()` method to ensure the types are fully updated before you execute a GraphQL query. For instance:

0 commit comments

Comments
 (0)