# Path: graphscale/pent.py
# class PentContextfulObject:
#     def __init__(self, context: PentContext) -> None:
#         self.__context = context
# 
#     @property
#     def context(self) -> PentContext:
#         return self.__context
# 
# class PentLoader(DataLoader):
#     def __init__(self, context: PentContext) -> None:
#         super().__init__(batch_load_fn=self._load_pents)
#         self.context = context
# 
#     async def _load_pents(self, ids: List[UUID]) -> Sequence[Pent]:
#         obj_dict = await self._actual_load_pent_dict(ids)
#         return list(obj_dict.values())
# 
#     async def _actual_load_pent_dict(self, ids: List[UUID]) -> Dict[UUID, Pent]:
#         obj_dict = await self.context.kvetch.gen_objects(ids)
#         pent_dict = OrderedDict()  # type: OrderedDict[UUID, Pent]
#         for obj_id, data in obj_dict.items():
#             if not data:
#                 pent_dict[obj_id] = None
#             else:
#                 cls = self.context.config.get_type(data['type_id'])
#                 pent_dict[obj_id] = cls(self.context, obj_id, data)
#         return pent_dict


from typing import Callable, Any
from graphql import GraphQLSchema
from sanic import Sanic
from sanic_graphql import GraphQLView
from .pent import PentContextfulObject, PentLoader
        from aoiklivereload import LiveReloader
    """ Creates a Sanic app and adds a graphql/graphiql endpoint """
    app = Sanic(__name__)
    app.debug = debug

    if debug:
        # hack from https://github.com/channelcat/sanic/issues/168
        # for some reason pylint is confused by this import
        #E0611 no name in module
        #pylint: disable=E0611
        reloader = LiveReloader()
        reloader.start_watcher_thread()

    # this is totally gross and I need a better story for managing context lifetime
    # versus loader lifetime. The context houses the in-memory shards in in memory
    # case currently so you cannot create a new one with every request. However
    # you do need a new loader every request because it is affined with its
    # asyncio event loop
    def root_factory() -> Any:
        root_object.context.loader = PentLoader(root_object.context)
        return root_object

    app.add_route(
        GraphQLView.as_view(
            schema=schema, graphiql=True, root_factory=root_factory, context=root_object.context
        ), '/graphql'
    )
    return app


def run_graphql_endpoint(

# Path: graphscale/pent.py
# class PentContextfulObject:
#     def __init__(self, context: PentContext) -> None:
#         self.__context = context
# 
#     @property
#     def context(self) -> PentContext:
#         return self.__context
# 
# class PentLoader(DataLoader):
#     def __init__(self, context: PentContext) -> None:
#         super().__init__(batch_load_fn=self._load_pents)
#         self.context = context
# 
#     async def _load_pents(self, ids: List[UUID]) -> Sequence[Pent]:
#         obj_dict = await self._actual_load_pent_dict(ids)
#         return list(obj_dict.values())
# 
#     async def _actual_load_pent_dict(self, ids: List[UUID]) -> Dict[UUID, Pent]:
#         obj_dict = await self.context.kvetch.gen_objects(ids)
#         pent_dict = OrderedDict()  # type: OrderedDict[UUID, Pent]
#         for obj_id, data in obj_dict.items():
#             if not data:
#                 pent_dict[obj_id] = None
#             else:
#                 cls = self.context.config.get_type(data['type_id'])
#                 pent_dict[obj_id] = cls(self.context, obj_id, data)
#         return pent_dict


# Path: graphscale/server.py
from typing import Callable, Any
from graphql import GraphQLSchema
from sanic import Sanic
from sanic_graphql import GraphQLView
from .pent import PentContextfulObject, PentLoader
        from aoiklivereload import LiveReloader

    """ Creates a Sanic app and adds a graphql/graphiql endpoint """
    app = Sanic(__name__)
    app.debug = debug

    if debug:
        # hack from https://github.com/channelcat/sanic/issues/168
        # for some reason pylint is confused by this import
        #E0611 no name in module
        #pylint: disable=E0611
        reloader = LiveReloader()
        reloader.start_watcher_thread()

    # this is totally gross and I need a better story for managing context lifetime
    # versus loader lifetime. The context houses the in-memory shards in in memory
    # case currently so you cannot create a new one with every request. However
    # you do need a new loader every request because it is affined with its
    # asyncio event loop
    def root_factory() -> Any:
        root_object.context.loader = PentLoader(root_object.context)
        return root_object

    app.add_route(
        GraphQLView.as_view(
            schema=schema, graphiql=True, root_factory=root_factory, context=root_object.context
        ), '/graphql'
    )
    return app


def run_graphql_endpoint(

    root_object: PentContextfulObject, schema: GraphQLSchema, debug: bool=True, port: int=8080