finite_state_sdk.utils

 1from gql import gql
 2from graphql.language.ast import OperationDefinitionNode, OperationType
 3
 4
 5class BreakoutException(Exception):
 6    """Exception raised for errors in the BreakoutException."""
 7
 8    pass
 9
10
11def is_not_breakout_exception(exception):
12    """Check if the exception is not a BreakoutException."""
13    return not isinstance(exception, BreakoutException)
14
15
16def is_mutation(query_string):
17    """
18    Check if the provided GraphQL query string contains any mutations.
19
20    Args:
21        query_string (str): The GraphQL query string.
22
23    Returns:
24        bool: True if there is a mutation, False otherwise.
25    """
26    operation_types = determine_operation_types(query_string)
27    return OperationType.MUTATION in operation_types
28
29
30def determine_operation_types(query_string):
31    # Parse the query string
32    query_doc = gql(query_string)
33    operation_types = []
34
35    # Check the type of the first operation in the document
36    for definition in query_doc.definitions:
37        if isinstance(definition, OperationDefinitionNode):
38            operation_types.append(definition.operation)
39
40    return operation_types
class BreakoutException(builtins.Exception):
6class BreakoutException(Exception):
7    """Exception raised for errors in the BreakoutException."""
8
9    pass

Exception raised for errors in the BreakoutException.

Inherited Members
builtins.Exception
Exception
builtins.BaseException
with_traceback
add_note
args
def is_not_breakout_exception(exception):
12def is_not_breakout_exception(exception):
13    """Check if the exception is not a BreakoutException."""
14    return not isinstance(exception, BreakoutException)

Check if the exception is not a BreakoutException.

def is_mutation(query_string):
17def is_mutation(query_string):
18    """
19    Check if the provided GraphQL query string contains any mutations.
20
21    Args:
22        query_string (str): The GraphQL query string.
23
24    Returns:
25        bool: True if there is a mutation, False otherwise.
26    """
27    operation_types = determine_operation_types(query_string)
28    return OperationType.MUTATION in operation_types

Check if the provided GraphQL query string contains any mutations.

Arguments:
  • query_string (str): The GraphQL query string.
Returns:

bool: True if there is a mutation, False otherwise.

def determine_operation_types(query_string):
31def determine_operation_types(query_string):
32    # Parse the query string
33    query_doc = gql(query_string)
34    operation_types = []
35
36    # Check the type of the first operation in the document
37    for definition in query_doc.definitions:
38        if isinstance(definition, OperationDefinitionNode):
39            operation_types.append(definition.operation)
40
41    return operation_types