def resolve_create_request(root, info, data: CreateRequestInput = None ) -> CreateRequestOutput: core = LibraryCore.from_request() try: request_id = core.create_request(email=data.email, title=data.title) except UserError as e: return CreateRequestOutput(ok=False, error_message=str(e)) return CreateRequestOutput(ok=True, request_id=request_id)
def resolve_list_books(root, info) -> List[Book]: core = LibraryCore.from_request() return list(core.list_books())
def resolve_delete_request(root, info, id: int) -> DeleteRequestOutput: core = LibraryCore.from_request() request = core.get_request(id) core.delete_request(request) return DeleteRequestOutput(ok=True)
def resolve_create_request_output_request(root, info) -> BookRequest: if root.request_id is None: return None core = LibraryCore.from_request() return core.get_request(root.request_id)
def resolve_get_request(root, info, id: int) -> BookRequest: core = LibraryCore.from_request() return core.get_request(id)