diff --git a/changelog/46.fixed.md b/changelog/46.fixed.md new file mode 100644 index 00000000..b21af46d --- /dev/null +++ b/changelog/46.fixed.md @@ -0,0 +1 @@ +`execute_graphql` method for InfrahubClient(Sync) now properly considers the `default_branch` setting diff --git a/infrahub_sdk/client.py b/infrahub_sdk/client.py index 3422535c..74f32d03 100644 --- a/infrahub_sdk/client.py +++ b/infrahub_sdk/client.py @@ -575,6 +575,7 @@ async def execute_graphql( _type_: _description_ """ + branch_name = branch_name or self.default_branch url = self._graphql_url(branch_name=branch_name, at=at) payload: dict[str, Union[str, dict]] = {"query": query} @@ -1112,6 +1113,7 @@ def execute_graphql( dict: The result of the GraphQL query or mutation. """ + branch_name = branch_name or self.default_branch url = self._graphql_url(branch_name=branch_name, at=at) payload: dict[str, Union[str, dict]] = {"query": query} diff --git a/tests/unit/sdk/conftest.py b/tests/unit/sdk/conftest.py index a870cfdb..680bc4ae 100644 --- a/tests/unit/sdk/conftest.py +++ b/tests/unit/sdk/conftest.py @@ -1958,25 +1958,25 @@ async def mock_rest_api_artifact_generate(httpx_mock: HTTPXMock) -> HTTPXMock: @pytest.fixture async def mock_query_mutation_schema_dropdown_add(httpx_mock: HTTPXMock) -> None: response = {"data": {"SchemaDropdownAdd": {"ok": True}}} - httpx_mock.add_response(method="POST", url="http://mock/graphql", json=response) + httpx_mock.add_response(method="POST", url="http://mock/graphql/main", json=response) @pytest.fixture async def mock_query_mutation_schema_dropdown_remove(httpx_mock: HTTPXMock) -> None: response = {"data": {"SchemaDropdownRemove": {"ok": True}}} - httpx_mock.add_response(method="POST", url="http://mock/graphql", json=response) + httpx_mock.add_response(method="POST", url="http://mock/graphql/main", json=response) @pytest.fixture async def mock_query_mutation_schema_enum_add(httpx_mock: HTTPXMock) -> None: response = {"data": {"SchemaEnumAdd": {"ok": True}}} - httpx_mock.add_response(method="POST", url="http://mock/graphql", json=response) + httpx_mock.add_response(method="POST", url="http://mock/graphql/main", json=response) @pytest.fixture async def mock_query_mutation_schema_enum_remove(httpx_mock: HTTPXMock) -> None: response = {"data": {"SchemaEnumRemove": {"ok": True}}} - httpx_mock.add_response(method="POST", url="http://mock/graphql", json=response) + httpx_mock.add_response(method="POST", url="http://mock/graphql/main", json=response) @pytest.fixture diff --git a/tests/unit/sdk/test_client.py b/tests/unit/sdk/test_client.py index 50dc0b34..eb0f0930 100644 --- a/tests/unit/sdk/test_client.py +++ b/tests/unit/sdk/test_client.py @@ -607,7 +607,7 @@ async def test_allocate_next_ip_prefix( assert ip_prefix.description.value == "test" -EXPECTED_ECHO = """URL: http://mock/graphql +EXPECTED_ECHO = """URL: http://mock/graphql/main QUERY: query GetTags($name: String!) {