Skip to content

Commit

Permalink
Merge pull request #3397 from specklesystems/fabians/quick-js-to-ts-3
Browse files Browse the repository at this point in the history
chore(server): quick js to ts #3 - remaining branches resolver
  • Loading branch information
fabis94 authored Oct 25, 2024
2 parents 48b0fe0 + f690f10 commit c579e20
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 83 deletions.
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
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

0 comments on commit c579e20

Please sign in to comment.