示例#1
0
def resolve_create_note(
        root, info, data: CreateNoteInput = None) -> CreateNoteOutput:

    core = NotesCore.from_request()
    try:
        note_id = core.create(title=data.title, text=data.text)
    except UserError as e:
        return CreateNoteOutput(ok=False, error_message=str(e))

    return CreateNoteOutput(ok=True, note_id=note_id)
示例#2
0
def resolve_update_note(
        root,
        info,
        id: int,
        data: UpdateNoteInput) -> UpdateNoteOutput:

    core = NotesCore.from_request()
    note = core.get(id)
    core.update(note, title=data.title, text=data.text)
    return UpdateNoteOutput(ok=True, note_id=id)
示例#3
0
def resolve_upload_note(
        root, info, uploaded_file: GraphQLFileUpload) -> UploadNoteOutput:

    core = NotesCore.from_request()
    title = uploaded_file.filename
    text = uploaded_file.stream.read().decode('utf-8')

    # TODO: ensure the file contains text, not binary data

    note_id = core.create(title=title, text=text)
    return UploadNoteOutput(ok=True, note_id=note_id)
示例#4
0
def resolve_update_note_output_note(root, info) -> Note:
    core = NotesCore.from_request()
    return core.get(root.note_id)
示例#5
0
def resolve_get_note(root, info, id: int) -> Note:
    core = NotesCore.from_request()
    return core.get(id)
示例#6
0
def resolve_list_notes(root, info) -> List[Note]:
    core = NotesCore.from_request()
    return list(core.list())
示例#7
0
def resolve_delete_note(root, info, id: int) -> DeleteNoteOutput:
    core = NotesCore.from_request()
    note = core.get(id)
    core.delete(note)
    return DeleteNoteOutput(ok=True)