Skip to content

Commit

Permalink
全部移植
Browse files Browse the repository at this point in the history
  • Loading branch information
kgtkr committed Jan 17, 2024
1 parent d21f1af commit 9123ad1
Show file tree
Hide file tree
Showing 17 changed files with 154 additions and 254 deletions.
37 changes: 0 additions & 37 deletions packages/server/src/resolvers/index.ts

This file was deleted.

56 changes: 0 additions & 56 deletions packages/server/src/resolvers/res.ts

This file was deleted.

17 changes: 0 additions & 17 deletions packages/server/src/resolvers/subscription.ts

This file was deleted.

57 changes: 0 additions & 57 deletions packages/server/src/resolvers/topic.ts

This file was deleted.

9 changes: 9 additions & 0 deletions packages/server/src/schema/res/resolvers/ResBase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { getTopic } from "../../../usecases";
import type { ResResolvers } from "./../../types.generated";

export const ResBase: Omit<ResResolvers, "__resolveType"> = {
topic: async (res, _args, context, _info) => {
const topic = await getTopic({ id: res.topicID }, context.ports);
return topic;
},
};
19 changes: 6 additions & 13 deletions packages/server/src/schema/res/resolvers/ResDelete.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import type { ResDeleteResolvers } from './../../types.generated';
export const ResDelete: ResDeleteResolvers = {
/* Implement ResDelete resolver logic here */
date: () => { /* ResDelete.date resolver is required because ResDelete.date exists but ResDeleteMapper.date does not */ },
dv: () => { /* ResDelete.dv resolver is required because ResDelete.dv exists but ResDeleteMapper.dv does not */ },
hash: () => { /* ResDelete.hash resolver is required because ResDelete.hash exists but ResDeleteMapper.hash does not */ },
id: () => { /* ResDelete.id resolver is required because ResDelete.id exists but ResDeleteMapper.id does not */ },
replyCount: () => { /* ResDelete.replyCount resolver is required because ResDelete.replyCount exists but ResDeleteMapper.replyCount does not */ },
self: () => { /* ResDelete.self resolver is required because ResDelete.self exists but ResDeleteMapper.self does not */ },
topic: () => { /* ResDelete.topic resolver is required because ResDelete.topic exists but ResDeleteMapper.topic does not */ },
uv: () => { /* ResDelete.uv resolver is required because ResDelete.uv exists but ResDeleteMapper.uv does not */ },
voteFlag: () => { /* ResDelete.voteFlag resolver is required because ResDelete.voteFlag exists but ResDeleteMapper.voteFlag does not */ }
};
import type { ResDeleteResolvers } from "./../../types.generated";
import { ResBase } from "./ResBase";

export const ResDelete: ResDeleteResolvers = {
...ResBase,
};
28 changes: 14 additions & 14 deletions packages/server/src/schema/res/resolvers/ResFork.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import type { ResForkResolvers } from './../../types.generated';
export const ResFork: ResForkResolvers = {
/* Implement ResFork resolver logic here */
date: () => { /* ResFork.date resolver is required because ResFork.date exists but ResForkMapper.date does not */ },
dv: () => { /* ResFork.dv resolver is required because ResFork.dv exists but ResForkMapper.dv does not */ },
hash: () => { /* ResFork.hash resolver is required because ResFork.hash exists but ResForkMapper.hash does not */ },
id: () => { /* ResFork.id resolver is required because ResFork.id exists but ResForkMapper.id does not */ },
replyCount: () => { /* ResFork.replyCount resolver is required because ResFork.replyCount exists but ResForkMapper.replyCount does not */ },
self: () => { /* ResFork.self resolver is required because ResFork.self exists but ResForkMapper.self does not */ },
topic: () => { /* ResFork.topic resolver is required because ResFork.topic exists but ResForkMapper.topic does not */ },
uv: () => { /* ResFork.uv resolver is required because ResFork.uv exists but ResForkMapper.uv does not */ },
voteFlag: () => { /* ResFork.voteFlag resolver is required because ResFork.voteFlag exists but ResForkMapper.voteFlag does not */ },
fork: () => { /* ResFork.fork resolver is required because ResFork.fork exists but ResForkMapper.fork does not */ }
};
import { getTopic } from "../../../usecases";
import type { ResForkResolvers } from "./../../types.generated";
import { ResBase } from "./ResBase";

export const ResFork: ResForkResolvers = {
...ResBase,
fork: async (res, _args, context, _info) => {
const fork = await getTopic({ id: res.forkID }, context.ports);
if (fork.type !== "fork") {
throw new Error();
}
return fork;
},
};
25 changes: 11 additions & 14 deletions packages/server/src/schema/res/resolvers/ResHistory.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import type { ResHistoryResolvers } from './../../types.generated';
export const ResHistory: ResHistoryResolvers = {
/* Implement ResHistory resolver logic here */
date: () => { /* ResHistory.date resolver is required because ResHistory.date exists but ResHistoryMapper.date does not */ },
dv: () => { /* ResHistory.dv resolver is required because ResHistory.dv exists but ResHistoryMapper.dv does not */ },
hash: () => { /* ResHistory.hash resolver is required because ResHistory.hash exists but ResHistoryMapper.hash does not */ },
id: () => { /* ResHistory.id resolver is required because ResHistory.id exists but ResHistoryMapper.id does not */ },
replyCount: () => { /* ResHistory.replyCount resolver is required because ResHistory.replyCount exists but ResHistoryMapper.replyCount does not */ },
self: () => { /* ResHistory.self resolver is required because ResHistory.self exists but ResHistoryMapper.self does not */ },
topic: () => { /* ResHistory.topic resolver is required because ResHistory.topic exists but ResHistoryMapper.topic does not */ },
uv: () => { /* ResHistory.uv resolver is required because ResHistory.uv exists but ResHistoryMapper.uv does not */ },
voteFlag: () => { /* ResHistory.voteFlag resolver is required because ResHistory.voteFlag exists but ResHistoryMapper.voteFlag does not */ },
history: () => { /* ResHistory.history resolver is required because ResHistory.history exists but ResHistoryMapper.history does not */ }
};
import { getHistory } from "../../../usecases";
import type { ResHistoryResolvers } from "./../../types.generated";
import { ResBase } from "./ResBase";

export const ResHistory: ResHistoryResolvers = {
...ResBase,
history: async (res, _args, context, _info) => {
const history = await getHistory({ id: res.historyID }, context.ports);
return history;
},
};
38 changes: 23 additions & 15 deletions packages/server/src/schema/res/resolvers/ResNormal.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import type { ResNormalResolvers } from './../../types.generated';
export const ResNormal: ResNormalResolvers = {
/* Implement ResNormal resolver logic here */
date: () => { /* ResNormal.date resolver is required because ResNormal.date exists but ResNormalMapper.date does not */ },
dv: () => { /* ResNormal.dv resolver is required because ResNormal.dv exists but ResNormalMapper.dv does not */ },
hash: () => { /* ResNormal.hash resolver is required because ResNormal.hash exists but ResNormalMapper.hash does not */ },
id: () => { /* ResNormal.id resolver is required because ResNormal.id exists but ResNormalMapper.id does not */ },
replyCount: () => { /* ResNormal.replyCount resolver is required because ResNormal.replyCount exists but ResNormalMapper.replyCount does not */ },
self: () => { /* ResNormal.self resolver is required because ResNormal.self exists but ResNormalMapper.self does not */ },
topic: () => { /* ResNormal.topic resolver is required because ResNormal.topic exists but ResNormalMapper.topic does not */ },
uv: () => { /* ResNormal.uv resolver is required because ResNormal.uv exists but ResNormalMapper.uv does not */ },
voteFlag: () => { /* ResNormal.voteFlag resolver is required because ResNormal.voteFlag exists but ResNormalMapper.voteFlag does not */ },
profile: () => { /* ResNormal.profile resolver is required because ResNormal.profile exists but ResNormalMapper.profile does not */ },
reply: () => { /* ResNormal.reply resolver is required because ResNormal.reply exists but ResNormalMapper.reply does not */ }
};
import { getProfile, getRes } from "../../../usecases";
import type { ResNormalResolvers } from "./../../types.generated";
import { ResBase } from "./ResBase";

export const ResNormal: ResNormalResolvers = {
...ResBase,
reply: async (res, _args, context, _info) => {
if (res.replyID !== null) {
const reply = await getRes({ id: res.replyID }, context.ports);
return reply;
} else {
return null;
}
},
profile: async (res, _args, context, _info) => {
if (res.profileID !== null) {
const profile = await getProfile({ id: res.profileID }, context.ports);
return profile;
} else {
return null;
}
},
};
11 changes: 6 additions & 5 deletions packages/server/src/schema/res/resolvers/ResTopic.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ResTopicResolvers } from './../../types.generated';
export const ResTopic: ResTopicResolvers = {
/* Implement ResTopic resolver logic here */
topic: () => { /* ResTopic.topic resolver is required because ResTopic.topic exists but ResTopicMapper.topic does not */ }
};
import type { ResTopicResolvers } from "./../../types.generated";
import { ResBase } from "./ResBase";

export const ResTopic: ResTopicResolvers = {
...ResBase,
};
19 changes: 15 additions & 4 deletions packages/server/src/schema/res/resolvers/Subscription/resAdded.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
import type { SubscriptionResolvers } from './../../../types.generated';
export const resAdded: NonNullable<SubscriptionResolvers['resAdded']> = {
subscribe: async (_parent, _arg, _ctx) => { /* Implement Subscription.resAdded resolver logic here */ },
}
import type { SubscriptionResolvers } from "./../../../types.generated";
import * as ixa from "ix/asynciterable";
import * as ixaOps from "ix/asynciterable/operators";

export const resAdded: NonNullable<SubscriptionResolvers["resAdded"]> = {
subscribe: (_parent, args, context, _info) =>
ixa.from(context.ports.resRepo.subscribeInsertEvent(args.topic)).pipe(
ixaOps.map((data) => ({
resAdded: {
count: data.count,
res: data.res.toAPI(context.ports.authContainer.getTokenOrNull()),
},
}))
),
};
22 changes: 22 additions & 0 deletions packages/server/src/schema/resolveTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,26 @@ export const resolveTypes: Resolvers = {
}
},
},
Topic: {
__resolveType(obj) {
switch (obj.type) {
case "normal":
return "TopicNormal";
case "one":
return "TopicOne";
case "fork":
return "TopicFork";
}
},
},
TopicSearch: {
__resolveType(obj) {
switch (obj.type) {
case "normal":
return "TopicNormal";
case "one":
return "TopicOne";
}
},
},
};
16 changes: 16 additions & 0 deletions packages/server/src/schema/topic/resolvers/TopicBase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { TopicResolvers } from "./../../types.generated";
import * as O from "fp-ts/lib/Option";

export const TopicBase: Omit<TopicResolvers, "__resolveType"> = {
subscribe: async (topic, _args, context, _info) => {
// TODO: N+1
const token = context.ports.authContainer.getTokenOrNull();
if (O.isNone(token)) {
return null;
}
return await context.ports.topicRepo.getSubscription(
topic.id,
token.value.user
);
},
};
Loading

0 comments on commit 9123ad1

Please sign in to comment.