-
Notifications
You must be signed in to change notification settings - Fork 7
/
example1.py
75 lines (58 loc) · 2.04 KB
/
example1.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""
Generated by qenerate plugin=pydantic_v1. DO NOT MODIFY MANUALLY!
"""
from collections.abc import Callable # noqa: F401 # pylint: disable=W0611
from datetime import datetime # noqa: F401 # pylint: disable=W0611
from enum import Enum # noqa: F401 # pylint: disable=W0611
from typing import ( # noqa: F401 # pylint: disable=W0611
Any,
Optional,
Union,
)
from pydantic import ( # noqa: F401 # pylint: disable=W0611
BaseModel,
Extra,
Field,
Json,
)
DEFINITION = """
query JenkinsConfigs {
jenkins_configs: jenkins_configs_v1 {
name
...on JenkinsConfig_v1 {
type
config_path {
content
}
}
}
}
"""
class ConfiguredBaseModel(BaseModel):
class Config:
smart_union=True
extra=Extra.forbid
class JenkinsConfigV1(ConfiguredBaseModel):
name: str = Field(..., alias="name")
class ResourceV1(ConfiguredBaseModel):
content: str = Field(..., alias="content")
class JenkinsConfigV1_JenkinsConfigV1(JenkinsConfigV1):
q_type: str = Field(..., alias="type")
config_path: Optional[ResourceV1] = Field(..., alias="config_path")
class JenkinsConfigsQueryData(ConfiguredBaseModel):
jenkins_configs: Optional[list[Union[JenkinsConfigV1_JenkinsConfigV1, JenkinsConfigV1]]] = Field(..., alias="jenkins_configs")
def query(query_func: Callable, **kwargs: Any) -> JenkinsConfigsQueryData:
"""
This is a convenience function which queries and parses the data into
concrete types. It should be compatible with most GQL clients.
You do not have to use it to consume the generated data classes.
Alternatively, you can also mime and alternate the behavior
of this function in the caller.
Parameters:
query_func (Callable): Function which queries your GQL Server
kwargs: optional arguments that will be passed to the query function
Returns:
JenkinsConfigsQueryData: queried data parsed into generated classes
"""
raw_data: dict[Any, Any] = query_func(DEFINITION, **kwargs)
return JenkinsConfigsQueryData(**raw_data)