-
Notifications
You must be signed in to change notification settings - Fork 337
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: refactor ReflectionGroup to SDL pattern (#9807)
Signed-off-by: Matt Krick <matt.krick@gmail.com>
- Loading branch information
Showing
7 changed files
with
47 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,6 @@ graphql` | |
reflectionGroups { | ||
id | ||
title | ||
smartTitle | ||
reflections { | ||
id | ||
plaintextContent | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,7 +14,6 @@ graphql` | |
id | ||
title | ||
promptId | ||
smartTitle | ||
reflections { | ||
id | ||
plaintextContent | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 37 additions & 1 deletion
38
packages/server/graphql/public/types/RetroReflectionGroup.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,45 @@ | ||
import {Selectable} from 'kysely' | ||
import MeetingRetrospective from '../../../database/types/MeetingRetrospective' | ||
import Reflection from '../../../database/types/Reflection' | ||
import {RetroReflectionGroup as TRetroReflectionGroup} from '../../../postgres/pg' | ||
import {getUserId} from '../../../utils/authorization' | ||
import {RetroReflectionGroupResolvers} from '../resolverTypes' | ||
|
||
export interface RetroReflectionGroupSource extends Selectable<TRetroReflectionGroup> {} | ||
|
||
const RetroReflectionGroup: RetroReflectionGroupResolvers = {} | ||
const RetroReflectionGroup: RetroReflectionGroupResolvers = { | ||
meeting: async ({meetingId}, _args, {dataLoader}) => { | ||
const retroMeeting = await dataLoader.get('newMeetings').load(meetingId) | ||
return retroMeeting as MeetingRetrospective | ||
}, | ||
prompt: ({promptId}, _args, {dataLoader}) => { | ||
return dataLoader.get('reflectPrompts').load(promptId) | ||
}, | ||
reflections: async ({id: reflectionGroupId, meetingId}, _args, {dataLoader}) => { | ||
// use meetingId so we only hit the DB once instead of once per group | ||
const reflections = await dataLoader.get('retroReflectionsByMeetingId').load(meetingId) | ||
const filteredReflections = reflections.filter( | ||
(reflection: Reflection) => reflection.reflectionGroupId === reflectionGroupId | ||
) | ||
filteredReflections.sort((a: Reflection, b: Reflection) => (a.sortOrder < b.sortOrder ? 1 : -1)) | ||
return filteredReflections | ||
}, | ||
team: async ({meetingId}, _args, {dataLoader}) => { | ||
const meeting = await dataLoader.get('newMeetings').load(meetingId) | ||
return dataLoader.get('teams').loadNonNull(meeting.teamId) | ||
}, | ||
titleIsUserDefined: ({title, smartTitle}) => { | ||
return title ? title !== smartTitle : false | ||
}, | ||
voteCount: ({voterIds}) => { | ||
return voterIds ? voterIds.length : 0 | ||
}, | ||
viewerVoteCount: ({voterIds}, _args, {authToken}) => { | ||
const viewerId = getUserId(authToken) | ||
return voterIds | ||
? voterIds.reduce((sum, voterId) => (voterId === viewerId ? sum + 1 : sum), 0) | ||
: 0 | ||
} | ||
} | ||
|
||
export default RetroReflectionGroup |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,145 +1,9 @@ | ||
import { | ||
GraphQLBoolean, | ||
GraphQLFloat, | ||
GraphQLID, | ||
GraphQLInt, | ||
GraphQLList, | ||
GraphQLNonNull, | ||
GraphQLObjectType, | ||
GraphQLString | ||
} from 'graphql' | ||
import Reflection from '../../database/types/Reflection' | ||
import {getUserId} from '../../utils/authorization' | ||
import {GraphQLObjectType} from 'graphql' | ||
import {GQLContext} from '../graphql' | ||
import {resolveForSU} from '../resolvers' | ||
import CommentorDetails from './CommentorDetails' | ||
import GraphQLISO8601Type from './GraphQLISO8601Type' | ||
import ReflectPrompt from './ReflectPrompt' | ||
import RetroReflection from './RetroReflection' | ||
import RetrospectiveMeeting from './RetrospectiveMeeting' | ||
import Team from './Team' | ||
|
||
const RetroReflectionGroup: GraphQLObjectType = new GraphQLObjectType<any, GQLContext>({ | ||
name: 'RetroReflectionGroup', | ||
description: 'A reflection group created during the group phase of a retrospective', | ||
fields: () => ({ | ||
id: { | ||
type: new GraphQLNonNull(GraphQLID), | ||
description: 'shortid' | ||
}, | ||
commentors: { | ||
type: new GraphQLList(new GraphQLNonNull(CommentorDetails)), | ||
description: 'A list of users currently commenting', | ||
deprecationReason: 'Moved to ThreadConnection. Can remove Jun-01-2021', | ||
resolve: ({commentor = []}) => { | ||
return commentor | ||
} | ||
}, | ||
createdAt: { | ||
type: new GraphQLNonNull(GraphQLISO8601Type), | ||
description: 'The timestamp the meeting was created' | ||
}, | ||
isActive: { | ||
type: new GraphQLNonNull(GraphQLBoolean), | ||
description: 'True if the group has not been removed, else false' | ||
}, | ||
meetingId: { | ||
type: new GraphQLNonNull(GraphQLID), | ||
description: 'The foreign key to link a reflection group to its meeting' | ||
}, | ||
meeting: { | ||
type: new GraphQLNonNull(RetrospectiveMeeting), | ||
description: 'The retrospective meeting this reflection was created in', | ||
resolve: ({meetingId}, _args: unknown, {dataLoader}) => { | ||
return dataLoader.get('newMeetings').load(meetingId) | ||
} | ||
}, | ||
prompt: { | ||
type: new GraphQLNonNull(ReflectPrompt), | ||
resolve: ({promptId}, _args: unknown, {dataLoader}) => { | ||
return dataLoader.get('reflectPrompts').load(promptId) | ||
} | ||
}, | ||
promptId: { | ||
type: new GraphQLNonNull(GraphQLID), | ||
description: 'The foreign key to link a reflection group to its prompt. Immutable.' | ||
}, | ||
reflections: { | ||
type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(RetroReflection))), | ||
resolve: async ({id: reflectionGroupId, meetingId}, _args: unknown, {dataLoader}) => { | ||
// use meetingId so we only hit the DB once instead of once per group | ||
const reflections = await dataLoader.get('retroReflectionsByMeetingId').load(meetingId) | ||
const filteredReflections = reflections.filter( | ||
(reflection: Reflection) => reflection.reflectionGroupId === reflectionGroupId | ||
) | ||
filteredReflections.sort((a: Reflection, b: Reflection) => | ||
a.sortOrder < b.sortOrder ? 1 : -1 | ||
) | ||
return filteredReflections | ||
} | ||
}, | ||
smartTitle: { | ||
type: GraphQLString, | ||
description: 'Our auto-suggested title, to be compared to the actual title for analytics', | ||
resolve: resolveForSU('smartTitle') | ||
}, | ||
sortOrder: { | ||
type: new GraphQLNonNull(GraphQLFloat), | ||
description: 'The sort order of the reflection group' | ||
}, | ||
discussionPromptQuestion: { | ||
type: GraphQLString, | ||
description: `The AI generated question to prompt and engage the discussion of this reflection group` | ||
}, | ||
team: { | ||
type: Team, | ||
description: 'The team that is running the retro', | ||
resolve: async ({meetingId}, _args: unknown, {dataLoader}) => { | ||
const meeting = await dataLoader.get('newMeetings').load(meetingId) | ||
return dataLoader.get('teams').load(meeting.teamId) | ||
} | ||
}, | ||
title: { | ||
type: GraphQLString, | ||
description: 'The title of the grouping of the retrospective reflections' | ||
}, | ||
titleIsUserDefined: { | ||
type: new GraphQLNonNull(GraphQLBoolean), | ||
description: 'true if a user wrote the title, else false', | ||
resolve: ({title, smartTitle}) => { | ||
return title ? title !== smartTitle : false | ||
} | ||
}, | ||
updatedAt: { | ||
type: GraphQLISO8601Type, | ||
description: 'The timestamp the meeting was updated at' | ||
}, | ||
voterIds: { | ||
type: new GraphQLNonNull(new GraphQLList(new GraphQLNonNull(GraphQLID))), | ||
description: 'A list of voterIds (userIds). Not available to team to preserve anonymity', | ||
resolve: resolveForSU('voterIds') | ||
}, | ||
voteCount: { | ||
type: new GraphQLNonNull(GraphQLInt), | ||
description: 'The number of votes this group has received', | ||
resolve: ({voterIds}) => { | ||
return voterIds ? voterIds.length : 0 | ||
} | ||
}, | ||
viewerVoteCount: { | ||
type: GraphQLInt, | ||
description: 'The number of votes the viewer has given this group', | ||
resolve: ({voterIds}, _args: unknown, {authToken}) => { | ||
const viewerId = getUserId(authToken) | ||
return voterIds | ||
? voterIds.reduce( | ||
(sum: number, voterId: string) => (voterId === viewerId ? sum + 1 : sum), | ||
0 | ||
) | ||
: 0 | ||
} | ||
} | ||
}) | ||
fields: {} | ||
}) | ||
|
||
export default RetroReflectionGroup |