-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
267 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "qenerate" | ||
version = "0.6.1" | ||
version = "0.7.0" | ||
description = "Code Generator for GraphQL Query and Fragment Data Classes" | ||
authors = [ | ||
"Red Hat - Service Delivery - AppSRE <[email protected]>" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
fragment VaultSecret on VaultSecret_v1 { | ||
path | ||
field | ||
version | ||
format | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
query SaasFilesWithEnum { | ||
apps_v1 { | ||
saasFiles { | ||
pipelinesProvider { | ||
labels | ||
} | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
tests/generator/expected/pydantic_v1/empty_map_to_none/fragment.py.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
""" | ||
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, | ||
) | ||
|
||
|
||
class ConfiguredBaseModel(BaseModel): | ||
@root_validator(pre=True) | ||
def remove_empty(cls, values: dict): | ||
fields = list(values.keys()) | ||
for field in fields: | ||
value = values[field] | ||
if isinstance(value, dict): | ||
if not values[field]: | ||
values[field] = None | ||
return values | ||
|
||
class Config: | ||
smart_union=True | ||
extra=Extra.forbid | ||
|
||
|
||
class VaultSecret(ConfiguredBaseModel): | ||
path: str = Field(..., alias="path") | ||
field: str = Field(..., alias="field") | ||
version: Optional[int] = Field(..., alias="version") | ||
q_format: Optional[str] = Field(..., alias="format") |
83 changes: 83 additions & 0 deletions
83
tests/generator/expected/pydantic_v1/empty_map_to_none/query.py.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
""" | ||
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 SaasFilesWithEnum { | ||
apps_v1 { | ||
saasFiles { | ||
pipelinesProvider { | ||
labels | ||
} | ||
} | ||
} | ||
} | ||
|
||
""" | ||
|
||
|
||
class ConfiguredBaseModel(BaseModel): | ||
@root_validator(pre=True) | ||
def remove_empty(cls, values: dict): | ||
fields = list(values.keys()) | ||
for field in fields: | ||
value = values[field] | ||
if isinstance(value, dict): | ||
if not values[field]: | ||
values[field] = None | ||
return values | ||
|
||
class Config: | ||
smart_union=True | ||
extra=Extra.forbid | ||
|
||
|
||
class PipelinesProviderV1(ConfiguredBaseModel): | ||
labels: Optional[Json] = Field(..., alias="labels") | ||
|
||
|
||
class SaasFileV2(ConfiguredBaseModel): | ||
pipelines_provider: PipelinesProviderV1 = Field(..., alias="pipelinesProvider") | ||
|
||
|
||
class AppV1(ConfiguredBaseModel): | ||
saas_files: Optional[list[Optional[SaasFileV2]]] = Field(..., alias="saasFiles") | ||
|
||
|
||
class SaasFilesWithEnumQueryData(ConfiguredBaseModel): | ||
apps_v1: Optional[list[Optional[AppV1]]] = Field(..., alias="apps_v1") | ||
|
||
|
||
def query(query_func: Callable, **kwargs: Any) -> SaasFilesWithEnumQueryData: | ||
""" | ||
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: | ||
SaasFilesWithEnumQueryData: queried data parsed into generated classes | ||
""" | ||
raw_data: dict[Any, Any] = query_func(DEFINITION, **kwargs) | ||
return SaasFilesWithEnumQueryData(**raw_data) |
Oops, something went wrong.