Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove noteFromQuote mutations #1034

Merged
merged 2 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 0 additions & 76 deletions servers/notes-api/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -277,72 +277,6 @@ input CreateNoteMarkdownInput {
createdAt: ISOString
}

"""
Input to create a new Note seeded with copied content from a page.
The entire content becomes editable and is not able to be "reattached"
like a traditional highlight.
"""
input CreateNoteFromQuoteInput {
"""Optional title for this Note"""
title: String
"""
Client-provided UUID for the new Note.
If not provided, will be generated on the server.
"""
id: ID
"""
The Web Resource where the quote is taken from.
This should always be sent by the client where possible,
but in some cases (e.g. copying from mobile apps) there may
not be an accessible source url.
"""
source: ValidUrl
"""
JSON representation of a ProseMirror document, which
contains the formatted snipped text. This is used to seed
the initial Note document state, and will become editable.
"""
quote: ProseMirrorJson!
"""
When this note was created. If not provided, defaults to server time upon
receiving request.
"""
createdAt: ISOString
}

"""
Input to create a new Note seeded with copied content from a page.
The entire content becomes editable and is not able to be "reattached"
like a traditional highlight.
"""
input CreateNoteFromQuoteMarkdownInput {
"""Optional title for this Note"""
title: String
"""
Client-provided UUID for the new Note.
If not provided, will be generated on the server.
"""
id: ID
"""
The Web Resource where the quote is taken from.
This should always be sent by the client where possible,
but in some cases (e.g. copying from mobile apps) there may
not be an accessible source url.
"""
source: ValidUrl
"""
Commonmark Markdown document, which contains the formatted
snipped text. This is used to seed the initial Note
document state, and will become editable.
"""
quote: Markdown!
"""
When this note was created. If not provided, defaults to server time upon
receiving request.
"""
createdAt: ISOString
}

input EditNoteTitleInput {
"""The ID of the note to edit"""
id: ID!
Expand Down Expand Up @@ -427,16 +361,6 @@ type Mutation {
Create a new note, optionally with title and markdown content
"""
createNoteMarkdown(input: CreateNoteMarkdownInput!): Note! @requiresScopes(scopes: [["ROLE_USER"]])
"""
Create a new note, with a pre-populated block that contains the quoted and cited text
selected by a user.
"""
createNoteFromQuote(input: CreateNoteFromQuoteInput!): Note! @requiresScopes(scopes: [["ROLE_USER"]])
"""
Create a new note, with a pre-populated block that contains the quoted and cited text
selected by a user.
"""
createNoteFromQuoteMarkdown(input: CreateNoteFromQuoteMarkdownInput!): Note! @requiresScopes(scopes: [["ROLE_USER"]])

"""
Edit the title of a Note.
Expand Down
96 changes: 2 additions & 94 deletions servers/notes-api/src/__generated__/graphql.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 0 additions & 6 deletions servers/notes-api/src/apollo/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,6 @@ export const resolvers: Resolvers = {
createNoteMarkdown(root, { input }, context) {
return context.NoteModel.createFromMarkdown(input);
},
createNoteFromQuote(root, { input }, context) {
return context.NoteModel.fromQuote(input);
},
createNoteFromQuoteMarkdown(root, { input }, context) {
return context.NoteModel.fromMarkdownQuote(input);
},
editNoteTitle(root, { input }, context) {
return context.NoteModel.editTitle(input);
},
Expand Down
48 changes: 1 addition & 47 deletions servers/notes-api/src/models/Note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@ import DataLoader from 'dataloader';
import {
Note,
CreateNoteInput,
CreateNoteFromQuoteInput,
EditNoteTitleInput,
EditNoteContentInput,
DeleteNoteInput,
CreateNoteFromQuoteMarkdownInput,
CreateNoteMarkdownInput,
EditNoteContentMarkdownInput,
ArchiveNoteInput,
Expand All @@ -16,11 +14,7 @@ import { Insertable, NoResultError, Selectable } from 'kysely';
import { orderAndMap } from '../utils/dataloader';
import { IContext } from '../apollo/context';
import { NotesService } from '../datasources/NoteService';
import {
docFromMarkdown,
ProseMirrorDoc,
wrapDocInBlockQuote,
} from './ProseMirrorDoc';
import { docFromMarkdown, ProseMirrorDoc } from './ProseMirrorDoc';
import { DatabaseError } from 'pg';
import {
NoteFilterInput,
Expand Down Expand Up @@ -192,46 +186,6 @@ export class NoteModel {
};
return await this.create(createInput);
}
/**
* Create a new Note seeded with a blockquote (optionally with
* an additional paragraph with the source link).
*/
async fromQuote(input: CreateNoteFromQuoteInput) {
try {
const docContent = JSON.parse(input.quote);
const options =
input.source != null ? { source: input.source.toString() } : undefined;
const quotedDoc = wrapDocInBlockQuote(docContent, options);
const createInput: CreateNoteInput = {
docContent: JSON.stringify(quotedDoc),
createdAt: input.createdAt,
id: input.id,
title: input.title,
source: input.source,
};
return this.create(createInput);
} catch (error) {
if (error instanceof SyntaxError) {
throw new UserInputError(
`Received malformed JSON for docContent: ${error.message}`,
);
} else {
throw error;
}
}
}
/**
* Create a new Note seeded with a blockquote (optionally with
* an additional paragraph with the source link).
*/
async fromMarkdownQuote(input: CreateNoteFromQuoteMarkdownInput) {
const quote = docFromMarkdown(input.quote);
const createInput: CreateNoteFromQuoteInput = {
...input,
quote: JSON.stringify(quote.toJSON()),
};
return await this.fromQuote(createInput);
}
/**
* Edit a note's title
*/
Expand Down
40 changes: 1 addition & 39 deletions servers/notes-api/src/models/ProseMirrorDoc.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import basicText from '../test/documents/basicText.json';
import {
docFromMarkdown,
ProseMirrorDoc,
wrapDocInBlockQuote,
} from './ProseMirrorDoc';
import { docFromMarkdown, ProseMirrorDoc } from './ProseMirrorDoc';
import { schema } from 'prosemirror-markdown';
import fromQuote from '../test/documents/fromQuote.json';
import badMd from '../test/documents/badMd.json';
import { UserInputError } from '@pocket-tools/apollo-utils';
import * as fs from 'fs';
import path from 'path';

Expand All @@ -30,38 +24,6 @@ describe('ProseMirrorDoc', () => {
expect(doc.markdown).toBeString();
});
});
describe('quote constructor', () => {
it('wraps quote in blockquote and adds attribution', () => {
const { input, expectedSource } = fromQuote;
const actual = wrapDocInBlockQuote(input, { source: 'localhost:3001' });
expect(actual).toEqual(expectedSource);
});
it('wraps quote in blockquote without attribution', () => {
const { input, expectedNoSource } = fromQuote;
const actual = wrapDocInBlockQuote(input);
expect(actual).toEqual(expectedNoSource);
});
it('throws error if an invalid node is encountered', () => {
const bad = {
type: 'doc',
content: [
{
type: 'invalid',
content: [
{
type: 'text',
text: '',
},
],
},
],
};
expect(() => wrapDocInBlockQuote(bad)).toThrowWithMessage(
UserInputError,
/.*Invalid Document.*/,
);
});
});
describe('markdown parser', () => {
it('parses plain text paragraphs', () => {
const doc = docFromMarkdown(basicTextMd);
Expand Down
Loading
Loading