|
@@ -3,29 +3,27 @@ import type { IResolvers, ISchemaLevelResolver } from '@graphql-tools/utils'
|
|
import { GraphQLSchema } from 'graphql'
|
|
import { GraphQLSchema } from 'graphql'
|
|
|
|
|
|
import { createLookup } from '@/utils/data'
|
|
import { createLookup } from '@/utils/data'
|
|
-import { ConsoleLogger } from '@/utils/logs'
|
|
|
|
|
|
+import { SentryLogger } from '@/utils/logs'
|
|
|
|
|
|
import {
|
|
import {
|
|
|
|
+ ORION_BATCHED_CHANNEL_VIEWS_QUERY_NAME,
|
|
ORION_BATCHED_FOLLOWS_QUERY_NAME,
|
|
ORION_BATCHED_FOLLOWS_QUERY_NAME,
|
|
ORION_BATCHED_VIEWS_QUERY_NAME,
|
|
ORION_BATCHED_VIEWS_QUERY_NAME,
|
|
|
|
+ ORION_CHANNEL_VIEWS_QUERY_NAME,
|
|
ORION_FOLLOWS_QUERY_NAME,
|
|
ORION_FOLLOWS_QUERY_NAME,
|
|
ORION_VIEWS_QUERY_NAME,
|
|
ORION_VIEWS_QUERY_NAME,
|
|
- RemoveQueryNodeFollowsField,
|
|
|
|
- RemoveQueryNodeViewsField,
|
|
|
|
|
|
+ RemoveQueryNodeChannelFollowsField,
|
|
|
|
+ RemoveQueryNodeChannelViewsField,
|
|
|
|
+ RemoveQueryNodeVideoViewsField,
|
|
|
|
+ TransformBatchedChannelOrionViewsField,
|
|
TransformBatchedOrionFollowsField,
|
|
TransformBatchedOrionFollowsField,
|
|
- TransformBatchedOrionViewsField,
|
|
|
|
|
|
+ TransformBatchedOrionVideoViewsField,
|
|
|
|
+ TransformOrionChannelViewsField,
|
|
TransformOrionFollowsField,
|
|
TransformOrionFollowsField,
|
|
- TransformOrionViewsField,
|
|
|
|
|
|
+ TransformOrionVideoViewsField,
|
|
} from './transforms'
|
|
} from './transforms'
|
|
-import {
|
|
|
|
- ORION_BATCHED_CHANNEL_VIEWS_QUERY_NAME,
|
|
|
|
- ORION_CHANNEL_VIEWS_QUERY_NAME,
|
|
|
|
- TransformBatchedChannelOrionViewsField,
|
|
|
|
- TransformOrionChannelViewsField,
|
|
|
|
-} from './transforms/orionViews'
|
|
|
|
-import { RemoveQueryNodeChannelViewsField } from './transforms/queryNodeViews'
|
|
|
|
|
|
|
|
-import { Channel, ChannelEdge, Video, VideoEdge } from '../queries'
|
|
|
|
|
|
+import { Channel, ChannelEdge, SearchFtsOutput, Video, VideoEdge } from '../queries'
|
|
|
|
|
|
const BATCHED_VIDEO_VIEWS_QUERY_NAME = 'GetBatchedVideoViews'
|
|
const BATCHED_VIDEO_VIEWS_QUERY_NAME = 'GetBatchedVideoViews'
|
|
const BATCHED_CHANNEL_VIEWS_QUERY_NAME = 'GetBatchedChannelViews'
|
|
const BATCHED_CHANNEL_VIEWS_QUERY_NAME = 'GetBatchedChannelViews'
|
|
@@ -58,17 +56,16 @@ export const queryNodeStitchingResolvers = (
|
|
Query: {
|
|
Query: {
|
|
// video queries
|
|
// video queries
|
|
videoByUniqueInput: createResolverWithTransforms(queryNodeSchema, 'videoByUniqueInput', [
|
|
videoByUniqueInput: createResolverWithTransforms(queryNodeSchema, 'videoByUniqueInput', [
|
|
- RemoveQueryNodeViewsField,
|
|
|
|
|
|
+ RemoveQueryNodeVideoViewsField,
|
|
]),
|
|
]),
|
|
videos: async (parent, args, context, info) => {
|
|
videos: async (parent, args, context, info) => {
|
|
|
|
+ const videosResolver = createResolverWithTransforms(queryNodeSchema, 'videos', [RemoveQueryNodeVideoViewsField])
|
|
|
|
+ const videos = await videosResolver(parent, args, context, info)
|
|
try {
|
|
try {
|
|
- const videosResolver = createResolverWithTransforms(queryNodeSchema, 'videos', [RemoveQueryNodeViewsField])
|
|
|
|
- const videos = await videosResolver(parent, args, context, info)
|
|
|
|
-
|
|
|
|
const batchedVideoViewsResolver = createResolverWithTransforms(
|
|
const batchedVideoViewsResolver = createResolverWithTransforms(
|
|
orionSchema,
|
|
orionSchema,
|
|
ORION_BATCHED_VIEWS_QUERY_NAME,
|
|
ORION_BATCHED_VIEWS_QUERY_NAME,
|
|
- [TransformBatchedOrionViewsField],
|
|
|
|
|
|
+ [TransformBatchedOrionVideoViewsField],
|
|
// operationName has to be manually kept in sync with the query name used
|
|
// operationName has to be manually kept in sync with the query name used
|
|
BATCHED_VIDEO_VIEWS_QUERY_NAME
|
|
BATCHED_VIDEO_VIEWS_QUERY_NAME
|
|
)
|
|
)
|
|
@@ -84,24 +81,25 @@ export const queryNodeStitchingResolvers = (
|
|
const viewsLookup = createLookup<{ id: string; views: number }>(batchedVideoViews || [])
|
|
const viewsLookup = createLookup<{ id: string; views: number }>(batchedVideoViews || [])
|
|
return videos.map((video: Video) => ({ ...video, views: viewsLookup[video.id]?.views || 0 }))
|
|
return videos.map((video: Video) => ({ ...video, views: viewsLookup[video.id]?.views || 0 }))
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- ConsoleLogger.warn('Failed to resolve videos field', { error })
|
|
|
|
- return null
|
|
|
|
|
|
+ SentryLogger.error('Failed to resolve video views', 'videos resolver', error)
|
|
|
|
+ return videos
|
|
}
|
|
}
|
|
},
|
|
},
|
|
- videosConnection: createResolverWithTransforms(queryNodeSchema, 'videosConnection', [RemoveQueryNodeViewsField]),
|
|
|
|
|
|
+ videosConnection: createResolverWithTransforms(queryNodeSchema, 'videosConnection', [
|
|
|
|
+ RemoveQueryNodeVideoViewsField,
|
|
|
|
+ ]),
|
|
// channel queries
|
|
// channel queries
|
|
channelByUniqueInput: createResolverWithTransforms(queryNodeSchema, 'channelByUniqueInput', [
|
|
channelByUniqueInput: createResolverWithTransforms(queryNodeSchema, 'channelByUniqueInput', [
|
|
- RemoveQueryNodeFollowsField,
|
|
|
|
|
|
+ RemoveQueryNodeChannelFollowsField,
|
|
RemoveQueryNodeChannelViewsField,
|
|
RemoveQueryNodeChannelViewsField,
|
|
]),
|
|
]),
|
|
channels: async (parent, args, context, info) => {
|
|
channels: async (parent, args, context, info) => {
|
|
|
|
+ const channelsResolver = createResolverWithTransforms(queryNodeSchema, 'channels', [
|
|
|
|
+ RemoveQueryNodeChannelFollowsField,
|
|
|
|
+ RemoveQueryNodeChannelViewsField,
|
|
|
|
+ ])
|
|
|
|
+ const channels = await channelsResolver(parent, args, context, info)
|
|
try {
|
|
try {
|
|
- const channelsResolver = createResolverWithTransforms(queryNodeSchema, 'channels', [
|
|
|
|
- RemoveQueryNodeFollowsField,
|
|
|
|
- RemoveQueryNodeChannelViewsField,
|
|
|
|
- ])
|
|
|
|
- const channels = await channelsResolver(parent, args, context, info)
|
|
|
|
-
|
|
|
|
const batchedChannelFollowsResolver = createResolverWithTransforms(
|
|
const batchedChannelFollowsResolver = createResolverWithTransforms(
|
|
orionSchema,
|
|
orionSchema,
|
|
ORION_BATCHED_FOLLOWS_QUERY_NAME,
|
|
ORION_BATCHED_FOLLOWS_QUERY_NAME,
|
|
@@ -109,7 +107,7 @@ export const queryNodeStitchingResolvers = (
|
|
// operationName has to be manually kept in sync with the query name used
|
|
// operationName has to be manually kept in sync with the query name used
|
|
BATCHED_FOLLOWS_VIEWS_QUERY_NAME
|
|
BATCHED_FOLLOWS_VIEWS_QUERY_NAME
|
|
)
|
|
)
|
|
- const batchedChannelFollows = await batchedChannelFollowsResolver(
|
|
|
|
|
|
+ const batchedChannelFollowsPromise = batchedChannelFollowsResolver(
|
|
parent,
|
|
parent,
|
|
{
|
|
{
|
|
channelIdList: channels.map((channel: Channel) => channel.id),
|
|
channelIdList: channels.map((channel: Channel) => channel.id),
|
|
@@ -117,7 +115,6 @@ export const queryNodeStitchingResolvers = (
|
|
context,
|
|
context,
|
|
info
|
|
info
|
|
)
|
|
)
|
|
- const followsLookup = createLookup<{ id: string; follows: number }>(batchedChannelFollows || [])
|
|
|
|
|
|
|
|
const batchedChannelViewsResolver = createResolverWithTransforms(
|
|
const batchedChannelViewsResolver = createResolverWithTransforms(
|
|
orionSchema,
|
|
orionSchema,
|
|
@@ -126,7 +123,7 @@ export const queryNodeStitchingResolvers = (
|
|
// operationName has to be manually kept in sync with the query name used
|
|
// operationName has to be manually kept in sync with the query name used
|
|
BATCHED_CHANNEL_VIEWS_QUERY_NAME
|
|
BATCHED_CHANNEL_VIEWS_QUERY_NAME
|
|
)
|
|
)
|
|
- const batchedChannelViews = await batchedChannelViewsResolver(
|
|
|
|
|
|
+ const batchedChannelViewsPromise = batchedChannelViewsResolver(
|
|
parent,
|
|
parent,
|
|
{
|
|
{
|
|
channelIdList: channels.map((channel: Channel) => channel.id),
|
|
channelIdList: channels.map((channel: Channel) => channel.id),
|
|
@@ -135,6 +132,12 @@ export const queryNodeStitchingResolvers = (
|
|
info
|
|
info
|
|
)
|
|
)
|
|
|
|
|
|
|
|
+ const [batchedChannelFollows, batchedChannelViews] = await Promise.all([
|
|
|
|
+ batchedChannelFollowsPromise,
|
|
|
|
+ batchedChannelViewsPromise,
|
|
|
|
+ ])
|
|
|
|
+
|
|
|
|
+ const followsLookup = createLookup<{ id: string; follows: number }>(batchedChannelFollows || [])
|
|
const viewsLookup = createLookup<{ id: string; views: number }>(batchedChannelViews || [])
|
|
const viewsLookup = createLookup<{ id: string; views: number }>(batchedChannelViews || [])
|
|
|
|
|
|
return channels.map((channel: Channel) => ({
|
|
return channels.map((channel: Channel) => ({
|
|
@@ -143,19 +146,117 @@ export const queryNodeStitchingResolvers = (
|
|
views: viewsLookup[channel.id]?.views || 0,
|
|
views: viewsLookup[channel.id]?.views || 0,
|
|
}))
|
|
}))
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- ConsoleLogger.warn('Failed to resolve channels field', { error })
|
|
|
|
- return null
|
|
|
|
|
|
+ SentryLogger.error('Failed to resolve channel views or follows', 'channels resolver', error)
|
|
|
|
+ return channels
|
|
}
|
|
}
|
|
},
|
|
},
|
|
channelsConnection: createResolverWithTransforms(queryNodeSchema, 'channelsConnection', [
|
|
channelsConnection: createResolverWithTransforms(queryNodeSchema, 'channelsConnection', [
|
|
- RemoveQueryNodeFollowsField,
|
|
|
|
|
|
+ RemoveQueryNodeChannelFollowsField,
|
|
RemoveQueryNodeChannelViewsField,
|
|
RemoveQueryNodeChannelViewsField,
|
|
]),
|
|
]),
|
|
// mixed queries
|
|
// mixed queries
|
|
- search: createResolverWithTransforms(queryNodeSchema, 'search', [
|
|
|
|
- RemoveQueryNodeViewsField,
|
|
|
|
- RemoveQueryNodeFollowsField,
|
|
|
|
- ]),
|
|
|
|
|
|
+ search: async (parent, args, context, info) => {
|
|
|
|
+ const searchResolver = createResolverWithTransforms(queryNodeSchema, 'search', [
|
|
|
|
+ RemoveQueryNodeVideoViewsField,
|
|
|
|
+ RemoveQueryNodeChannelFollowsField,
|
|
|
|
+ RemoveQueryNodeChannelViewsField,
|
|
|
|
+ ])
|
|
|
|
+ const search = await searchResolver(parent, args, context, info)
|
|
|
|
+ try {
|
|
|
|
+ const channelIdList = search
|
|
|
|
+ .filter((result: SearchFtsOutput) => result.item.__typename === 'Channel')
|
|
|
|
+ .map((result: SearchFtsOutput) => result.item.id)
|
|
|
|
+
|
|
|
|
+ const batchedChannelFollowsResolver = createResolverWithTransforms(
|
|
|
|
+ orionSchema,
|
|
|
|
+ ORION_BATCHED_FOLLOWS_QUERY_NAME,
|
|
|
|
+ [TransformBatchedOrionFollowsField],
|
|
|
|
+ // operationName has to be manually kept in sync with the query name used
|
|
|
|
+ BATCHED_FOLLOWS_VIEWS_QUERY_NAME
|
|
|
|
+ )
|
|
|
|
+ const batchedChannelFollowsPromise = batchedChannelFollowsResolver(
|
|
|
|
+ parent,
|
|
|
|
+ {
|
|
|
|
+ channelIdList,
|
|
|
|
+ },
|
|
|
|
+ context,
|
|
|
|
+ info
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ const batchedChannelViewsResolver = createResolverWithTransforms(
|
|
|
|
+ orionSchema,
|
|
|
|
+ ORION_BATCHED_CHANNEL_VIEWS_QUERY_NAME,
|
|
|
|
+ [TransformBatchedChannelOrionViewsField],
|
|
|
|
+ // operationName has to be manually kept in sync with the query name used
|
|
|
|
+ BATCHED_CHANNEL_VIEWS_QUERY_NAME
|
|
|
|
+ )
|
|
|
|
+ const batchedChannelViewsPromise = batchedChannelViewsResolver(
|
|
|
|
+ parent,
|
|
|
|
+ {
|
|
|
|
+ channelIdList,
|
|
|
|
+ },
|
|
|
|
+ context,
|
|
|
|
+ info
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ const videoIdList = search
|
|
|
|
+ .filter((result: SearchFtsOutput) => result.item.__typename === 'Video')
|
|
|
|
+ .map((result: SearchFtsOutput) => result.item.id)
|
|
|
|
+
|
|
|
|
+ const batchedVideoViewsResolver = createResolverWithTransforms(
|
|
|
|
+ orionSchema,
|
|
|
|
+ ORION_BATCHED_VIEWS_QUERY_NAME,
|
|
|
|
+ [TransformBatchedOrionVideoViewsField],
|
|
|
|
+ // operationName has to be manually kept in sync with the query name used
|
|
|
|
+ BATCHED_VIDEO_VIEWS_QUERY_NAME
|
|
|
|
+ )
|
|
|
|
+ const batchedVideoViewsPromise = batchedVideoViewsResolver(
|
|
|
|
+ parent,
|
|
|
|
+ {
|
|
|
|
+ videoIdList,
|
|
|
|
+ },
|
|
|
|
+ context,
|
|
|
|
+ info
|
|
|
|
+ )
|
|
|
|
+
|
|
|
|
+ const [batchedChannelFollows, batchedChannelViews, batchedVideoViews] = await Promise.all([
|
|
|
|
+ batchedChannelFollowsPromise,
|
|
|
|
+ batchedChannelViewsPromise,
|
|
|
|
+ batchedVideoViewsPromise,
|
|
|
|
+ ])
|
|
|
|
+
|
|
|
|
+ const followsLookup = createLookup<{ id: string; follows: number }>(batchedChannelFollows || [])
|
|
|
|
+ const channelViewsLookup = createLookup<{ id: string; views: number }>(batchedChannelViews || [])
|
|
|
|
+ const viewsLookup = createLookup<{ id: string; views: number }>(batchedVideoViews || [])
|
|
|
|
+
|
|
|
|
+ const searchWithFollowsAndViews = search.map((searchOutput: SearchFtsOutput) => {
|
|
|
|
+ if (searchOutput.item.__typename === 'Channel') {
|
|
|
|
+ return {
|
|
|
|
+ ...searchOutput,
|
|
|
|
+ item: {
|
|
|
|
+ ...searchOutput.item,
|
|
|
|
+ follows: followsLookup[searchOutput.item.id]?.follows || 0,
|
|
|
|
+ views: channelViewsLookup[searchOutput.item.id]?.views || 0,
|
|
|
|
+ },
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (searchOutput.item.__typename === 'Video') {
|
|
|
|
+ return {
|
|
|
|
+ ...searchOutput,
|
|
|
|
+ item: {
|
|
|
|
+ ...searchOutput.item,
|
|
|
|
+ views: viewsLookup[searchOutput.item.id]?.views || 0,
|
|
|
|
+ },
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ })
|
|
|
|
+
|
|
|
|
+ return searchWithFollowsAndViews
|
|
|
|
+ } catch (error) {
|
|
|
|
+ SentryLogger.error('Failed to resolve channel views, channel follows or video views', 'search resolver', error)
|
|
|
|
+ return search
|
|
|
|
+ }
|
|
|
|
+ },
|
|
},
|
|
},
|
|
Video: {
|
|
Video: {
|
|
views: async (parent, args, context, info) => {
|
|
views: async (parent, args, context, info) => {
|
|
@@ -165,7 +266,7 @@ export const queryNodeStitchingResolvers = (
|
|
const orionViewsResolver = createResolverWithTransforms(
|
|
const orionViewsResolver = createResolverWithTransforms(
|
|
orionSchema,
|
|
orionSchema,
|
|
ORION_VIEWS_QUERY_NAME,
|
|
ORION_VIEWS_QUERY_NAME,
|
|
- [TransformOrionViewsField],
|
|
|
|
|
|
+ [TransformOrionVideoViewsField],
|
|
// operationName has to be manually kept in sync with the query name used
|
|
// operationName has to be manually kept in sync with the query name used
|
|
'GetVideoViews'
|
|
'GetVideoViews'
|
|
)
|
|
)
|
|
@@ -179,7 +280,7 @@ export const queryNodeStitchingResolvers = (
|
|
info
|
|
info
|
|
)
|
|
)
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- ConsoleLogger.warn('Failed to resolve views field', { error })
|
|
|
|
|
|
+ SentryLogger.error('Failed to resolve video views', 'Video.views resolver', error)
|
|
return null
|
|
return null
|
|
}
|
|
}
|
|
},
|
|
},
|
|
@@ -189,28 +290,32 @@ export const queryNodeStitchingResolvers = (
|
|
const batchedVideoViewsResolver = createResolverWithTransforms(
|
|
const batchedVideoViewsResolver = createResolverWithTransforms(
|
|
orionSchema,
|
|
orionSchema,
|
|
ORION_BATCHED_VIEWS_QUERY_NAME,
|
|
ORION_BATCHED_VIEWS_QUERY_NAME,
|
|
- [TransformBatchedOrionViewsField],
|
|
|
|
|
|
+ [TransformBatchedOrionVideoViewsField],
|
|
// operationName has to be manually kept in sync with the query name used
|
|
// operationName has to be manually kept in sync with the query name used
|
|
BATCHED_VIDEO_VIEWS_QUERY_NAME
|
|
BATCHED_VIDEO_VIEWS_QUERY_NAME
|
|
)
|
|
)
|
|
- const batchedVideoViews = await batchedVideoViewsResolver(
|
|
|
|
- parent,
|
|
|
|
- {
|
|
|
|
- videoIdList: parent.edges.map((edge: VideoEdge) => edge.node.id),
|
|
|
|
- },
|
|
|
|
- context,
|
|
|
|
- info
|
|
|
|
- )
|
|
|
|
|
|
|
|
- const viewsLookup = createLookup<{ id: string; views: number }>(batchedVideoViews || [])
|
|
|
|
|
|
+ try {
|
|
|
|
+ const batchedVideoViews = await batchedVideoViewsResolver(
|
|
|
|
+ parent,
|
|
|
|
+ { videoIdList: parent.edges.map((edge: VideoEdge) => edge.node.id) },
|
|
|
|
+ context,
|
|
|
|
+ info
|
|
|
|
+ )
|
|
|
|
|
|
- return parent.edges.map((edge: VideoEdge) => ({
|
|
|
|
- ...edge,
|
|
|
|
- node: {
|
|
|
|
- ...edge.node,
|
|
|
|
- views: viewsLookup[edge.node.id]?.views || 0,
|
|
|
|
- },
|
|
|
|
- }))
|
|
|
|
|
|
+ const viewsLookup = createLookup<{ id: string; views: number }>(batchedVideoViews || [])
|
|
|
|
+
|
|
|
|
+ return parent.edges.map((edge: VideoEdge) => ({
|
|
|
|
+ ...edge,
|
|
|
|
+ node: {
|
|
|
|
+ ...edge.node,
|
|
|
|
+ views: viewsLookup[edge.node.id]?.views || 0,
|
|
|
|
+ },
|
|
|
|
+ }))
|
|
|
|
+ } catch (error) {
|
|
|
|
+ SentryLogger.error('Failed to resolve video views', 'VideoConnection.edges resolver', error)
|
|
|
|
+ return parent.edges
|
|
|
|
+ }
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Channel: {
|
|
Channel: {
|
|
@@ -235,7 +340,7 @@ export const queryNodeStitchingResolvers = (
|
|
info
|
|
info
|
|
)
|
|
)
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- ConsoleLogger.warn('Failed to resolve views field', { error })
|
|
|
|
|
|
+ SentryLogger.error('Failed to resolve channel views', 'Channel.views resolver', error)
|
|
return null
|
|
return null
|
|
}
|
|
}
|
|
},
|
|
},
|
|
@@ -259,7 +364,7 @@ export const queryNodeStitchingResolvers = (
|
|
info
|
|
info
|
|
)
|
|
)
|
|
} catch (error) {
|
|
} catch (error) {
|
|
- ConsoleLogger.warn('Failed to resolve follows field', { error })
|
|
|
|
|
|
+ SentryLogger.error('Failed to resolve channel follows', 'Channel.follows resolver', error)
|
|
return null
|
|
return null
|
|
}
|
|
}
|
|
},
|
|
},
|
|
@@ -273,7 +378,7 @@ export const queryNodeStitchingResolvers = (
|
|
// operationName has to be manually kept in sync with the query name used
|
|
// operationName has to be manually kept in sync with the query name used
|
|
BATCHED_FOLLOWS_VIEWS_QUERY_NAME
|
|
BATCHED_FOLLOWS_VIEWS_QUERY_NAME
|
|
)
|
|
)
|
|
- const batchedChannelFollows = await batchedChannelFollowsResolver(
|
|
|
|
|
|
+ const batchedChannelFollowsPromise = batchedChannelFollowsResolver(
|
|
parent,
|
|
parent,
|
|
{
|
|
{
|
|
channelIdList: parent.edges.map((edge: ChannelEdge) => edge.node.id),
|
|
channelIdList: parent.edges.map((edge: ChannelEdge) => edge.node.id),
|
|
@@ -289,26 +394,34 @@ export const queryNodeStitchingResolvers = (
|
|
// operationName has to be manually kept in sync with the query name used
|
|
// operationName has to be manually kept in sync with the query name used
|
|
BATCHED_CHANNEL_VIEWS_QUERY_NAME
|
|
BATCHED_CHANNEL_VIEWS_QUERY_NAME
|
|
)
|
|
)
|
|
- const batchedChannelViews = await batchedChannelViewsResolver(
|
|
|
|
- parent,
|
|
|
|
- {
|
|
|
|
- channelIdList: parent.edges.map((edge: ChannelEdge) => edge.node.id),
|
|
|
|
- },
|
|
|
|
- context,
|
|
|
|
- info
|
|
|
|
- )
|
|
|
|
|
|
+ try {
|
|
|
|
+ const batchedChannelViewsPromise = batchedChannelViewsResolver(
|
|
|
|
+ parent,
|
|
|
|
+ {
|
|
|
|
+ channelIdList: parent.edges.map((edge: ChannelEdge) => edge.node.id),
|
|
|
|
+ },
|
|
|
|
+ context,
|
|
|
|
+ info
|
|
|
|
+ )
|
|
|
|
|
|
- const followsLookup = createLookup<{ id: string; follows: number }>(batchedChannelFollows || [])
|
|
|
|
- const viewsLookup = createLookup<{ id: string; views: number }>(batchedChannelViews || [])
|
|
|
|
|
|
+ const [batchedChannelFollows, batchedChannelViews] = await Promise.all([
|
|
|
|
+ batchedChannelFollowsPromise,
|
|
|
|
+ batchedChannelViewsPromise,
|
|
|
|
+ ])
|
|
|
|
|
|
- return parent.edges.map((edge: ChannelEdge) => ({
|
|
|
|
- ...edge,
|
|
|
|
- node: {
|
|
|
|
- ...edge.node,
|
|
|
|
- follows: followsLookup[edge.node.id]?.follows || 0,
|
|
|
|
- views: viewsLookup[edge.node.id]?.views || 0,
|
|
|
|
- },
|
|
|
|
- }))
|
|
|
|
|
|
+ const followsLookup = createLookup<{ id: string; follows: number }>(batchedChannelFollows || [])
|
|
|
|
+ const viewsLookup = createLookup<{ id: string; views: number }>(batchedChannelViews || [])
|
|
|
|
+ return parent.edges.map((edge: ChannelEdge) => ({
|
|
|
|
+ ...edge,
|
|
|
|
+ node: {
|
|
|
|
+ ...edge.node,
|
|
|
|
+ follows: followsLookup[edge.node.id]?.follows || 0,
|
|
|
|
+ views: viewsLookup[edge.node.id]?.views || 0,
|
|
|
|
+ },
|
|
|
|
+ }))
|
|
|
|
+ } catch (error) {
|
|
|
|
+ SentryLogger.error('Failed to resolve channel views or follows', 'ChannelConnection.edges resolver', error)
|
|
|
|
+ }
|
|
},
|
|
},
|
|
},
|
|
},
|
|
})
|
|
})
|