|
4 | 4 | import copy |
5 | 5 | import logging |
6 | 6 | import time |
| 7 | +import warnings |
7 | 8 | from collections.abc import Coroutine, MutableMapping |
8 | 9 | from functools import wraps |
9 | 10 | from time import sleep |
@@ -893,13 +894,20 @@ async def execute_graphql( |
893 | 894 | branch_name (str, optional): Name of the branch on which the query will be executed. Defaults to None. |
894 | 895 | at (str, optional): Time when the query should be executed. Defaults to None. |
895 | 896 | timeout (int, optional): Timeout in second for the query. Defaults to None. |
896 | | - raise_for_error (bool, optional): Flag to indicate that we need to raise an exception if the response has some errors. Defaults to True. |
| 897 | + raise_for_error (bool, optional): Deprecated, flag to indicate that we need to raise an exception if the response has some errors. |
| 898 | + Defaults to True. |
897 | 899 | Raises: |
898 | 900 | GraphQLError: _description_ |
899 | 901 |
|
900 | 902 | Returns: |
901 | 903 | _type_: _description_ |
902 | 904 | """ |
| 905 | + if not raise_for_error: |
| 906 | + warnings.warn( |
| 907 | + "Setting `raise_for_error=False` is deprecated, use `try/except` to handle errors.", |
| 908 | + DeprecationWarning, |
| 909 | + stacklevel=1, |
| 910 | + ) |
903 | 911 |
|
904 | 912 | branch_name = branch_name or self.default_branch |
905 | 913 | url = self._graphql_url(branch_name=branch_name, at=at) |
@@ -950,9 +958,7 @@ async def execute_graphql( |
950 | 958 | response = decode_json(response=resp) |
951 | 959 |
|
952 | 960 | if "errors" in response: |
953 | | - if raise_for_error: |
954 | | - raise GraphQLError(errors=response["errors"], query=query, variables=variables) |
955 | | - return response["errors"] |
| 961 | + raise GraphQLError(errors=response["errors"], query=query, variables=variables) |
956 | 962 |
|
957 | 963 | return response["data"] |
958 | 964 |
|
@@ -1639,13 +1645,20 @@ def execute_graphql( |
1639 | 1645 | branch_name (str, optional): Name of the branch on which the query will be executed. Defaults to None. |
1640 | 1646 | at (str, optional): Time when the query should be executed. Defaults to None. |
1641 | 1647 | timeout (int, optional): Timeout in second for the query. Defaults to None. |
1642 | | - raise_for_error (bool, optional): Flag to indicate that we need to raise an exception if the response has some errors. Defaults to True. |
| 1648 | + raise_for_error (bool, optional): Deprecated, flag to indicate that we need to raise an exception if the response has some errors. |
| 1649 | + Defaults to True. |
1643 | 1650 | Raises: |
1644 | 1651 | GraphQLError: When an error occurs during the execution of the GraphQL query or mutation. |
1645 | 1652 |
|
1646 | 1653 | Returns: |
1647 | 1654 | dict: The result of the GraphQL query or mutation. |
1648 | 1655 | """ |
| 1656 | + if not raise_for_error: |
| 1657 | + warnings.warn( |
| 1658 | + "Setting `raise_for_error=False` is deprecated, use `try/except` to handle errors.", |
| 1659 | + DeprecationWarning, |
| 1660 | + stacklevel=1, |
| 1661 | + ) |
1649 | 1662 |
|
1650 | 1663 | branch_name = branch_name or self.default_branch |
1651 | 1664 | url = self._graphql_url(branch_name=branch_name, at=at) |
@@ -1696,9 +1709,7 @@ def execute_graphql( |
1696 | 1709 | response = decode_json(response=resp) |
1697 | 1710 |
|
1698 | 1711 | if "errors" in response: |
1699 | | - if raise_for_error: |
1700 | | - raise GraphQLError(errors=response["errors"], query=query, variables=variables) |
1701 | | - return response["errors"] |
| 1712 | + raise GraphQLError(errors=response["errors"], query=query, variables=variables) |
1702 | 1713 |
|
1703 | 1714 | return response["data"] |
1704 | 1715 |
|
|
0 commit comments