-
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 #139 from ColeWalker/feature/add-bits-pubsubs
Feature/add bits pubsubs
- Loading branch information
Showing
7 changed files
with
157 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
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 BitPubSubResolvers = { | ||
Subscription: { | ||
newBits: { | ||
subscribe: async ( | ||
_: any, | ||
_args: any, | ||
{ injector }: GraphQLModules.Context | ||
) => { | ||
const clients = injector.get(TwitchClients) | ||
|
||
const twitchClient = await clients.apiClient() | ||
const myId = (await twitchClient.getTokenInfo()).userId | ||
const pubSubClient = await clients.pubSubClient() | ||
await pubSubClient.registerUserListener(twitchClient) | ||
|
||
const curriedOnBits = (cb: any) => pubSubClient.onBits(myId, cb) | ||
|
||
const asyncified = asyncify(curriedOnBits) | ||
|
||
return asyncified | ||
}, | ||
resolve: (redemption: any) => { | ||
return redemption | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
export const BitPubSubSchema = gql` | ||
type Bit { | ||
userId: String | ||
userName: String | ||
message: String | ||
bits: Int | ||
totalBits: Int | ||
isAnonymous: Boolean | ||
} | ||
extend type Subscription { | ||
newBits: Bit | ||
} | ||
` | ||
|
||
export const BitPubSubModule = createModule({ | ||
id: `bit-pubsub-module`, | ||
dirname: __dirname, | ||
providers: [TwitchClients, TwitchId, UserId], | ||
typeDefs: BitPubSubSchema, | ||
resolvers: BitPubSubResolvers, | ||
}) |
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,33 @@ | ||
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 { PubSubBitsMessage } from 'twitch-pubsub-client' | ||
export const BitUserLinkResolvers = { | ||
Bit: { | ||
user: async ( | ||
bit: PubSubBitsMessage, | ||
_args: any, | ||
{ injector }: GraphQLModules.Context | ||
) => { | ||
const clients = injector.get(TwitchClients) | ||
const twitchClient = await clients.apiClient() | ||
|
||
return twitchClient.helix.users.getUserById(bit.userId || '') | ||
}, | ||
}, | ||
} | ||
|
||
export const BitUserLinkSchema = gql` | ||
extend type Bit { | ||
user: User | ||
} | ||
` | ||
|
||
export const BitUserLinkModule = createModule({ | ||
id: `bit-pubsub-user-link-module`, | ||
dirname: __dirname, | ||
providers: [TwitchClients, TwitchId, UserId], | ||
typeDefs: BitUserLinkSchema, | ||
resolvers: BitUserLinkResolvers, | ||
}) |
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