Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Commit 0a190ac

Browse files
Jozef VolakJozefiel
Jozef Volak
authored andcommitted
[graphql-pydantic-converter] Add concatenate_queries function render multiple queries together
1 parent ea9d136 commit 0a190ac

File tree

4 files changed

+74
-2
lines changed

4 files changed

+74
-2
lines changed

utils/graphql-pydantic-converter/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
- Generating of pydantic dataclasses for response parsing
1010

1111
# 0.1.2
12-
- Ignore generating of private graphql schema objects
12+
- Ignore generating of private graphql schema objects
13+
- Add graphql_pydantic_converter.graphql_types.concatenate_queries function

utils/graphql-pydantic-converter/graphql_pydantic_converter/graphql_types.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
if TYPE_CHECKING:
1010
from typing import Any
11+
from typing import Union
1112

1213

1314
def generate_type(depth: int) -> str:
@@ -329,3 +330,8 @@ def render(self) -> str:
329330
if variable:
330331
variable = f' ( {variable} )'
331332
return f'{{ { name }{variable} {{ {payload} }} }}'
333+
334+
335+
def concatenate_queries(queries: list[Union[Query, Mutation]]) -> str:
336+
merged_query = ''.join(query.render()[1:-1] for query in queries)
337+
return f'{{ {merged_query} }}'

utils/graphql-pydantic-converter/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ packages = [{ include = "graphql_pydantic_converter" }]
1919
name = "graphql-pydantic-converter"
2020
description = "Convert pydantic schema to pydantic datamodel and build request from it"
2121
authors = ["Jozef Volak <[email protected]>"]
22-
version = '0.1.1'
22+
version = '0.1.2'
2323
readme = ["README.md", "CHANGELOG.md"]
2424
keywords = ["graphql", "pydantic"]
2525
license = "Apache 2.0"

utils/graphql-pydantic-converter/tests/test_graphql_generator.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from render_models import TagAnd
2424
from render_models import TagOr
2525

26+
import graphql_pydantic_converter.graphql_types
2627
from graphql_pydantic_converter.graphql_types import ENUM
2728
from graphql_pydantic_converter.graphql_types import Input
2829
from graphql_pydantic_converter.schema_converter import GraphqlJsonParser
@@ -196,3 +197,67 @@ def test_parse_response(self) -> None:
196197

197198
assert 'cli_device_import' == response.data.blueprints.edges[0].node.name
198199

200+
def test_multiple_query(self) -> None:
201+
202+
query_first = SearchPoolsByTagsQuery(
203+
tags=TagOr(
204+
matchesAny=[
205+
TagAnd(
206+
matchesAll=[
207+
'root_pool'
208+
]
209+
)
210+
]
211+
),
212+
payload=ResourcePoolConnection(
213+
edges=ResourcePoolEdge(
214+
node=ResourcePool(
215+
Name=True,
216+
id=True,
217+
AllocationStrategy=AllocationStrategy(
218+
Name=True
219+
)
220+
)
221+
)
222+
)
223+
)
224+
225+
query_second = SchedulesQuery(
226+
payload=ScheduleConnection(
227+
pageInfo=PageInfoSchedule(
228+
hasNextPage=True,
229+
hasPreviousPage=True,
230+
startCursor=True,
231+
endCursor=True
232+
),
233+
edges=ScheduleEdge(
234+
node=Schedule(
235+
name=True,
236+
cronString=True,
237+
enabled=True
238+
),
239+
)
240+
),
241+
after='aaa',
242+
first=10,
243+
filter=SchedulesFilterInput(
244+
workflowName='TEST_A',
245+
workflowVersion='1'
246+
)
247+
)
248+
249+
queries = [
250+
query_first,
251+
query_second
252+
]
253+
254+
reference = '{ SearchPoolsByTags ( tags: { matchesAny: [ { matchesAll: [ "root_pool" ] } ] } ) ' \
255+
'{ edges { node { AllocationStrategy { Description Lang Name Script id } ' \
256+
'Name PoolProperties PoolType id } } totalCount } schedules ( after: "aaa", first: 10, filter: ' \
257+
'{ workflowName: "TEST_A" , workflowVersion: "1" } ) { edges { node { name enabled parallelRuns ' \
258+
'workflowName workflowVersion cronString workflowContext fromDate toDate status } cursor } ' \
259+
'pageInfo { hasNextPage hasPreviousPage startCursor endCursor } totalCount } }'
260+
261+
merged_query = graphql_pydantic_converter.graphql_types.concatenate_queries(queries)
262+
assert reference == merged_query
263+

0 commit comments

Comments
 (0)