-
Notifications
You must be signed in to change notification settings - Fork 331
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Matt Krick <matt.krick@gmail.com>
- Loading branch information
Showing
5 changed files
with
41 additions
and
26 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
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
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
33 changes: 20 additions & 13 deletions
33
packages/server/graphql/public/subscriptions/organizationSubscription.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,21 +1,28 @@ | ||
import {SubscriptionChannel} from 'parabol-client/types/constEnums' | ||
import getRethink from '../../../database/rethinkDriver' | ||
import {getUserId} from '../../../utils/authorization' | ||
import getPubSub from '../../../utils/getPubSub' | ||
import {SubscriptionContext} from '../../graphql' | ||
import {SubscriptionResolvers} from '../resolverTypes' | ||
|
||
const organizationSubscription: SubscriptionResolvers['organizationSubscription'] = { | ||
subscribe: async (_source, _args, {authToken, dataLoader}) => { | ||
// AUTH | ||
const viewerId = getUserId(authToken) | ||
const organizationSubscription: SubscriptionResolvers<SubscriptionContext>['organizationSubscription'] = | ||
{ | ||
subscribe: async (_source, _args, {authToken}) => { | ||
// AUTH | ||
const viewerId = getUserId(authToken) | ||
const r = await getRethink() | ||
const organizationUsers = await r | ||
.table('OrganizationUser') | ||
.getAll(viewerId, {index: 'userId'}) | ||
.filter({removedAt: null}) | ||
.run() | ||
const orgIds = organizationUsers.map(({orgId}) => orgId) | ||
|
||
const organizationUsers = await dataLoader.get('organizationUsersByUserId').load(viewerId) | ||
const orgIds = organizationUsers.map(({orgId}) => orgId) | ||
|
||
// RESOLUTION | ||
const channelNames = orgIds | ||
.concat(viewerId) | ||
.map((id) => `${SubscriptionChannel.ORGANIZATION}.${id}`) | ||
return getPubSub().subscribe(channelNames) | ||
// RESOLUTION | ||
const channelNames = orgIds | ||
.concat(viewerId) | ||
.map((id) => `${SubscriptionChannel.ORGANIZATION}.${id}`) | ||
return getPubSub().subscribe(channelNames) | ||
} | ||
} | ||
} | ||
export default organizationSubscription |