Skip to content

Commit e6ef484

Browse files
committed
Update docs
1 parent 3ec150f commit e6ef484

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

docs/from_data_model.md

+66
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,70 @@ assert generated == [
1919
Field(name="name", fields=[]),
2020
Field(name="friends", fields=[Field(name="name", fields=[])]),
2121
]
22+
23+
Field(name="human", fields=generated).render()
24+
"""human {
25+
name
26+
height(
27+
unit: FOOT
28+
)
29+
}"""
30+
```
31+
32+
We can use arguments for your queries
33+
34+
```python
35+
from pydantic import Field as PydanticField
36+
from graphql_query import Argument, Field, GraphQLQueryBaseModel
37+
38+
class Human(GraphQLQueryBaseModel):
39+
name: str
40+
height: float = PydanticField(graphql_arguments=[Argument(name="unit", value="FOOT")])
41+
42+
generated = Human.graphql_fields()
43+
44+
assert generated == [
45+
Field(name="name", fields=[]), Field(name="height", arguments=[Argument(name="unit", value="FOOT")])
46+
]
47+
48+
Field(name="human", fields=generated).render()
49+
"""human {
50+
name
51+
height(
52+
unit: FOOT
53+
)
54+
}"""
55+
```
56+
57+
For multiply union we have inline fragments
58+
59+
```python
60+
from typing import Union
61+
from graphql_query import Field, GraphQLQueryBaseModel, InlineFragment
62+
63+
class Droid(GraphQLQueryBaseModel):
64+
primaryFunction: str
65+
66+
class Human(GraphQLQueryBaseModel):
67+
height: float
68+
69+
class Hero(GraphQLQueryBaseModel):
70+
name: str
71+
type: Union[Human, Droid]
72+
73+
74+
generated = Hero.graphql_fields()
75+
76+
Field(name="hero", fields=generated).render()
77+
"""hero {
78+
name
79+
type {
80+
... on Human {
81+
height
82+
}
83+
... on Droid {
84+
primaryFunction
85+
}
86+
}
87+
}"""
2288
```

graphql_query/__version__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = "1.2.1"
1+
__version__ = "1.2.2"

0 commit comments

Comments
 (0)