Skip to content

Commit

Permalink
feat(notes): query to retrieve a note (#970)
Browse files Browse the repository at this point in the history
* feat(notes): query to retrieve a note

POCKET-10857

* chore: add back an accidentally deleted line

* chore: update docstring to match new generic args

* chore: add dom to lib

for ProseMirror types
  • Loading branch information
kschelonka authored Nov 21, 2024
1 parent 740bd2d commit bc66071
Show file tree
Hide file tree
Showing 28 changed files with 1,040 additions and 71 deletions.
234 changes: 204 additions & 30 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion servers/notes-api/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
schema: './schema.graphql',
generates: {
'./src/__generated__/types.ts': {
'./src/__generated__/graphql.d.ts': {
config: {
federation: true,
useIndexSignature: true,
Expand Down
2 changes: 1 addition & 1 deletion servers/notes-api/jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ process.env.AWS_DEFAULT_REGION = 'us-east-1';
process.env.DATABASE_URL =
'postgresql://pocket:password@localhost:5432/pocketnotes';
process.env.DATABASE_NAME = 'pocketnotes';
process.env.DATABASE_USER = 'pkt_notes';
process.env.DATABASE_USER = 'pocket';
process.env.DATABASE_PASSWORD = 'password';
process.env.DATABASE_HOST = 'localhost';
process.env.DATABASE_PORT = '5432';
23 changes: 16 additions & 7 deletions servers/notes-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,19 @@
"build-schema": "node dist/apollo/schema/buildSchema.js",
"db:generate": "prisma generate",
"db:push": "prisma db push --skip-generate",
"migrate:create": "dotenv -e .env.ci -- prisma migrate dev --create-only",
"dev": "dotenv -e .env.ci -- pnpm run migrate:deploy && pnpm run build && pnpm run watch",
"migrate:deploy": "prisma migrate deploy",
"prisma:pull": "dotenv -e .env.ci -- prisma db pull",
"prisma:generate": "dotenv -e .env.ci -- prisma generate",
"migrate:dev": "dotenv -e .env.ci -- prisma migrate dev",
"migrate:reset": "dotenv -e .env.ci -- prisma migrate reset",
"format": "eslint --fix",
"kysely:generate": "dotenv -e .env.ci -- kysely-codegen --out-file ./src/__generated__/db.d.ts",
"lint": "eslint --fix-dry-run",
"prebuild": "graphql-codegen && dotenv -e .env.ci -- prisma generate",
"migrate:create": "dotenv -e .env.ci -- prisma migrate dev --create-only",
"migrate:deploy": "prisma migrate deploy",
"migrate:dev": "dotenv -e .env.ci -- prisma migrate dev && pnpm run kysely:generate",
"migrate:reset": "dotenv -e .env.ci -- prisma migrate reset",
"prebuild": "graphql-codegen && pnpm run prisma:generate",
"pretest": "pnpm run prisma:generate",
"pretest-integrations": "dotenv -e .env.ci -- prisma migrate reset --skip-seed --force",
"prisma:generate": "dotenv -e .env.ci -- prisma generate && pnpm run kysely:generate",
"prisma:pull": "dotenv -e .env.ci -- prisma db pull",
"start": "pnpm run migrate:deploy && node dist/main.js",
"test": "jest \"\\.spec\\.ts\"",
"test-integrations": "jest \"\\.integration\\.ts\" --runInBand",
Expand All @@ -45,12 +46,16 @@
"@pocket-tools/ts-logger": "workspace:*",
"@sentry/node": "8.38.0",
"cors": "2.8.5",
"dataloader": "2.2.2",
"express": "4.20.0",
"graphql": "16.9.0",
"graphql-constraint-directive": "5.4.2",
"graphql-scalars": "^1.23.0",
"graphql-tag": "2.12.6",
"kysely": "0.27.4",
"pg": "^8.13.1",
"prosemirror-markdown": "^1.13.1",
"prosemirror-model": "^1.23.0",
"tslib": "2.8.0",
"uuid": "^10.0.0"
},
Expand All @@ -60,14 +65,18 @@
"@graphql-codegen/typescript-resolvers": "^4.1.0",
"@parcel/watcher": "^2.4.1",
"@pocket-tools/eslint-config": "workspace:*",
"@types/chance": "1.1.6",
"@types/cors": "^2.8.17",
"@types/express": "4.17.21",
"@types/jest": "29.5.14",
"@types/node": "^22.8.2",
"@types/pg": "^8.11.10",
"@types/supertest": "^6.0.2",
"chance": "1.1.12",
"concurrently": "^8.2.2",
"jest": "29.7.0",
"jest-extended": "4.0.2",
"kysely-codegen": "^0.16.4",
"nock": "14.0.0-beta.11",
"nodemon": "3.1.7",
"prisma": "5.21.1",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
Warnings:
- Made the column `clippingId` on table `Clipping` required. This step will fail if there are existing NULL values in that column.
- Made the column `noteId` on table `Note` required. This step will fail if there are existing NULL values in that column.
*/
-- AlterTable
ALTER TABLE "Clipping" ALTER COLUMN "clippingId" SET NOT NULL;

-- AlterTable
ALTER TABLE "Note" ADD COLUMN "archived" BOOLEAN NOT NULL DEFAULT false,
ALTER COLUMN "noteId" SET NOT NULL,
ALTER COLUMN "title" DROP NOT NULL;
13 changes: 4 additions & 9 deletions servers/notes-api/prisma/schema.prisma
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
generator kysely {
provider = "prisma-kysely"
output = "../node_modules/.kysely/client"
fileName = "types.ts"
}

datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
}

model Clipping {
id Int @id @default(autoincrement())
clippingId String? @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
clippingId String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
userId String @db.VarChar(300)
noteId String @unique @db.Uuid
sourceUrl String
Expand All @@ -28,14 +22,15 @@ model Clipping {

model Note {
id Int @id @default(autoincrement())
noteId String? @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
noteId String @unique @default(dbgenerated("gen_random_uuid()")) @db.Uuid
userId String @db.VarChar(300)
title String @db.VarChar(300)
title String? @db.VarChar(300)
sourceUrl String?
createdAt DateTime @default(dbgenerated("CURRENT_TIMESTAMP(0)")) @db.Timestamptz(0)
updatedAt DateTime @db.Timestamptz(3)
docContent Json?
deleted Boolean @default(false)
archived Boolean @default(false)
Clipping Clipping?
@@index([updatedAt], map: "NoteUpdated")
Expand Down
21 changes: 19 additions & 2 deletions servers/notes-api/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ extend schema
@composeDirective(name: "@constraint")

scalar ISOString
scalar ValidUrl
scalar Markdown

"""
A Note is an entity which may contain extracted components
Expand All @@ -12,7 +14,7 @@ and may be linked to a source url.
"""
type Note @key(fields: "id") {
"""
The Note's ID
This Note's identifier
"""
id: ID!
"""
Expand All @@ -26,7 +28,7 @@ type Note @key(fields: "id") {
"""
Markdown preview of the note content for summary view.
"""
contentPreview: String
contentPreview: Markdown
"""
When this note was created
"""
Expand All @@ -40,6 +42,21 @@ type Note @key(fields: "id") {
or via a Clipping, if applicable)
"""
savedItem: SavedItem
"""
The URL this entity was created from (either directly or via
a Clipping, if applicable).
"""
source: ValidUrl
"""
Whether this Note has been marked as archived (hide from default view).
"""
archived: Boolean!
"""
Whether this Note has been marked for deletion (will be eventually
removed from the server). Clients should delete Notes from their local
storage if this value is true.
"""
deleted: Boolean!
}

type SavedItem @key(fields: "url") {
Expand Down
66 changes: 66 additions & 0 deletions servers/notes-api/src/__generated__/db.d.ts

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

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

Loading

0 comments on commit bc66071

Please sign in to comment.