Skip to content

Commit

Permalink
chore: move some integrations to SDL pattern (#10000)
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Krick <[email protected]>
  • Loading branch information
mattkrick authored Jul 18, 2024
1 parent 5c45379 commit 6d01097
Show file tree
Hide file tree
Showing 61 changed files with 1,745 additions and 2,307 deletions.
20 changes: 20 additions & 0 deletions codegen.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,19 @@
"packages/server/graphql/public/resolverTypes.ts": {
"config": {
"contextType": "../graphql#GQLContext",
"showUnusedMappers": false,
"mappers": {
"_xGitLabProject": "./types/_xGitLabProject#_xGitLabProjectSource as _xGitLabProject",
"JiraServerIntegration": "./types/JiraServerIntegration#JiraServerIntegrationSource",
"GitHubIntegration": "../../postgres/queries/getGitHubAuthByUserIdTeamId#GitHubAuth",
"GitLabIntegration": "./types/GitLabIntegration#GitLabIntegrationSource",
"MattermostIntegration": "./types/MattermostIntegration#MattermostIntegrationSource",
"MSTeamsIntegration": "./types/MSTeamsIntegration#MSTeamsIntegrationSource",
"SlackIntegration": "../../database/types/SlackAuth#default as SlackAuthDB",
"SlackNotification": "../../database/types/SlackNotification#default as SlackNotificationDB",
"AzureDevOpsIntegration": ".types/AzureDevOpsIntegration#AzureDevOpsIntegrationSource",
"AzureDevOpsWorkItem": "../../dataloader/azureDevOpsLoaders#AzureDevOpsWorkItem",
"AzureDevOpsRemoteProject": "./types/AzureDevOpsRemoteProject#AzureDevOpsRemoteProjectSource",
"AcceptRequestToJoinDomainSuccess": "./types/AcceptRequestToJoinDomainSuccess#AcceptRequestToJoinDomainSuccessSource",
"AcceptTeamInvitationPayload": "./types/AcceptTeamInvitationPayload#AcceptTeamInvitationPayloadSource",
"ActionMeeting": "../../database/types/MeetingAction#default",
Expand All @@ -56,6 +68,8 @@
"AddedNotification": "./types/AddedNotification#AddedNotificationSource",
"AgendaItem": "../../database/types/AgendaItem#default as AgendaItemDB",
"ArchiveTeamPayload": "./types/ArchiveTeamPayload#ArchiveTeamPayloadSource",
"AtlassianIntegration": "../../postgres/queries/getAtlassianAuthByUserIdTeamId#AtlassianAuth as AtlassianAuthDB",
"JiraSearchQuery": "../../database/types/JiraSearchQuery#default as JiraSearchQueryDB",
"AuthTokenPayload": "./types/AuthTokenPayload#AuthTokenPayloadSource",
"AutogroupSuccess": "./types/AutogroupSuccess#AutogroupSuccessSource",
"BatchArchiveTasksSuccess": "./types/BatchArchiveTasksSuccess#BatchArchiveTasksSuccessSource",
Expand All @@ -71,8 +85,12 @@
"GcalIntegration": "./types/GcalIntegration#GcalIntegrationSource",
"GenerateGroupsSuccess": "./types/GenerateGroupsSuccess#GenerateGroupsSuccessSource",
"GetTemplateSuggestionSuccess": "./types/GetTemplateSuggestionSuccess#GetTemplateSuggestionSuccessSource",
"IntegrationProviderWebhook": "../../postgres/queries/getIntegrationProvidersByIds#TIntegrationProvider",
"IntegrationProviderOAuth1": "../../postgres/queries/getIntegrationProvidersByIds#TIntegrationProvider",
"IntegrationProviderOAuth2": "../../postgres/queries/getIntegrationProvidersByIds#TIntegrationProvider",
"InviteToTeamPayload": "./types/InviteToTeamPayload#InviteToTeamPayloadSource",
"JiraServerIssue": "./types/JiraServerIssue#JiraServerIssueSource",
"JiraServerRemoteProject": "../../dataloader/jiraServerLoaders#JiraServerProject",
"JiraIssue": "./types/JiraIssue#JiraIssueSource",
"JiraRemoteProject": "../types/JiraRemoteProject#JiraRemoteProjectSource",
"MeetingSeries": "../../postgres/types/MeetingSeries#MeetingSeries",
Expand Down Expand Up @@ -126,6 +144,8 @@
"TeamHealthStage": "./types/TeamHealthStage#TeamHealthStageSource",
"TeamInvitation": "../../database/types/TeamInvitation#default",
"TeamMember": "../../database/types/TeamMember#default as TeamMemberDB",
"TeamMemberIntegrationAuthWebhook": "../../postgres/queries/getTeamMemberIntegrationAuth#TeamMemberIntegrationAuth",
"TeamMemberIntegrationAuthOAuth1": "../../postgres/queries/getTeamMemberIntegrationAuth#TeamMemberIntegrationAuth",
"TeamMemberIntegrationAuthOAuth2": "../../postgres/queries/getTeamMemberIntegrationAuth#TeamMemberIntegrationAuth",
"TeamMemberIntegrations": "./types/TeamMemberIntegrations#TeamMemberIntegrationsSource",
"TeamPromptMeeting": "../../database/types/MeetingTeamPrompt#default as MeetingTeamPromptDB",
Expand Down
4 changes: 3 additions & 1 deletion packages/server/dataloader/azureDevOpsLoaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ export interface AzureDevOpsWorkItem {
type: string
descriptionHTML: string
service: 'azureDevOps'
teamId: string
userId: string
}

export interface AzureUserInfo {
Expand All @@ -123,7 +125,7 @@ export interface AzureAccountProject extends TeamProjectReference {
service: 'azureDevOps'
}

interface AzureProject extends ProjectRes {
export interface AzureProject extends ProjectRes {
userId: string
teamId: string
service: 'azureDevOps'
Expand Down
6 changes: 5 additions & 1 deletion packages/server/dataloader/jiraServerLoaders.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ type TeamUserKey = {
export type JiraServerProject = JiraServerRestProject & {
service: 'jiraServer'
providerId: number
userId: string
teamId: string
}

export const jiraServerIssue = (parent: RootDataLoader) => {
Expand Down Expand Up @@ -123,7 +125,9 @@ export const allJiraServerProjects = (parent: RootDataLoader) => {
.map((project) => ({
...project,
service: 'jiraServer' as const,
providerId: provider.id
providerId: provider.id,
userId,
teamId
}))
})
)
Expand Down
198 changes: 0 additions & 198 deletions packages/server/graphql/private/typeDefs/_legacy.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -982,35 +982,6 @@ type StandardMutationError {
message: String!
}

"""
A jira search query including all filters selected when the query was executed
"""
type JiraSearchQuery {
"""
shortid
"""
id: ID!

"""
The query string, either simple or JQL depending on the isJQL flag
"""
queryString: String!

"""
true if the queryString is JQL, else false
"""
isJQL: Boolean!

"""
The list of project keys selected as a filter. null if not set
"""
projectKeyFilters: [ID!]!

"""
the time the search query was last used. Used for sorting
"""
lastUsedAt: DateTime!
}

"""
The auth credentials for a token, specific to a team member
Expand Down Expand Up @@ -1057,97 +1028,8 @@ interface TeamMemberIntegrationAuth {
provider: IntegrationProvider!
}

"""
A connection to a list of items.
"""
type JiraServerIssueConnection {
"""
Page info with cursors coerced to ISO8601 dates
"""
pageInfo: PageInfo

"""
A list of edges.
"""
edges: [JiraServerIssueEdge!]!

"""
An error with the connection, if any
"""
error: StandardMutationError
}

"""
An edge in a connection.
"""
type JiraServerIssueEdge {
"""
The item at the end of the edge
"""
node: JiraServerIssue!
cursor: String
}

"""
The Jira Issue that comes direct from Jira Server
"""
type JiraServerIssue implements TaskIntegration {
id: ID!
issueKey: ID!
projectKey: ID!
projectName: String!

"""
The parabol teamId this issue was fetched for
"""
teamId: ID!

"""
The parabol userId this issue was fetched for
"""
userId: ID!

"""
The url to access the issue
"""
url: String!

"""
The plaintext summary of the jira issue
"""
summary: String!
description: String!

"""
The description converted into raw HTML
"""
descriptionHTML: String!

"""
The timestamp the issue was last updated
"""
updatedAt: DateTime!
}

"""
A GitHub search query including all filters selected when the query was executed
"""
type GitHubSearchQuery {
"""
shortid
"""
id: ID!

"""
The query string in GitHub format, including repository filters. e.g. is:issue is:open
"""
queryString: String!

"""
the time the search query was last used. Used for sorting
"""
lastUsedAt: DateTime!
}

"""
The event that triggers a slack notification
Expand All @@ -1174,86 +1056,6 @@ enum SlackNotificationEventTypeEnum {
member
}

"""
The Azure DevOps auth + integration helpers for a specific team member
"""
type AzureDevOpsIntegration {
"""
The OAuth2 Authorization for this team member
"""
auth: TeamMemberIntegrationAuthOAuth2

"""
Composite key in ado:teamId:userId format
"""
id: ID!

"""
true if the auth is valid, else false
"""
isActive: Boolean!

"""
The access token to Azure DevOps. null if no access token available or the viewer is not the user
"""
accessToken: ID

"""
The Azure DevOps account ID
"""
accountId: ID!

"""
The Azure DevOps instance IDs that the user has granted
"""
instanceIds: [ID!]!

"""
The timestamp the provider was created
"""
createdAt: DateTime!

"""
The team that the token is linked to
"""
teamId: ID!

"""
The timestamp the token was updated at
"""
updatedAt: DateTime!

"""
The user that the access token is attached to
"""
userId: ID!

"""
The cloud provider the team member may choose to integrate with. Nullable based on env vars
"""
cloudProvider: IntegrationProviderOAuth2

"""
The non-global providers shared with the team or organization
"""
sharedProviders: [IntegrationProviderOAuth2!]!
}

"""
The Azure DevOps Issue that comes direct from Azure DevOps
"""
type AzureDevOpsWorkItem {
"""
GUID instanceId:issueKey
"""
id: ID!

"""
URL to the issue
"""
url: String!
}

"""
All the user details for a specific meeting
"""
Expand Down
48 changes: 24 additions & 24 deletions packages/server/graphql/public/rootSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,27 @@ import permissions from './permissions'
// Resolvers from SDL first definitions
import resolvers from './resolvers'

// Schema from legacy TypeScript first definitions
const legacyParabolSchema = new GraphQLSchema({
// Schema from legacy TypeScript first definitions instead of SDL pattern
const legacyTypeDefs = new GraphQLSchema({
query,
mutation,
// defining a placeholder subscription because there's a bug in nest-graphql-schema that prefixes to _xGitHubSubscription if missing
subscription: new GraphQLObjectType({name: 'Subscription', fields: {}}),
types: rootTypes
})

const {schema: legacyParabolWithGitHubSchema, githubRequest} = nestGitHubEndpoint({
parentSchema: legacyParabolSchema,
const importAllStrings = (context: __WebpackModuleApi.RequireContext) => {
return context.keys().map((id) => context(id).default)
}

// Merge old POJO definitions with SDL definitions
const parabolTypeDefs = mergeSchemas({
schemas: [legacyTypeDefs],
typeDefs: importAllStrings(require.context('./typeDefs', false, /.graphql$/))
})

const {schema: typeDefsWithGitHub, githubRequest} = nestGitHubEndpoint({
parentSchema: parabolTypeDefs,
parentType: 'GitHubIntegration',
fieldName: 'api',
resolveEndpointContext: ({accessToken}) => ({
Expand All @@ -42,8 +52,8 @@ const {schema: legacyParabolWithGitHubSchema, githubRequest} = nestGitHubEndpoin
schemaIDL: githubSchema
})

const {schema: legacyParabolWithGitLabSchema, gitlabRequest} = nestGitLabEndpoint({
parentSchema: legacyParabolSchema,
const {schema: typeDefsWithGitHubGitLab, gitlabRequest} = nestGitLabEndpoint({
parentSchema: typeDefsWithGitHub,
parentType: 'GitLabIntegration',
fieldName: 'api',
resolveEndpointContext: async (
Expand All @@ -67,25 +77,15 @@ const {schema: legacyParabolWithGitLabSchema, gitlabRequest} = nestGitLabEndpoin
schemaIDL: gitlabSchema
})

const importAllStrings = (context: __WebpackModuleApi.RequireContext) => {
return context.keys().map((id) => context(id).default)
}

// Types from SDL first
const typeDefs = importAllStrings(require.context('./typeDefs', false, /.graphql$/))

const legacyParabolWithNestedSchema = mergeSchemas({
schemas: [legacyParabolWithGitHubSchema, legacyParabolWithGitLabSchema],
typeDefs
})

// IMPORTANT! mergeSchemas has a bug where resolvers will be overwritten by the default resolvers
// See https://github.com/ardatan/graphql-tools/issues/4367
const parabolWithNestedResolversSchema = addResolversToSchema({
schema: legacyParabolWithNestedSchema,
resolvers: composeResolvers(resolvers, permissions),
inheritResolversFromInterfaces: true
})
const publicSchema = resolveTypesForMutationPayloads(
addResolversToSchema({
schema: typeDefsWithGitHubGitLab,
resolvers: composeResolvers(resolvers, permissions),
inheritResolversFromInterfaces: true
})
)

const addRequestors = (schema: GraphQLSchema) => {
const finalSchema = schema as any
Expand All @@ -97,6 +97,6 @@ const addRequestors = (schema: GraphQLSchema) => {
}
}

const rootSchema = addRequestors(resolveTypesForMutationPayloads(parabolWithNestedResolversSchema))
const rootSchema = addRequestors(publicSchema)

export default rootSchema
Loading

0 comments on commit 6d01097

Please sign in to comment.