Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(server): quick js to ts #3 - remaining branches resolver #3397

Merged
merged 3 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { ActionTypes, ResourceTypes } from '@/modules/activitystream/helpers/types'
import {
pubsub,
BranchSubscriptions as BranchPubsubEvents,
PublishSubscription
} from '@/modules/shared/utils/subscriptions'
Expand Down Expand Up @@ -38,8 +37,7 @@ export const addBranchCreatedActivityFactory =
info: { branch },
message: `Branch created: ${branch.name} (${branch.id})`
}),
// @deprecated
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the @deprecated annotation relevant and used by tooling? Do we need to retain it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not really, Alessandro added it to avoid having to type these old subscriptions but i've done it here anyway. besides, there's a bunch of other subscriptions that are also "deprecated" and don't have this tag

pubsub.publish(BranchPubsubEvents.BranchCreated, {
publish(BranchPubsubEvents.BranchCreated, {
branchCreated: { ...branch },
streamId: branch.streamId
}),
Expand Down Expand Up @@ -76,8 +74,7 @@ export const addBranchUpdatedActivityFactory =
info: { old: oldBranch, new: update },
message: `Branch metadata changed for branch ${update.id}`
}),
// @deprecated
pubsub.publish(BranchPubsubEvents.BranchUpdated, {
publish(BranchPubsubEvents.BranchUpdated, {
branchUpdated: { ...update },
streamId,
branchId: update.id
Expand Down Expand Up @@ -115,7 +112,7 @@ export const addBranchDeletedActivityFactory =
info: { branch: { ...input, name: branchName } },
message: `Branch deleted: '${branchName}' (${input.id})`
}),
pubsub.publish(BranchPubsubEvents.BranchDeleted, {
publish(BranchPubsubEvents.BranchDeleted, {
branchDeleted: input,
streamId
}),
Expand Down
74 changes: 0 additions & 74 deletions packages/server/modules/core/graph/resolvers/branches.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { authorizeResolver } from '@/modules/shared'
import { authorizeResolver, BranchPubsubEvents } from '@/modules/shared'
import {
createBranchAndNotifyFactory,
updateBranchAndNotifyFactory,
Expand Down Expand Up @@ -30,7 +30,7 @@ import { legacyGetUserFactory } from '@/modules/core/repositories/users'
import { Resolvers } from '@/modules/core/graph/generated/graphql'
import { getPaginatedStreamBranchesFactory } from '@/modules/core/services/branch/retrieval'
import { saveActivityFactory } from '@/modules/activitystream/repositories'
import { publish } from '@/modules/shared/utils/subscriptions'
import { filteredSubscribe, publish } from '@/modules/shared/utils/subscriptions'

const markBranchStreamUpdated = markBranchStreamUpdatedFactory({ db })
const getStream = getStreamFactory({ db })
Expand Down Expand Up @@ -137,5 +137,57 @@ export = {
const deleted = await deleteBranchAndNotify(args.branch, context.userId!)
return deleted
}
},
Subscription: {
branchCreated: {
subscribe: filteredSubscribe(
BranchPubsubEvents.BranchCreated,
async (payload, variables, context) => {
await authorizeResolver(
context.userId,
payload.streamId,
Roles.Stream.Reviewer,
context.resourceAccessRules
)

return payload.streamId === variables.streamId
}
)
},
branchUpdated: {
subscribe: filteredSubscribe(
BranchPubsubEvents.BranchUpdated,
async (payload, variables, context) => {
await authorizeResolver(
context.userId,
payload.streamId,
Roles.Stream.Reviewer,
context.resourceAccessRules
)

const streamMatch = payload.streamId === variables.streamId
if (streamMatch && variables.branchId) {
return payload.branchId === variables.branchId
}

return streamMatch
}
)
},
branchDeleted: {
subscribe: filteredSubscribe(
BranchPubsubEvents.BranchDeleted,
async (payload, variables, context) => {
await authorizeResolver(
context.userId,
payload.streamId,
Roles.Stream.Reviewer,
context.resourceAccessRules
)

return payload.streamId === variables.streamId
}
)
}
}
} as Resolvers
27 changes: 26 additions & 1 deletion packages/server/modules/shared/utils/subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@ import {
StreamUpdateInput,
ProjectUpdateInput,
SubscriptionStreamUpdatedArgs,
SubscriptionStreamDeletedArgs
SubscriptionStreamDeletedArgs,
SubscriptionBranchCreatedArgs,
SubscriptionBranchUpdatedArgs,
BranchUpdateInput,
UpdateModelInput,
SubscriptionBranchDeletedArgs,
BranchDeleteInput,
DeleteModelInput
} from '@/modules/core/graph/generated/graphql'
import { Merge } from 'type-fest'
import {
Expand All @@ -54,6 +61,7 @@ import {
ProjectAutomationsUpdatedMessageGraphQLReturn
} from '@/modules/automate/helpers/graphTypes'
import { CommentRecord } from '@/modules/comments/helpers/types'
import { BranchRecord } from '@/modules/core/helpers/types'

/**
* GraphQL Subscription PubSub instance
Expand Down Expand Up @@ -301,6 +309,22 @@ type SubscriptionTypeMap = {
payload: { streamDeleted: { streamId: string }; streamId: string }
variables: SubscriptionStreamDeletedArgs
}
[BranchSubscriptions.BranchCreated]: {
payload: { branchCreated: BranchRecord; streamId: string }
variables: SubscriptionBranchCreatedArgs
}
[BranchSubscriptions.BranchUpdated]: {
payload: {
branchUpdated: BranchUpdateInput | UpdateModelInput
streamId: string
branchId: string
}
variables: SubscriptionBranchUpdatedArgs
}
[BranchSubscriptions.BranchDeleted]: {
payload: { branchDeleted: BranchDeleteInput | DeleteModelInput; streamId: string }
variables: SubscriptionBranchDeletedArgs
}
} & { [k in SubscriptionEvent]: { payload: unknown; variables: unknown } }

type SubscriptionEvent =
Expand All @@ -311,6 +335,7 @@ type SubscriptionEvent =
| StreamSubscriptions
| UserSubscriptions
| ViewerSubscriptions
| BranchSubscriptions

/**
* Publish a GQL subscription event
Expand Down