Skip to content

Commit

Permalink
feat(campaign): revise "WritingChallenge.articles" and return "featured"
Browse files Browse the repository at this point in the history
  • Loading branch information
gitwoz committed Oct 24, 2024
1 parent 7fe4439 commit c2c695a
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 5 deletions.
14 changes: 13 additions & 1 deletion schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -970,7 +970,7 @@ type WritingChallenge implements Node & Campaign {
stages: [CampaignStage!]!
state: CampaignState!
participants(input: CampaignParticipantsInput!): CampaignParticipantConnection!
articles(input: CampaignArticlesInput!): ArticleConnection!
articles(input: CampaignArticlesInput!): CampaignArticleConnection!
application: CampaignApplication
oss: CampaignOSS!
}
Expand All @@ -996,6 +996,18 @@ type CampaignParticipantEdge {
node: User!
}

type CampaignArticleConnection implements Connection {
totalCount: Int!
pageInfo: PageInfo!
edges: [CampaignArticleEdge!]!
}

type CampaignArticleEdge {
cursor: String!
node: Article!
featured: Boolean!
}

input CampaignParticipantsInput {
after: String
first: Int
Expand Down
64 changes: 62 additions & 2 deletions src/definitions/schema.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,20 @@ export type GQLCampaignApplication = {

export type GQLCampaignApplicationState = 'pending' | 'rejected' | 'succeeded'

export type GQLCampaignArticleConnection = GQLConnection & {
__typename?: 'CampaignArticleConnection'
edges: Array<GQLCampaignArticleEdge>
pageInfo: GQLPageInfo
totalCount: Scalars['Int']['output']
}

export type GQLCampaignArticleEdge = {
__typename?: 'CampaignArticleEdge'
cursor: Scalars['String']['output']
featured: Scalars['Boolean']['output']
node: GQLArticle
}

export type GQLCampaignArticleNotice = GQLNotice & {
__typename?: 'CampaignArticleNotice'
/** List of notice actors. */
Expand Down Expand Up @@ -4353,7 +4367,7 @@ export type GQLWritingChallenge = GQLCampaign &
announcements: Array<GQLArticle>
application?: Maybe<GQLCampaignApplication>
applicationPeriod?: Maybe<GQLDatetimeRange>
articles: GQLArticleConnection
articles: GQLCampaignArticleConnection
cover?: Maybe<Scalars['String']['output']>
description?: Maybe<Scalars['String']['output']>
id: Scalars['ID']['output']
Expand Down Expand Up @@ -4566,6 +4580,9 @@ export type GQLResolversInterfaceTypes<
| (Omit<GQLArticleVersionsConnection, 'edges'> & {
edges: Array<Maybe<RefType['ArticleVersionEdge']>>
})
| (Omit<GQLCampaignArticleConnection, 'edges'> & {
edges: Array<RefType['CampaignArticleEdge']>
})
| (Omit<GQLCampaignConnection, 'edges'> & {
edges?: Maybe<Array<RefType['CampaignEdge']>>
})
Expand Down Expand Up @@ -4760,6 +4777,16 @@ export type GQLResolversTypes = ResolversObject<{
Campaign: ResolverTypeWrapper<CampaignModel>
CampaignApplication: ResolverTypeWrapper<GQLCampaignApplication>
CampaignApplicationState: GQLCampaignApplicationState
CampaignArticleConnection: ResolverTypeWrapper<
Omit<GQLCampaignArticleConnection, 'edges'> & {
edges: Array<GQLResolversTypes['CampaignArticleEdge']>
}
>
CampaignArticleEdge: ResolverTypeWrapper<
Omit<GQLCampaignArticleEdge, 'node'> & {
node: GQLResolversTypes['Article']
}
>
CampaignArticleNotice: ResolverTypeWrapper<NoticeItemModel>
CampaignArticleNoticeType: GQLCampaignArticleNoticeType
CampaignArticlesFilter: GQLCampaignArticlesFilter
Expand Down Expand Up @@ -5385,6 +5412,12 @@ export type GQLResolversParentTypes = ResolversObject<{
Boolean: Scalars['Boolean']['output']
Campaign: CampaignModel
CampaignApplication: GQLCampaignApplication
CampaignArticleConnection: Omit<GQLCampaignArticleConnection, 'edges'> & {
edges: Array<GQLResolversParentTypes['CampaignArticleEdge']>
}
CampaignArticleEdge: Omit<GQLCampaignArticleEdge, 'node'> & {
node: GQLResolversParentTypes['Article']
}
CampaignArticleNotice: NoticeItemModel
CampaignArticlesFilter: GQLCampaignArticlesFilter
CampaignArticlesInput: GQLCampaignArticlesInput
Expand Down Expand Up @@ -6595,6 +6628,30 @@ export type GQLCampaignApplicationResolvers<
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>
}>

export type GQLCampaignArticleConnectionResolvers<
ContextType = Context,
ParentType extends GQLResolversParentTypes['CampaignArticleConnection'] = GQLResolversParentTypes['CampaignArticleConnection']
> = ResolversObject<{
edges?: Resolver<
Array<GQLResolversTypes['CampaignArticleEdge']>,
ParentType,
ContextType
>
pageInfo?: Resolver<GQLResolversTypes['PageInfo'], ParentType, ContextType>
totalCount?: Resolver<GQLResolversTypes['Int'], ParentType, ContextType>
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>
}>

export type GQLCampaignArticleEdgeResolvers<
ContextType = Context,
ParentType extends GQLResolversParentTypes['CampaignArticleEdge'] = GQLResolversParentTypes['CampaignArticleEdge']
> = ResolversObject<{
cursor?: Resolver<GQLResolversTypes['String'], ParentType, ContextType>
featured?: Resolver<GQLResolversTypes['Boolean'], ParentType, ContextType>
node?: Resolver<GQLResolversTypes['Article'], ParentType, ContextType>
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>
}>

export type GQLCampaignArticleNoticeResolvers<
ContextType = Context,
ParentType extends GQLResolversParentTypes['CampaignArticleNotice'] = GQLResolversParentTypes['CampaignArticleNotice']
Expand Down Expand Up @@ -7168,6 +7225,7 @@ export type GQLConnectionResolvers<
| 'AppreciationConnection'
| 'ArticleConnection'
| 'ArticleVersionsConnection'
| 'CampaignArticleConnection'
| 'CampaignConnection'
| 'CampaignParticipantConnection'
| 'CircleConnection'
Expand Down Expand Up @@ -9990,7 +10048,7 @@ export type GQLWritingChallengeResolvers<
ContextType
>
articles?: Resolver<
GQLResolversTypes['ArticleConnection'],
GQLResolversTypes['CampaignArticleConnection'],
ParentType,
ContextType,
RequireFields<GQLWritingChallengeArticlesArgs, 'input'>
Expand Down Expand Up @@ -10086,6 +10144,8 @@ export type GQLResolvers<ContextType = Context> = ResolversObject<{
BlockedSearchKeyword?: GQLBlockedSearchKeywordResolvers<ContextType>
Campaign?: GQLCampaignResolvers<ContextType>
CampaignApplication?: GQLCampaignApplicationResolvers<ContextType>
CampaignArticleConnection?: GQLCampaignArticleConnectionResolvers<ContextType>
CampaignArticleEdge?: GQLCampaignArticleEdgeResolvers<ContextType>
CampaignArticleNotice?: GQLCampaignArticleNoticeResolvers<ContextType>
CampaignConnection?: GQLCampaignConnectionResolvers<ContextType>
CampaignEdge?: GQLCampaignEdgeResolvers<ContextType>
Expand Down
21 changes: 20 additions & 1 deletion src/queries/campaign/articles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,31 @@ const resolver: GQLWritingChallengeResolvers['articles'] = async (
spamThreshold,
})

return connectionFromQuery({
const connection = await connectionFromQuery({
query,
orderBy: { column: 'order', order: 'desc' },
cursorColumn: 'id',
args: { first, after },
})

return {
...connection,
edges: await Promise.all(
connection.edges.map(async (edge) => {
const article = await atomService.findFirst({
table: 'campaign_article',
where: { campaignId, articleId: edge.node.id },
})
const featured = article.featured

return {
cursor: edge.cursor,
node: edge.node,
featured,
}
})
),
}
}

const validateStage = async (
Expand Down
14 changes: 13 additions & 1 deletion src/types/campaign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export default /* GraphQL */ `
state: CampaignState!
participants(input: CampaignParticipantsInput!): CampaignParticipantConnection!
articles(input: CampaignArticlesInput!): ArticleConnection!
articles(input: CampaignArticlesInput!): CampaignArticleConnection!
application: CampaignApplication @privateCache
Expand Down Expand Up @@ -133,6 +133,18 @@ export default /* GraphQL */ `
node: User! @logCache(type: "${NODE_TYPES.User}")
}
type CampaignArticleConnection implements Connection {
totalCount: Int!
pageInfo: PageInfo!
edges: [CampaignArticleEdge!]!
}
type CampaignArticleEdge {
cursor: String!
node: Article! @logCache(type: "${NODE_TYPES.Article}")
featured: Boolean!
}
input CampaignParticipantsInput {
after: String
first: Int
Expand Down

0 comments on commit c2c695a

Please sign in to comment.