@@ -19,4 +19,70 @@ assert generated == [
19
19
Field(name = " name" , fields = []),
20
20
Field(name = " friends" , fields = [Field(name = " name" , fields = [])]),
21
21
]
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
+ }"""
22
88
```
0 commit comments