Skip to content

Commit

Permalink
resolve type errors in loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
marcushaddon committed Jun 22, 2023
1 parent f8b66b9 commit c1c739c
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 30 deletions.
8 changes: 4 additions & 4 deletions src/core/server/graph/loaders/CommentModerationActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import GraphContext from "coral-server/graph/context";
import { retrieveCommentModerationActionConnection } from "coral-server/models/action/moderation/comment";

import {
CommentToStatusHistoryArgs,
UserToCommentModerationActionHistoryArgs,
GQLCommentGQLstatusHistoryArgs,
GQLUserGQLcommentModerationActionHistoryArgs,
} from "coral-server/graph/schema/__generated__/types";

export default (ctx: GraphContext) => ({
forModerator: (
{ first, after }: UserToCommentModerationActionHistoryArgs,
{ first, after }: GQLUserGQLcommentModerationActionHistoryArgs,
moderatorID: string
) =>
retrieveCommentModerationActionConnection(ctx.mongo, ctx.tenant.id, {
Expand All @@ -21,7 +21,7 @@ export default (ctx: GraphContext) => ({
},
}),
forComment: (
{ first, after }: CommentToStatusHistoryArgs,
{ first, after }: GQLCommentGQLstatusHistoryArgs,
commentID: string
) =>
retrieveCommentModerationActionConnection(ctx.mongo, ctx.tenant.id, {
Expand Down
45 changes: 29 additions & 16 deletions src/core/server/graph/loaders/Comments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@ import {
} from "coral-server/services/comments";

import {
CommentToParentsArgs,
CommentToRepliesArgs,
GQLActionPresence,
GQLCOMMENT_SORT,
GQLCommentGQLparentsArgs,
GQLCommentGQLrepliesArgs,
GQLFEATURE_FLAG,
GQLQueryGQLcommentsArgs,
GQLSTORY_MODE,
GQLStoryGQLcommentsArgs,
GQLTAG,
GQLUSER_ROLE,
QueryToCommentsArgs,
StoryToCommentsArgs,
UserToAllCommentsArgs,
UserToCommentsArgs,
UserToRejectedCommentsArgs,
GQLUserGQLallCommentsArgs,
GQLUserGQLcommentsArgs,
GQLUserGQLrejectedCommentsArgs,
} from "coral-server/graph/schema/__generated__/types";

import { requiredPropertyFilter, sectionFilter } from "./helpers";
Expand Down Expand Up @@ -214,7 +214,7 @@ export default (ctx: GraphContext) => ({
tag,
query,
orderBy,
}: QueryToCommentsArgs) => {
}: GQLQueryGQLcommentsArgs) => {
let story: Readonly<Story> | null = null;
if (storyID) {
story = await ctx.loaders.Stories.story.load(storyID);
Expand Down Expand Up @@ -268,21 +268,24 @@ export default (ctx: GraphContext) => ({
);
}
),
forUser: (userID: string, { first, orderBy, after }: UserToCommentsArgs) =>
forUser: (
userID: string,
{ first, orderBy, after }: GQLUserGQLcommentsArgs
) =>
retrieveCommentUserConnection(ctx.mongo, ctx.tenant.id, userID, {
first: defaultTo(first, 10),
orderBy: defaultTo(orderBy, GQLCOMMENT_SORT.CREATED_AT_DESC),
after,
}).then(primeCommentsFromConnection(ctx)),
forUserAll: (userID: string, { first, after }: UserToAllCommentsArgs) =>
forUserAll: (userID: string, { first, after }: GQLUserGQLallCommentsArgs) =>
retrieveAllCommentsUserConnection(ctx.mongo, ctx.tenant.id, userID, {
first: defaultTo(first, 10),
orderBy: GQLCOMMENT_SORT.CREATED_AT_DESC,
after,
}).then(primeCommentsFromConnection(ctx)),
forUserRejected: (
userID: string,
{ first, after }: UserToRejectedCommentsArgs
{ first, after }: GQLUserGQLrejectedCommentsArgs
) =>
retrieveRejectedCommentUserConnection(ctx.mongo, ctx.tenant.id, userID, {
first: defaultTo(first, 10),
Expand All @@ -292,7 +295,7 @@ export default (ctx: GraphContext) => ({
taggedForStory: async (
storyID: string,
tag: GQLTAG,
{ first, orderBy, after }: StoryToCommentsArgs
{ first, orderBy, after }: GQLStoryGQLcommentsArgs
) => {
const story = await ctx.loaders.Stories.story.load(storyID);
if (!story) {
Expand All @@ -318,7 +321,14 @@ export default (ctx: GraphContext) => ({
},
forStory: async (
storyID: string,
{ first, orderBy, after, tag, rating, refreshStream }: StoryToCommentsArgs
{
first,
orderBy,
after,
tag,
rating,
refreshStream,
}: GQLStoryGQLcommentsArgs
) => {
const story = await ctx.loaders.Stories.story.load(storyID);
if (!story) {
Expand Down Expand Up @@ -381,7 +391,7 @@ export default (ctx: GraphContext) => ({
forParent: async (
storyID: string,
parentID: string,
{ first, orderBy, after, flatten, refreshStream }: CommentToRepliesArgs
{ first, orderBy, after, flatten, refreshStream }: GQLCommentGQLrepliesArgs
) => {
const story = await ctx.loaders.Stories.story.load(storyID);
if (!story) {
Expand Down Expand Up @@ -434,7 +444,10 @@ export default (ctx: GraphContext) => ({

return conn;
},
parents: async (comment: Comment, { last, before }: CommentToParentsArgs) => {
parents: async (
comment: Comment,
{ last, before }: GQLCommentGQLparentsArgs
) => {
const story = await ctx.loaders.Stories.story.load(comment.storyID);
if (!story) {
throw new StoryNotFoundError(comment.storyID);
Expand All @@ -454,7 +467,7 @@ export default (ctx: GraphContext) => ({
},
allChildComments: async (
comment: Comment,
{ orderBy }: CommentToRepliesArgs
{ orderBy }: GQLCommentGQLrepliesArgs
) => {
const story = await ctx.loaders.Stories.story.load(comment.storyID);
if (!story) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/graph/loaders/Sites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
SiteConnectionInput,
} from "coral-server/models/site";

import { QueryToSitesArgs } from "coral-server/graph/schema/__generated__/types";
import { GQLQueryGQLsitesArgs } from "coral-server/graph/schema/__generated__/types";

const queryFilter = (query?: string): SiteConnectionInput["filter"] => {
if (query) {
Expand All @@ -26,7 +26,7 @@ export default (ctx: TenantContext) => ({
cache: !ctx.disableCaching,
}
),
connection: ({ first, after, query }: QueryToSitesArgs) =>
connection: ({ first, after, query }: GQLQueryGQLsitesArgs) =>
retrieveSiteConnection(ctx.mongo, ctx.tenant.id, {
first: defaultTo(first, 20),
after,
Expand Down
18 changes: 12 additions & 6 deletions src/core/server/graph/loaders/Stories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ import {
import { scraper } from "coral-server/services/stories/scraper";

import {
GQLQueryGQLstoriesArgs,
GQLSiteGQLtopStoriesArgs,
GQLSTORY_STATUS,
QueryToStoriesArgs,
SiteToTopStoriesArgs,
UserToOngoingDiscussionsArgs,
GQLUserGQLongoingDiscussionsArgs,
} from "coral-server/graph/schema/__generated__/types";

import { createManyBatchLoadFn } from "./util";
Expand Down Expand Up @@ -215,7 +215,13 @@ export default (ctx: GraphContext) => ({
cache: !ctx.disableCaching,
}
),
connection: ({ first, after, status, query, siteIDs }: QueryToStoriesArgs) =>
connection: ({
first,
after,
status,
query,
siteIDs,
}: GQLQueryGQLstoriesArgs) =>
retrieveStoryConnection(ctx.mongo, ctx.tenant.id, {
first: defaultTo(first, 10),
after,
Expand All @@ -229,7 +235,7 @@ export default (ctx: GraphContext) => ({
...queryFilter(query),
},
}).then(primeStoriesFromConnection(ctx)),
topStories: (siteID: string, { limit }: SiteToTopStoriesArgs) => {
topStories: (siteID: string, { limit }: GQLSiteGQLtopStoriesArgs) => {
// Find top active stories in the last 24 hours.
const start = DateTime.fromJSDate(ctx.now).minus({ hours: 24 }).toJSDate();

Expand Down Expand Up @@ -266,7 +272,7 @@ export default (ctx: GraphContext) => ({
),
ongoingDiscussions: (
authorID: string,
{ limit }: UserToOngoingDiscussionsArgs
{ limit }: GQLUserGQLongoingDiscussionsArgs
) =>
retrieveOngoingDiscussions(
ctx.mongo,
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/graph/loaders/Users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {
} from "coral-server/models/user";

import {
GQLQueryGQLusersArgs,
GQLUSER_ROLE,
GQLUSER_STATUS_FILTER,
QueryToUsersArgs,
} from "coral-server/graph/schema/__generated__/types";

type UserConnectionFilterInput = UserConnectionInput["filter"];
Expand Down Expand Up @@ -115,7 +115,7 @@ export default (ctx: Context) => {

return {
user,
connection: ({ first, after, role, query, status }: QueryToUsersArgs) =>
connection: ({ first, after, role, query, status }: GQLQueryGQLusersArgs) =>
retrieveUserConnection(ctx.mongo, ctx.tenant.id, {
first: defaultTo(first, 10),
after,
Expand Down

0 comments on commit c1c739c

Please sign in to comment.