Skip to content

Commit 59c9333

Browse files
authored
docs: add example of creating query builder from pydantic model
1 parent 703dc92 commit 59c9333

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

README.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![Code Quality](https://github.com/BeatsuDev/GraphQLRequests/actions/workflows/code_quality.yml/badge.svg)](https://github.com/BeatsuDev/GraphQLRequests/actions/workflows/code_quality.yml)
55
[![codecov](https://codecov.io/gh/BeatsuDev/GraphQLRequests/branch/main/graph/badge.svg?token=FBQKU5OEWT)](https://codecov.io/gh/BeatsuDev/GraphQLRequests)
66

7-
Define GraphQL types in Python as classes, then use them to automatically build queries. Or even simpler;
7+
Define GraphQL types in Python as classes or pydantic classes, then use them to automatically build queries. Or even simpler;
88
gqlrequests will automatically build the classes for you given the api endpoint by using introspection! (Now that's awesome).
99
You no longer need to define your requests as multiline strings (hence no strings attached).
1010

@@ -67,6 +67,16 @@ print(characters_query.build())
6767
# length
6868
# }
6969
# }
70+
71+
from pydantic import BaseModel
72+
73+
class ExampleModel(BaseModel):
74+
age: int
75+
name: str
76+
77+
ExampleQueryBuilder = gqlrequests.from_pydantic(ExampleModel)
78+
79+
print(ExampleQueryBuilder().build())
7080
```
7181

7282
## Edge cases

0 commit comments

Comments
 (0)