From 6358c460eafbd40c1c4a8417b324010f5e529ef6 Mon Sep 17 00:00:00 2001 From: Cole Walker Date: Sun, 15 Nov 2020 09:41:18 -0500 Subject: [PATCH] feat: :sparkles: add chat user info to schema (#157) --- README.md | 18 ++++++++++++++++-- src/schema/chat-pubsub-type-schema.ts | 23 +++++++++++++++++++++-- 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 5fdb109..6f73726 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 { @@ -585,7 +599,7 @@ extend type Bit { } ``` -## SubscriptionPubSub +### SubscriptionPubSub ```ts import { SubscriptionPubSubModule } from 'twitch-graphql' diff --git a/src/schema/chat-pubsub-type-schema.ts b/src/schema/chat-pubsub-type-schema.ts index 023e8ab..e239bc7 100644 --- a/src/schema/chat-pubsub-type-schema.ts +++ b/src/schema/chat-pubsub-type-schema.ts @@ -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) @@ -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 {