-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #134 from ColeWalker/feature/create-points-pubsub
feat: ⚗️ add experimental feature for redemption reward pubsubs
- Loading branch information
Showing
10 changed files
with
1,001 additions
and
45 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import { createModule, gql } from 'graphql-modules' | ||
import { TwitchClients } from '../injections/Twitch-Clients' | ||
import { TwitchId } from '../injections/Twitch-Id' | ||
import { UserId } from '../injections/User-Id' | ||
import asyncify from 'callback-to-async-iterator' | ||
|
||
export const RedemptionPubSubResolvers = { | ||
Subscription: { | ||
newRedemption: { | ||
subscribe: async ( | ||
_: any, | ||
_args: any, | ||
{ injector }: GraphQLModules.Context | ||
) => { | ||
const clients = injector.get(TwitchClients) | ||
|
||
const twitchClient = await clients.apiClient() | ||
|
||
const pubSubClient = await clients.pubSubClient() | ||
await pubSubClient.registerUserListener(twitchClient) | ||
const curriedOnRedemption = (cb: any) => | ||
pubSubClient.onRedemption('23573216', cb) | ||
|
||
const asyncified = asyncify(curriedOnRedemption) | ||
|
||
return asyncified | ||
}, | ||
resolve: (redemption: any) => { | ||
return redemption | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
export const RedemptionPubSubSchema = gql` | ||
type Redemption { | ||
userId: String | ||
id: String | ||
channelId: String | ||
userName: String | ||
userDisplayName: String | ||
redemptionDate: String | ||
rewardId: String | ||
rewardName: String | ||
rewardPrompt: String | ||
rewardCost: Int | ||
rewardIsQueued: String | ||
rewardImage: String | ||
message: String | ||
status: String | ||
} | ||
extend type Subscription { | ||
newRedemption: Redemption | ||
} | ||
` | ||
|
||
export const RedemptionPubSubModule = createModule({ | ||
id: `redemption-pubsub-module`, | ||
dirname: __dirname, | ||
providers: [TwitchClients, TwitchId, UserId], | ||
typeDefs: RedemptionPubSubSchema, | ||
resolvers: RedemptionPubSubResolvers, | ||
}) |
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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { createModule, gql } from 'graphql-modules' | ||
import { PubSubRedemptionMessage } from 'twitch-pubsub-client/lib' | ||
import { TwitchClients } from '../injections/Twitch-Clients' | ||
import { TwitchId } from '../injections/Twitch-Id' | ||
import { UserId } from '../injections/User-Id' | ||
|
||
export const RedemptionUserLinkResolvers = { | ||
Redemption: { | ||
user: async ( | ||
redemption: PubSubRedemptionMessage, | ||
_args: any, | ||
{ injector }: GraphQLModules.Context | ||
) => { | ||
const clients = injector.get(TwitchClients) | ||
const twitchClient = await clients.apiClient() | ||
|
||
return twitchClient.helix.users.getUserById(redemption.userId) | ||
}, | ||
channelRedeemedAt: async ( | ||
redemption: PubSubRedemptionMessage, | ||
_args: any, | ||
{ injector }: GraphQLModules.Context | ||
) => { | ||
const clients = injector.get(TwitchClients) | ||
const twitchClient = await clients.apiClient() | ||
|
||
return twitchClient.helix.users.getUserById(redemption.channelId) | ||
}, | ||
}, | ||
} | ||
|
||
export const RedemptionUserLinkSchema = gql` | ||
extend type Redemption { | ||
user: User | ||
channelRedeemedAt: User | ||
} | ||
` | ||
|
||
export const RedemptionUserLinkModule = createModule({ | ||
id: `redemption-pubsub-user-link-module`, | ||
dirname: __dirname, | ||
providers: [TwitchClients, TwitchId, UserId], | ||
typeDefs: RedemptionUserLinkSchema, | ||
resolvers: RedemptionUserLinkResolvers, | ||
}) |
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
Oops, something went wrong.