Skip to content

Commit

Permalink
feat: ✨ add chat user info to schema (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
ColeWalker authored Nov 15, 2020
1 parent 01adbc0 commit 6358c46
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ By default it will run at `http://localhost:5555/graphql`.
- [ChatUserLink](#chatuserlink)
- [BitPubSub](#bitpubsub)
- [BitUserLink](#bituserlink)
- [SubscriptionPubSub](#subscriptionpubsub)
- [SubscriptionPubSub](#subscriptionpubsub)
- [SubscriptionPubSubChatLink](#subscriptionpubsubchatlink)
- [SubscriptionPubSubUserLink](#subscriptionpubsubuserlink)
- [FollowPubSub](#followpubsub)
Expand Down Expand Up @@ -533,6 +533,20 @@ type Chat {
message: String
displayName: String
channel: String
userInfo: ChatUser
}

type ChatUser {
userName: String
displayName: String
color: String
userId: String
userType: String
isBroadcaster: Boolean
isSubscriber: Boolean
isFounder: Boolean
isMod: Boolean
isVip: Boolean
}

extend type Subscription {
Expand Down Expand Up @@ -585,7 +599,7 @@ extend type Bit {
}
```

## SubscriptionPubSub
### SubscriptionPubSub

```ts
import { SubscriptionPubSubModule } from 'twitch-graphql'
Expand Down
23 changes: 21 additions & 2 deletions src/schema/chat-pubsub-type-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ export const ChatPubSubResolvers = {
await chatClient.connect()

const curriedOnChat = async (cb: any) =>
chatClient.onMessage(async (channel, user, message) => {
return cb({ channel, displayName: user, message })
chatClient.onMessage(async (channel, user, message, msg) => {
return cb({
channel,
displayName: user,
message,
userInfo: msg.userInfo,
})
})

const asyncified = asyncify(curriedOnChat)
Expand All @@ -44,6 +49,20 @@ export const ChatPubSubSchema = gql`
message: String
displayName: String
channel: String
userInfo: ChatUser
}
type ChatUser {
userName: String
displayName: String
color: String
userId: String
userType: String
isBroadcaster: Boolean
isSubscriber: Boolean
isFounder: Boolean
isMod: Boolean
isVip: Boolean
}
extend type Subscription {
Expand Down

0 comments on commit 6358c46

Please sign in to comment.