예제 #1
0
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)
예제 #2
0
def resolve_list_books(root, info) -> List[Book]:
    core = LibraryCore.from_request()
    return list(core.list_books())
예제 #3
0
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)
예제 #4
0
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)
예제 #5
0
def resolve_get_request(root, info, id: int) -> BookRequest:
    core = LibraryCore.from_request()
    return core.get_request(id)