-
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
14 changed files
with
202 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "qenerate" | ||
version = "0.4.7" | ||
version = "0.5.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
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,14 @@ | ||
mutation AddComment($body: String = "", $subjectId: ID = "") { | ||
addComment(input: {subjectId: $subjectId, body: $body}) { | ||
subject { | ||
... on Topic { | ||
id | ||
name | ||
} | ||
... on User { | ||
id | ||
} | ||
} | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
tests/generator/expected/pydantic_v1/github/comment_mutation.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,98 @@ | ||
""" | ||
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 = """ | ||
mutation AddComment($body: String = "", $subjectId: ID = "") { | ||
addComment(input: {subjectId: $subjectId, body: $body}) { | ||
subject { | ||
... on Topic { | ||
id | ||
name | ||
} | ||
... on User { | ||
id | ||
} | ||
} | ||
} | ||
} | ||
|
||
""" | ||
|
||
|
||
class Node(BaseModel): | ||
|
||
class Config: | ||
smart_union = True | ||
extra = Extra.forbid | ||
|
||
|
||
class Topic(Node): | ||
q_id: str = Field(..., alias="id") | ||
name: str = Field(..., alias="name") | ||
|
||
class Config: | ||
smart_union = True | ||
extra = Extra.forbid | ||
|
||
|
||
class User(Node): | ||
q_id: str = Field(..., alias="id") | ||
email: str = Field(..., alias="email") | ||
|
||
class Config: | ||
smart_union = True | ||
extra = Extra.forbid | ||
|
||
|
||
class AddCommentPayload(BaseModel): | ||
subject: Optional[Union[Topic, User, Node]] = Field(..., alias="subject") | ||
|
||
class Config: | ||
smart_union = True | ||
extra = Extra.forbid | ||
|
||
|
||
class AddCommentMutationResponse(BaseModel): | ||
add_comment: Optional[AddCommentPayload] = Field(..., alias="addComment") | ||
|
||
class Config: | ||
smart_union = True | ||
extra = Extra.forbid | ||
|
||
|
||
def mutate(mutation_func: Callable, **kwargs: Any) -> AddCommentMutationResponse: | ||
""" | ||
This is a convenience function which executes a mutation and parses the response | ||
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: | ||
mutation_func (Callable): Function which executes the mutation. | ||
kwargs: Arguments that will be passed to the mutation function. | ||
This must include the mutation parameters. | ||
|
||
Returns: | ||
AddCommentMutationResponse: mutation response parsed into generated classes | ||
""" | ||
raw_data: dict[Any, Any] = mutation_func(DEFINITION, **kwargs) | ||
return AddCommentMutationResponse(**raw_data) |
Oops, something went wrong.