Skip to content

Commit

Permalink
add _ prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
Minister944 committed Feb 28, 2024
1 parent fdc5fb8 commit 7a01e91
Show file tree
Hide file tree
Showing 15 changed files with 406 additions and 394 deletions.
26 changes: 13 additions & 13 deletions ariadne_codegen/client_generators/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ def __init__(

self._class_def = generate_class_def(name=name, base_names=[base_client])
self._gql_func_name = "gql"
self._operation_str_variable = "query"
self._variables_dict_variable = "variables"
self._response_variable = "response"
self._data_variable = "data"
self._operation_str_variable = "_query"
self._variables_dict_variable = "_variables"
self._response_variable = "_response"
self._data_variable = "_data"

def generate(self) -> ast.Module:
"""Generate module with class definition of graphql client."""
Expand Down Expand Up @@ -141,15 +141,15 @@ def add_method(
raise NotSupported(
"Subscriptions are only available when using async client."
)
method_def: Union[ast.FunctionDef, ast.AsyncFunctionDef] = (
self._generate_subscription_method_def(
name=name,
operation_name=operation_name,
return_type=return_type,
arguments=arguments,
arguments_dict=arguments_dict,
operation_str=operation_str,
)
method_def: Union[
ast.FunctionDef, ast.AsyncFunctionDef
] = self._generate_subscription_method_def(
name=name,
operation_name=operation_name,
return_type=return_type,
arguments=arguments,
arguments_dict=arguments_dict,
operation_str=operation_str,
)
elif async_:
method_def = self._generate_async_method(
Expand Down
44 changes: 22 additions & 22 deletions tests/client_generators/test_client_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,15 @@ def test_add_method_generates_correct_async_method_body(async_base_client_import
return_type_module_name = method_name
expected_method_body = [
ast.Assign(
targets=[ast.Name(id="query")],
targets=[ast.Name(id="_query")],
value=ast.Call(
func=ast.Name("gql"),
keywords=[],
args=[[ast.Constant(value=l + "\n") for l in query_str.splitlines()]],
),
),
ast.AnnAssign(
target=ast.Name(id="variables"),
target=ast.Name(id="_variables"),
annotation=ast.Subscript(
value=ast.Name(id=DICT),
slice=ast.Tuple(elts=[ast.Name(id="str"), ast.Name(id="object")]),
Expand All @@ -270,27 +270,27 @@ def test_add_method_generates_correct_async_method_body(async_base_client_import
simple=1,
),
ast.Assign(
targets=[ast.Name(id="response")],
targets=[ast.Name(id="_response")],
value=ast.Await(
value=ast.Call(
func=ast.Attribute(value=ast.Name(id="self"), attr="execute"),
args=[],
keywords=[
ast.keyword(arg="query", value=ast.Name(id="query")),
ast.keyword(arg="query", value=ast.Name(id="_query")),
ast.keyword(
arg="operation_name", value=ast.Constant(value="ListXyz")
),
ast.keyword(arg="variables", value=ast.Name(id="variables")),
ast.keyword(arg="variables", value=ast.Name(id="_variables")),
ast.keyword(value=ast.Name(id=KWARGS_NAMES)),
],
)
),
),
ast.Assign(
targets=[ast.Name(id="data")],
targets=[ast.Name(id="_data")],
value=ast.Call(
func=ast.Attribute(value=ast.Name(id="self"), attr="get_data"),
args=[ast.Name(id="response")],
args=[ast.Name(id="_response")],
keywords=[],
),
),
Expand All @@ -299,7 +299,7 @@ def test_add_method_generates_correct_async_method_body(async_base_client_import
func=ast.Attribute(
value=ast.Name(id="ListXyz"), attr=MODEL_VALIDATE_METHOD
),
args=[ast.Name(id="data")],
args=[ast.Name(id="_data")],
keywords=[],
)
),
Expand Down Expand Up @@ -393,15 +393,15 @@ def test_add_method_generates_correct_method_body(base_client_import):
return_type_module_name = method_name
expected_method_body = [
ast.Assign(
targets=[ast.Name(id="query")],
targets=[ast.Name(id="_query")],
value=ast.Call(
func=ast.Name("gql"),
keywords=[],
args=[[ast.Constant(value=l + "\n") for l in query_str.splitlines()]],
),
),
ast.AnnAssign(
target=ast.Name(id="variables"),
target=ast.Name(id="_variables"),
annotation=ast.Subscript(
value=ast.Name(id=DICT),
slice=ast.Tuple(elts=[ast.Name(id="str"), ast.Name(id="object")]),
Expand All @@ -412,25 +412,25 @@ def test_add_method_generates_correct_method_body(base_client_import):
simple=1,
),
ast.Assign(
targets=[ast.Name(id="response")],
targets=[ast.Name(id="_response")],
value=ast.Call(
func=ast.Attribute(value=ast.Name(id="self"), attr="execute"),
args=[],
keywords=[
ast.keyword(arg="query", value=ast.Name(id="query")),
ast.keyword(arg="query", value=ast.Name(id="_query")),
ast.keyword(
arg="operation_name", value=ast.Constant(value="ListXyz")
),
ast.keyword(arg="variables", value=ast.Name(id="variables")),
ast.keyword(arg="variables", value=ast.Name(id="_variables")),
ast.keyword(value=ast.Name(id=KWARGS_NAMES)),
],
),
),
ast.Assign(
targets=[ast.Name(id="data")],
targets=[ast.Name(id="_data")],
value=ast.Call(
func=ast.Attribute(value=ast.Name(id="self"), attr="get_data"),
args=[ast.Name(id="response")],
args=[ast.Name(id="_response")],
keywords=[],
),
),
Expand All @@ -439,7 +439,7 @@ def test_add_method_generates_correct_method_body(base_client_import):
func=ast.Attribute(
value=ast.Name(id="ListXyz"), attr=MODEL_VALIDATE_METHOD
),
args=[ast.Name(id="data")],
args=[ast.Name(id="_data")],
keywords=[],
)
),
Expand Down Expand Up @@ -486,7 +486,7 @@ def test_add_method_generates_async_generator_for_subscription_definition(
),
body=[
ast.Assign(
targets=[ast.Name(id="query")],
targets=[ast.Name(id="_query")],
value=ast.Call(
func=ast.Name(id="gql"),
args=[
Expand All @@ -496,7 +496,7 @@ def test_add_method_generates_async_generator_for_subscription_definition(
),
),
ast.AnnAssign(
target=ast.Name(id="variables"),
target=ast.Name(id="_variables"),
annotation=ast.Subscript(
value=ast.Name(id=DICT),
slice=ast.Tuple(elts=[ast.Name(id="str"), ast.Name(id="object")]),
Expand All @@ -505,16 +505,16 @@ def test_add_method_generates_async_generator_for_subscription_definition(
simple=1,
),
ast.AsyncFor(
target=ast.Name(id="data"),
target=ast.Name(id="_data"),
iter=ast.Call(
func=ast.Attribute(value=ast.Name(id="self"), attr="execute_ws"),
args=[],
keywords=[
ast.keyword(arg="query", value=ast.Name(id="query")),
ast.keyword(arg="query", value=ast.Name(id="_query")),
ast.keyword(
arg="operation_name", value=ast.Constant(value="GetCounter")
),
ast.keyword(arg="variables", value=ast.Name(id="variables")),
ast.keyword(arg="variables", value=ast.Name(id="_variables")),
ast.keyword(value=ast.Name(id=KWARGS_NAMES)),
],
),
Expand All @@ -526,7 +526,7 @@ def test_add_method_generates_async_generator_for_subscription_definition(
value=ast.Name(id="GetCounter"),
attr=MODEL_VALIDATE_METHOD,
),
args=[ast.Name(id="data")],
args=[ast.Name(id="_data")],
keywords=[],
)
)
Expand Down
12 changes: 6 additions & 6 deletions tests/main/clients/custom_base_client/expected_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def gql(q: str) -> str:

class Client(CustomAsyncBaseClient):
async def get_query_a(self, data_a: inputA, **kwargs: Any) -> GetQueryA:
query = gql(
_query = gql(
"""
query getQueryA($dataA: inputA!) {
queryA(dataA: $dataA) {
Expand All @@ -20,9 +20,9 @@ async def get_query_a(self, data_a: inputA, **kwargs: Any) -> GetQueryA:
}
"""
)
variables: Dict[str, object] = {"dataA": data_a}
response = await self.execute(
query=query, operation_name="getQueryA", variables=variables, **kwargs
_variables: Dict[str, object] = {"dataA": data_a}
_response = await self.execute(
query=_query, operation_name="getQueryA", variables=_variables, **kwargs
)
data = self.get_data(response)
return GetQueryA.model_validate(data)
_data = self.get_data(_response)
return GetQueryA.model_validate(_data)
12 changes: 6 additions & 6 deletions tests/main/clients/custom_config_file/expected_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ def gql(q: str) -> str:

class Client(AsyncBaseClient):
async def test(self, **kwargs: Any) -> Test:
query = gql(
_query = gql(
"""
query test {
testQuery
}
"""
)
variables: Dict[str, object] = {}
response = await self.execute(
query=query, operation_name="test", variables=variables, **kwargs
_variables: Dict[str, object] = {}
_response = await self.execute(
query=_query, operation_name="test", variables=_variables, **kwargs
)
data = self.get_data(response)
return Test.model_validate(data)
_data = self.get_data(_response)
return Test.model_validate(_data)
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def gql(q: str) -> str:

class Client(AsyncBaseClient):
async def get_query_a(self, data_a: inputA, **kwargs: Any) -> GetQueryA:
query = gql(
_query = gql(
"""
query getQueryA($dataA: inputA!) {
queryA(dataA: $dataA) {
Expand All @@ -20,9 +20,9 @@ async def get_query_a(self, data_a: inputA, **kwargs: Any) -> GetQueryA:
}
"""
)
variables: Dict[str, object] = {"dataA": data_a}
response = await self.execute(
query=query, operation_name="getQueryA", variables=variables, **kwargs
_variables: Dict[str, object] = {"dataA": data_a}
_response = await self.execute(
query=_query, operation_name="getQueryA", variables=_variables, **kwargs
)
data = self.get_data(response)
return GetQueryA.model_validate(data)
_data = self.get_data(_response)
return GetQueryA.model_validate(_data)
12 changes: 6 additions & 6 deletions tests/main/clients/custom_scalars/expected_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ async def get_a(
other: Any,
**kwargs: Any
) -> GetA:
query = gql(
_query = gql(
"""
query getA($date: DATETIME!, $code: CODE!, $id: CUSTOMID!, $input: TestInput!, $other: NOTMAPPED!) {
testQuery(date: $date, code: $code, id: $id, input: $input, other: $other) {
Expand All @@ -33,15 +33,15 @@ async def get_a(
}
"""
)
variables: Dict[str, object] = {
_variables: Dict[str, object] = {
"date": date,
"code": serialize_code(code),
"id": id,
"input": input,
"other": other,
}
response = await self.execute(
query=query, operation_name="getA", variables=variables, **kwargs
_response = await self.execute(
query=_query, operation_name="getA", variables=_variables, **kwargs
)
data = self.get_data(response)
return GetA.model_validate(data)
_data = self.get_data(_response)
return GetA.model_validate(_data)
Loading

0 comments on commit 7a01e91

Please sign in to comment.