Skip to content

Commit acbc7a7

Browse files
committed
fixing arguments inconsistency
1 parent b5adbf2 commit acbc7a7

File tree

5 files changed

+292
-33
lines changed

5 files changed

+292
-33
lines changed

.vscode/settings.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,9 @@
3636
"python.testing.pytestEnabled": true,
3737
"python.linting.pylintEnabled": true,
3838
"python.linting.pylintArgs": ["--enable=W0614"],
39-
"python.linting.enabled": false
39+
"python.linting.enabled": false,
40+
"[python]": {
41+
"editor.defaultFormatter": "ms-python.black-formatter"
42+
},
43+
"python.formatting.provider": "none"
4044
}

gg/schema.py

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
from pydantic import BaseModel, Field
2+
from typing import Optional, Literal, List
3+
from api.proxies import execute
4+
from gql.client import AsyncClientSession
5+
from enum import Enum
6+
7+
8+
class Beast(BaseModel):
9+
typename: Optional[Literal["Beast"]] = Field(alias="__typename")
10+
common_name: Optional[str] = Field(alias="commonName")
11+
"a beast's name to you and I"
12+
tax_class: Optional[str] = Field(alias="taxClass")
13+
"taxonomy grouping"
14+
15+
16+
class CreateBeastCreatebeast(BaseModel):
17+
typename: Optional[Literal["Beast"]] = Field(alias="__typename")
18+
binomial: Optional[str]
19+
"a beast's name in Latin"
20+
common_name: Optional[str] = Field(alias="commonName")
21+
"a beast's name to you and I"
22+
23+
24+
class CreateBeast(BaseModel):
25+
create_beast: CreateBeastCreatebeast = Field(alias="createBeast")
26+
"create a massive beast on the server"
27+
28+
class Arguments(BaseModel):
29+
id: str
30+
legs: int
31+
binomial: str
32+
common_name: str = Field(alias="commonName")
33+
tax_class: str = Field(alias="taxClass")
34+
eats: Optional[List[Optional[str]]] = Field(default=None)
35+
36+
class Meta:
37+
document = "mutation createBeast($id: ID!, $legs: Int!, $binomial: String!, $commonName: String!, $taxClass: String!, $eats: [ID]) {\n createBeast(\n id: $id\n legs: $legs\n binomial: $binomial\n commonName: $commonName\n taxClass: $taxClass\n eats: $eats\n ) {\n binomial\n commonName\n }\n}"
38+
39+
40+
class Get_beasts(BaseModel):
41+
beasts: Optional[List[Optional[Beast]]]
42+
"get all the beasts on the server"
43+
44+
class Arguments(BaseModel):
45+
pass
46+
47+
class Meta:
48+
document = "fragment Beast on Beast {\n commonName\n taxClass\n}\n\nquery get_beasts {\n beasts {\n ...Beast\n }\n}"
49+
50+
51+
async def acreate_beast(
52+
client: AsyncClientSession,
53+
id: str,
54+
legs: int,
55+
binomial: str,
56+
common_name: str,
57+
tax_class: str,
58+
eats: Optional[List[Optional[str]]] = None,
59+
) -> CreateBeastCreatebeast:
60+
"""createBeast
61+
62+
63+
64+
Arguments:
65+
client (gql.client.AsyncClientSession): Specify that in turms.plugin.funcs.OperationsFuncPlugin
66+
id (str): id
67+
legs (int): legs
68+
binomial (str): binomial
69+
common_name (str): commonName
70+
tax_class (str): taxClass
71+
eats (Optional[List[Optional[str]]], optional): eats.
72+
73+
Returns:
74+
CreateBeastCreatebeast"""
75+
return (
76+
await execute(
77+
client,
78+
CreateBeast,
79+
{
80+
"id": id,
81+
"legs": legs,
82+
"binomial": binomial,
83+
"commonName": common_name,
84+
"taxClass": tax_class,
85+
"eats": eats,
86+
},
87+
)
88+
).create_beast
89+
90+
91+
async def aget_beasts(client: AsyncClientSession) -> Optional[List[Optional[Beast]]]:
92+
"""get_beasts
93+
94+
95+
96+
Arguments:
97+
client (gql.client.AsyncClientSession): Specify that in turms.plugin.funcs.OperationsFuncPlugin
98+
99+
Returns:
100+
Optional[List[Optional[Beast]]]"""
101+
return (await execute(client, Get_beasts, {})).beasts

graphql.config.yaml

+30-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
projects:
32
default:
43
schema: https://countries.trevorblades.com/
@@ -16,3 +15,33 @@ projects:
1615
- type: turms.processors.black.BlackProcessor
1716
scalar_definitions:
1817
uuid: str
18+
beast:
19+
schema: tests/schemas/beasts.graphql
20+
documents: tests/documents/beasts/**.graphql
21+
extensions:
22+
turms:
23+
out_dir: gg
24+
plugins:
25+
- type: turms.plugins.enums.EnumsPlugin
26+
- type: turms.plugins.inputs.InputsPlugin
27+
- type: turms.plugins.fragments.FragmentsPlugin
28+
- type: turms.plugins.operations.OperationsPlugin
29+
- type: turms.plugins.funcs.FuncsPlugin
30+
- type: turms.plugins.funcs.FuncsPlugin
31+
global_args:
32+
- type: gql.client.AsyncClientSession
33+
key: client
34+
definitions:
35+
- type: query
36+
use: api.proxies.execute
37+
is_async: True
38+
- type: mutation
39+
use: api.proxies.execute
40+
is_async: True
41+
stylers:
42+
- type: turms.stylers.capitalize.CapitalizeStyler
43+
- type: turms.stylers.snake_case.SnakeCaseStyler
44+
processors:
45+
- type: turms.processors.black.BlackProcessor
46+
scalar_definitions:
47+
uuid: str

tests/test_funcs.py

+89
Original file line numberDiff line numberDiff line change
@@ -235,3 +235,92 @@ def test_extra_args(beast_schema):
235235
generated_ast,
236236
"",
237237
)
238+
239+
240+
241+
def test_extra_args(beast_schema):
242+
config = GeneratorConfig(
243+
documents=build_relative_glob("/documents/beasts/**/*.graphql"),
244+
)
245+
246+
extra_args = [
247+
Arg(
248+
key="client",
249+
type="mocks.ExtraArg",
250+
description="An Extra Arg",
251+
)
252+
]
253+
254+
extra_kwargs = [
255+
Kwarg(
256+
key="extra",
257+
type="int",
258+
description="An Extra Arg",
259+
default=5,
260+
)
261+
]
262+
263+
generated_ast = generate_ast(
264+
config,
265+
beast_schema,
266+
stylers=[DefaultStyler()],
267+
plugins=[
268+
EnumsPlugin(),
269+
InputsPlugin(),
270+
FragmentsPlugin(),
271+
OperationsPlugin(),
272+
FuncsPlugin(
273+
config=FuncsPluginConfig(
274+
definitions=[
275+
FunctionDefinition(
276+
type="query",
277+
use="mocks.query",
278+
is_async=False,
279+
extra_args=extra_args,
280+
extra_kwargs=extra_kwargs,
281+
),
282+
FunctionDefinition(
283+
type="query",
284+
use="mocks.query",
285+
is_async=True,
286+
extra_args=extra_args,
287+
extra_kwargs=extra_kwargs,
288+
),
289+
FunctionDefinition(
290+
type="mutation",
291+
use="mocks.aquery",
292+
is_async=False,
293+
extra_args=extra_args,
294+
extra_kwargs=extra_kwargs,
295+
),
296+
FunctionDefinition(
297+
type="mutation",
298+
use="mocks.aquery",
299+
is_async=True,
300+
extra_args=extra_args,
301+
extra_kwargs=extra_kwargs,
302+
),
303+
FunctionDefinition(
304+
type="subscription",
305+
use="mocks.subscribe",
306+
is_async=False,
307+
extra_args=extra_args,
308+
extra_kwargs=extra_kwargs,
309+
),
310+
FunctionDefinition(
311+
type="subscription",
312+
use="mocks.asubscribe",
313+
is_async=True,
314+
extra_args=extra_args,
315+
extra_kwargs=extra_kwargs,
316+
),
317+
]
318+
),
319+
),
320+
],
321+
)
322+
323+
unit_test_with(
324+
generated_ast,
325+
"",
326+
)

0 commit comments

Comments
 (0)