# Path: graphscale/pent.py
# class PentContext:
#     def __init__(self, *, kvetch: Kvetch, config: PentConfig) -> None:
#         self.__kvetch = kvetch
#         self.__config = config
#         self.loader = PentLoader(self)
# 
#     def cls_from_name(self, name: str) -> Type:
#         return self.__config.get_class_from_name(name)
# 
#     @property
#     def kvetch(self) -> Kvetch:
#         return self.__kvetch
# 
#     @property
#     def config(self) -> PentConfig:
#         return self.__config
# 
#     # had to change things to nuke loader at beginning of request again
#     # @property
#     # def loader(self) -> 'PentLoader':
#     #     return self.__loader
# 
# class PentContextfulObject:
#     def __init__(self, context: PentContext) -> None:
#         self.__context = context
# 
#     @property
#     def context(self) -> PentContext:
#         return self.__context


from typing import Any, Dict, NamedTuple, cast
from graphql import graphql as graphql_main
from graphql import GraphQLSchema
from graphql.execution import ExecutionResult
from .pent import PentContext, PentContextfulObject
        import traceback
        full_query = (
            '{operation} ({arg_list}) '.format(arg_list=arg_list, operation=operation) + '{' +
            graphql_text + '}'
        )
        arg_dict = {arg.name: arg.value for arg in args}
        result = await (
            exec_in_mem_graphql(
                self.graphql_schema, self.context, full_query, self.root_value, arg_dict
            )
        )
        if result.errors:
            _process_error(result)

        return cast(dict, result.data)


def _process_error(result: ExecutionResult) -> None:
    # this is pretty horrific. need a better generalized story to getting reasonable
    # stack traces
    print(repr(result.errors[0]))
    if hasattr(result.errors[0], 'original_error'):
        print(repr(result.errors[0].original_error))
        original_error = result.errors[0].original_error
        trace = original_error.__traceback__
        trace_string = ''.join(traceback.format_tb(trace))
        print('ORIGINAL: ' + trace_string)


async def exec_in_mem_graphql(
    graphql_schema: GraphQLSchema,

# Path: graphscale/pent.py
# class PentContext:
#     def __init__(self, *, kvetch: Kvetch, config: PentConfig) -> None:
#         self.__kvetch = kvetch
#         self.__config = config
#         self.loader = PentLoader(self)
# 
#     def cls_from_name(self, name: str) -> Type:
#         return self.__config.get_class_from_name(name)
# 
#     @property
#     def kvetch(self) -> Kvetch:
#         return self.__kvetch
# 
#     @property
#     def config(self) -> PentConfig:
#         return self.__config
# 
#     # had to change things to nuke loader at beginning of request again
#     # @property
#     # def loader(self) -> 'PentLoader':
#     #     return self.__loader
# 
# class PentContextfulObject:
#     def __init__(self, context: PentContext) -> None:
#         self.__context = context
# 
#     @property
#     def context(self) -> PentContext:
#         return self.__context


# Path: graphscale/graphql_client.py
from typing import Any, Dict, NamedTuple, cast
from graphql import graphql as graphql_main
from graphql import GraphQLSchema
from graphql.execution import ExecutionResult
from .pent import PentContext, PentContextfulObject
        import traceback

        full_query = (
            '{operation} ({arg_list}) '.format(arg_list=arg_list, operation=operation) + '{' +
            graphql_text + '}'
        )
        arg_dict = {arg.name: arg.value for arg in args}
        result = await (
            exec_in_mem_graphql(
                self.graphql_schema, self.context, full_query, self.root_value, arg_dict
            )
        )
        if result.errors:
            _process_error(result)

        return cast(dict, result.data)


def _process_error(result: ExecutionResult) -> None:
    # this is pretty horrific. need a better generalized story to getting reasonable
    # stack traces
    print(repr(result.errors[0]))
    if hasattr(result.errors[0], 'original_error'):
        print(repr(result.errors[0].original_error))
        original_error = result.errors[0].original_error
        trace = original_error.__traceback__
        trace_string = ''.join(traceback.format_tb(trace))
        print('ORIGINAL: ' + trace_string)


async def exec_in_mem_graphql(
    graphql_schema: GraphQLSchema,

    pent_context: PentContext,