Skip to content

Commit 2859b53

Browse files
authored
Merge pull request #47 from opsmill/wvd-20240930-fix-execute-graphql
Fix `execute_graphql` method not respecting clien's `default_branch` property
2 parents f2a19e0 + 35f510d commit 2859b53

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

changelog/46.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
`execute_graphql` method for InfrahubClient(Sync) now properly considers the `default_branch` setting

infrahub_sdk/client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,7 @@ async def execute_graphql(
575575
_type_: _description_
576576
"""
577577

578+
branch_name = branch_name or self.default_branch
578579
url = self._graphql_url(branch_name=branch_name, at=at)
579580

580581
payload: dict[str, Union[str, dict]] = {"query": query}
@@ -1112,6 +1113,7 @@ def execute_graphql(
11121113
dict: The result of the GraphQL query or mutation.
11131114
"""
11141115

1116+
branch_name = branch_name or self.default_branch
11151117
url = self._graphql_url(branch_name=branch_name, at=at)
11161118

11171119
payload: dict[str, Union[str, dict]] = {"query": query}

tests/unit/sdk/conftest.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,25 +1958,25 @@ async def mock_rest_api_artifact_generate(httpx_mock: HTTPXMock) -> HTTPXMock:
19581958
@pytest.fixture
19591959
async def mock_query_mutation_schema_dropdown_add(httpx_mock: HTTPXMock) -> None:
19601960
response = {"data": {"SchemaDropdownAdd": {"ok": True}}}
1961-
httpx_mock.add_response(method="POST", url="http://mock/graphql", json=response)
1961+
httpx_mock.add_response(method="POST", url="http://mock/graphql/main", json=response)
19621962

19631963

19641964
@pytest.fixture
19651965
async def mock_query_mutation_schema_dropdown_remove(httpx_mock: HTTPXMock) -> None:
19661966
response = {"data": {"SchemaDropdownRemove": {"ok": True}}}
1967-
httpx_mock.add_response(method="POST", url="http://mock/graphql", json=response)
1967+
httpx_mock.add_response(method="POST", url="http://mock/graphql/main", json=response)
19681968

19691969

19701970
@pytest.fixture
19711971
async def mock_query_mutation_schema_enum_add(httpx_mock: HTTPXMock) -> None:
19721972
response = {"data": {"SchemaEnumAdd": {"ok": True}}}
1973-
httpx_mock.add_response(method="POST", url="http://mock/graphql", json=response)
1973+
httpx_mock.add_response(method="POST", url="http://mock/graphql/main", json=response)
19741974

19751975

19761976
@pytest.fixture
19771977
async def mock_query_mutation_schema_enum_remove(httpx_mock: HTTPXMock) -> None:
19781978
response = {"data": {"SchemaEnumRemove": {"ok": True}}}
1979-
httpx_mock.add_response(method="POST", url="http://mock/graphql", json=response)
1979+
httpx_mock.add_response(method="POST", url="http://mock/graphql/main", json=response)
19801980

19811981

19821982
@pytest.fixture

tests/unit/sdk/test_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ async def test_allocate_next_ip_prefix(
607607
assert ip_prefix.description.value == "test"
608608

609609

610-
EXPECTED_ECHO = """URL: http://mock/graphql
610+
EXPECTED_ECHO = """URL: http://mock/graphql/main
611611
QUERY:
612612
613613
query GetTags($name: String!) {

0 commit comments

Comments
 (0)