|
4 | 4 | from pytest_httpx import HTTPXMock |
5 | 5 |
|
6 | 6 | from infrahub_sdk import InfrahubClient, InfrahubClientSync |
7 | | -from infrahub_sdk.exceptions import NodeNotFoundError |
| 7 | +from infrahub_sdk.exceptions import GraphQLError, NodeNotFoundError |
8 | 8 | from infrahub_sdk.node import InfrahubNode, InfrahubNodeSync |
9 | 9 | from tests.unit.sdk.conftest import BothClients |
10 | 10 |
|
@@ -800,3 +800,35 @@ async def test_clone_define_branch(clients: BothClients, client_type: str) -> No |
800 | 800 | assert clone.default_branch == clone_branch |
801 | 801 | assert original_branch != clone_branch |
802 | 802 | assert clone.store._default_branch == clone_branch |
| 803 | + |
| 804 | + |
| 805 | +@pytest.mark.parametrize("client_type", client_types) |
| 806 | +async def test_execute_graphql_error(httpx_mock: HTTPXMock, clients, client_type) -> None: |
| 807 | + httpx_mock.add_response(method="POST", json={"errors": ["foo"]}, is_reusable=True) |
| 808 | + |
| 809 | + query = """ |
| 810 | + query GetTags { |
| 811 | + BuiltinTag { |
| 812 | + edges { |
| 813 | + node { |
| 814 | + id |
| 815 | + display_label |
| 816 | + } |
| 817 | + } |
| 818 | + } |
| 819 | + } |
| 820 | + """ |
| 821 | + |
| 822 | + if client_type == "standard": |
| 823 | + with pytest.raises(GraphQLError): |
| 824 | + await clients.standard.execute_graphql(query=query, raise_for_error=True) |
| 825 | + |
| 826 | + response = await clients.standard.execute_graphql(query=query, raise_for_error=False) |
| 827 | + else: |
| 828 | + with pytest.raises(GraphQLError): |
| 829 | + clients.sync.execute_graphql(query=query, raise_for_error=True) |
| 830 | + |
| 831 | + response = clients.sync.execute_graphql(query=query, raise_for_error=False) |
| 832 | + |
| 833 | + assert response |
| 834 | + assert response[0] == "foo" |
0 commit comments