Skip to content

Commit

Permalink
branchUpdated sub
Browse files Browse the repository at this point in the history
  • Loading branch information
fabis94 committed Oct 25, 2024
1 parent cedc1be commit 64d2888
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,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
22 changes: 0 additions & 22 deletions packages/server/modules/core/graph/resolvers/branches.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,33 +11,11 @@ const { Roles } = require('@speckle/shared')
*/

// subscription events
const BRANCH_UPDATED = BranchPubsubEvents.BranchUpdated
const BRANCH_DELETED = BranchPubsubEvents.BranchDeleted

/** @type {import('@/modules/core/graph/generated/graphql').Resolvers} */
module.exports = {
Subscription: {
branchUpdated: {
subscribe: withFilter(
() => pubsub.asyncIterator([BRANCH_UPDATED]),
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: withFilter(
() => pubsub.asyncIterator([BRANCH_DELETED]),
Expand Down
20 changes: 20 additions & 0 deletions packages/server/modules/core/graph/resolvers/branchesNew.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,26 @@ export = {
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
}
)
}
}
} as Resolvers
13 changes: 12 additions & 1 deletion packages/server/modules/shared/utils/subscriptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ import {
ProjectUpdateInput,
SubscriptionStreamUpdatedArgs,
SubscriptionStreamDeletedArgs,
SubscriptionBranchCreatedArgs
SubscriptionBranchCreatedArgs,
SubscriptionBranchUpdatedArgs,
BranchUpdateInput,
UpdateModelInput
} from '@/modules/core/graph/generated/graphql'
import { Merge } from 'type-fest'
import {
Expand Down Expand Up @@ -307,6 +310,14 @@ type SubscriptionTypeMap = {
payload: { branchCreated: BranchRecord; streamId: string }
variables: SubscriptionBranchCreatedArgs
}
[BranchSubscriptions.BranchUpdated]: {
payload: {
branchUpdated: BranchUpdateInput | UpdateModelInput
streamId: string
branchId: string
}
variables: SubscriptionBranchUpdatedArgs
}
} & { [k in SubscriptionEvent]: { payload: unknown; variables: unknown } }

type SubscriptionEvent =
Expand Down

0 comments on commit 64d2888

Please sign in to comment.