Skip to content

Commit 992c22f

Browse files
authored
Remove stories, comments (demo) (kriasoft#243)
1 parent 1d33f17 commit 992c22f

File tree

13 files changed

+14
-647
lines changed

13 files changed

+14
-647
lines changed

api/schema.graphql

Lines changed: 0 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ type Root {
1919
me: User
2020
user(username: String!): User
2121
users(after: String, first: Int): UserConnection
22-
story(slug: String!): Story
23-
stories: [Story]
2422
}
2523

2624
# An object with an ID
@@ -116,32 +114,6 @@ type UserEdge {
116114
cursor: String!
117115
}
118116

119-
type Story implements Node {
120-
# The ID of an object
121-
id: ID!
122-
author: User!
123-
slug: String!
124-
title: String!
125-
text(truncate: Int): String!
126-
isURL: Boolean!
127-
comments: [Comment]
128-
pointsCount: Int!
129-
pointGiven: Boolean!
130-
commentsCount: Int!
131-
createdAt(format: String): String
132-
updatedAt(format: String): String
133-
}
134-
135-
type Comment implements Node {
136-
# The ID of an object
137-
id: ID!
138-
parent: Comment
139-
author: User!
140-
text: String
141-
createdAt(format: String): String
142-
updatedAt(format: String): String
143-
}
144-
145117
type Mutation {
146118
# Authenticates user with an ID token or email and password.
147119
signIn(idToken: String, email: String, password: String): SignInPayload
@@ -151,15 +123,6 @@ type Mutation {
151123

152124
# Updates a user.
153125
updateUser(input: UpdateUserInput!): UpdateUserPayload
154-
155-
# Deletes a user.
156-
deleteUser(input: DeleteUserInput!): DeleteUserPayload
157-
158-
# Creates or updates a story.
159-
upsertStory(input: UpsertStoryInput!): UpsertStoryPayload
160-
161-
# Marks the story as "liked".
162-
likeStory(input: LikeStoryInput!): LikeStoryPayload
163126
}
164127

165128
type SignInPayload {
@@ -183,38 +146,3 @@ input UpdateUserInput {
183146
validateOnly: Boolean
184147
clientMutationId: String
185148
}
186-
187-
type DeleteUserPayload {
188-
deletedUserId: String
189-
clientMutationId: String
190-
}
191-
192-
input DeleteUserInput {
193-
id: ID!
194-
clientMutationId: String
195-
}
196-
197-
type UpsertStoryPayload {
198-
story: Story
199-
errors: [[String!]!]
200-
clientMutationId: String
201-
}
202-
203-
input UpsertStoryInput {
204-
id: ID
205-
title: String
206-
text: String
207-
approved: Boolean
208-
validateOnly: Boolean
209-
clientMutationId: String
210-
}
211-
212-
type LikeStoryPayload {
213-
story: Story
214-
clientMutationId: String
215-
}
216-
217-
input LikeStoryInput {
218-
id: ID!
219-
clientMutationId: String
220-
}

api/src/context.ts

Lines changed: 6 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
import DataLoader from "dataloader";
88
import { Request } from "express";
99

10-
import db, { User, Identity, Story, Comment } from "./db";
11-
import { mapTo, mapToMany, mapToValues } from "./utils";
10+
import db, { User, Identity } from "./db";
11+
import { mapTo, mapToMany } from "./utils";
1212
import { UnauthorizedError, ForbiddenError } from "./error";
1313

1414
export class Context {
@@ -24,6 +24,10 @@ export class Context {
2424
}
2525
}
2626

27+
/*
28+
* Authentication and authorization
29+
* ------------------------------------------------------------------------ */
30+
2731
get user(): User | null {
2832
return this.req.user;
2933
}
@@ -36,10 +40,6 @@ export class Context {
3640
this.req.signOut();
3741
}
3842

39-
/*
40-
* Authorization
41-
* ------------------------------------------------------------------------ */
42-
4343
ensureAuthorized(check?: (user: User) => boolean): void {
4444
if (!this.req.user) {
4545
throw new UnauthorizedError();
@@ -89,107 +89,4 @@ export class Context {
8989
.select()
9090
.then((rows) => mapToMany(rows, keys, (x) => x.user_id)),
9191
);
92-
93-
storyById = new DataLoader<string, Story | null>((keys) =>
94-
db
95-
.table<Story>("stories")
96-
.whereIn("id", keys)
97-
.select()
98-
.then((rows) => {
99-
rows.forEach((x) => this.storyBySlug.prime(x.slug, x));
100-
return rows;
101-
})
102-
.then((rows) => mapTo(rows, keys, (x) => x.id)),
103-
);
104-
105-
storyBySlug = new DataLoader<string, Story | null>((keys) =>
106-
db
107-
.table<Story>("stories")
108-
.whereIn("slug", keys)
109-
.select()
110-
.then((rows) => {
111-
rows.forEach((x) => this.storyById.prime(x.id, x));
112-
return rows;
113-
})
114-
.then((rows) => mapTo(rows, keys, (x) => x.slug)),
115-
);
116-
117-
storyCommentsCount = new DataLoader<string, number>((keys) =>
118-
db
119-
.table<Comment>("comments")
120-
.whereIn("story_id", keys)
121-
.groupBy("story_id")
122-
.select<{ story_id: string; count: string }[]>(
123-
"story_id",
124-
db.raw("count(story_id)"),
125-
)
126-
.then((rows) =>
127-
mapToValues(
128-
rows,
129-
keys,
130-
(x) => x.story_id,
131-
(x) => (x ? Number(x.count) : 0),
132-
),
133-
),
134-
);
135-
136-
storyPointsCount = new DataLoader<string, number>((keys) =>
137-
db
138-
.table("stories")
139-
.leftJoin("story_points", "story_points.story_id", "stories.id")
140-
.whereIn("stories.id", keys)
141-
.groupBy("stories.id")
142-
.select("stories.id", db.raw("count(story_points.user_id)::int"))
143-
.then((rows) =>
144-
mapToValues(
145-
rows,
146-
keys,
147-
(x) => x.id,
148-
(x) => (x ? parseInt(x.count, 10) : 0),
149-
),
150-
),
151-
);
152-
153-
storyPointGiven = new DataLoader<string, boolean>((keys) => {
154-
const currentUser = this.user;
155-
const userId = currentUser ? currentUser.id : "";
156-
157-
return db
158-
.table("stories")
159-
.leftJoin("story_points", function join() {
160-
this.on("story_points.story_id", "stories.id").andOn(
161-
"story_points.user_id",
162-
db.raw("?", [userId]),
163-
);
164-
})
165-
.whereIn("stories.id", keys)
166-
.select<{ id: string; given: boolean }[]>(
167-
"stories.id",
168-
db.raw("(story_points.user_id IS NOT NULL) AS given"),
169-
)
170-
.then((rows) =>
171-
mapToValues(
172-
rows,
173-
keys,
174-
(x) => x.id,
175-
(x) => x?.given || false,
176-
),
177-
);
178-
});
179-
180-
commentById = new DataLoader<string, Comment | null>((keys) =>
181-
db
182-
.table<Comment>("comments")
183-
.whereIn("id", keys)
184-
.select()
185-
.then((rows) => mapTo(rows, keys, (x) => x.id)),
186-
);
187-
188-
commentsByStoryId = new DataLoader<string, Comment[]>((keys) =>
189-
db
190-
.table<Comment>("comments")
191-
.whereIn("story_id", keys)
192-
.select()
193-
.then((rows) => mapToMany(rows, keys, (x) => x.story_id)),
194-
);
19592
}

api/src/db.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,6 @@ export enum IdentityProvider {
4949
playgames = "playgames",
5050
}
5151

52-
export type CommentPoint = {
53-
comment_id: string;
54-
user_id: string;
55-
};
56-
57-
export type Comment = {
58-
id: string;
59-
story_id: string;
60-
parent_id: string | null;
61-
author_id: string;
62-
text: string | null;
63-
created_at: Date;
64-
updated_at: Date;
65-
};
66-
6752
export type Identity = {
6853
provider: IdentityProvider;
6954
id: string;
@@ -86,23 +71,6 @@ export type Identity = {
8671
expires_at: Date | null;
8772
};
8873

89-
export type Story = {
90-
id: string;
91-
author_id: string;
92-
slug: string;
93-
title: string;
94-
text: string | null;
95-
is_url: boolean;
96-
approved: boolean;
97-
created_at: Date;
98-
updated_at: Date;
99-
};
100-
101-
export type StoryPoint = {
102-
story_id: string;
103-
user_id: string;
104-
};
105-
10674
export type User = {
10775
id: string;
10876
username: string;

api/src/mutations/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,3 @@
66

77
export * from "./auth";
88
export * from "./user";
9-
export * from "./story";

0 commit comments

Comments
 (0)