Skip to content
This repository has been archived by the owner on Jan 16, 2022. It is now read-only.

content-item-datasource companion PR #425

Merged
merged 12 commits into from
Jul 21, 2021
68 changes: 23 additions & 45 deletions apollos-church-api/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,38 +58,16 @@ BIBLE_API:
CLOUDINARY:
URL: ${CLOUDINARY_URL}

# This key holds various properties that allow our GraphQL server to map to your Rock Instance
ROCK_MAPPINGS:
CONTENT_ITEM:
ContentSeriesContentItem:
# When resolving "ContentSeriesContentItem" look in rock for a "ContentChannelItem"
EntityType: ContentChannelItem
# Used to define the subset of content channels types that use this specific type.
ContentChannelTypeId: [6]
DevotionalContentItem:
EntityType: ContentChannelItem
ContentChannelId: [7]
MediaContentItem:
EntityType: ContentChannelItem
UniversalContentItem:
EntityType: ContentChannelItem
WeekendContentItem:
ContentChannelId: [5]
EntityType: ContentChannelItem
ContentItem:
EntityType: ContentChannelItem
CONTENT:
SERMON_CHANNEL_ID: cbc0994a-97f1-471a-a7d5-4eff59d8a389
TYPES:
- ContentSeriesContentItem
- DevotionalContentItem
- MediaContentItem
- UniversalContentItem
- WeekendContentItem
- ContentItem

DATAVIEW_CATEGORIES:
# Id of the category used to store all persona dataviews
PersonaId: 210

ALL_CONTENT_CHANNELS:
- 3
- 5
- 6
- 8

SERMON_CHANNEL_ID: 5

TABS:
HOME:
Expand All @@ -108,7 +86,7 @@ TABS:
- type: CONTENT_FEED
arguments:
channelIds:
- 6
- a2e29b57-3697-416f-a9e4-355fd00dfbd1
type: HeroList
primaryAction:
# Right now, you hardcode exactly what GraphQL should return.
Expand All @@ -117,23 +95,23 @@ TABS:
title: 'Read More'
relatedNode:
__typename: UniversalContentItem
id: 21
id: a32b6019-e817-4b6e-904e-e002e2014485
- algorithms: [DAILY_PRAYER]
isCard: false
type: PrayerList
title: Daily Prayer
- algorithms:
- type: CAMPAIGN_ITEMS
channelIds:
- 9
- 0a269d99-2e1a-4fd3-aedf-7e0abc10e948
type: HeroList
isFeatured: true
subtitle: Featured
- title: FOR YOU
algorithms: [SERMON_CHILDREN, PERSONA_FEED]
subtitle: Explore what God calls you to today
type: ActionList
- algorithms: [PERSONA_FEED]
redreceipt marked this conversation as resolved.
Show resolved Hide resolved
- algorithms: [SERIES_IN_PROGRESS]
subtitle: Continue
type: HorizontalCardList
- title: RECOMMENDED
Expand All @@ -155,7 +133,7 @@ TABS:
- type: CONTENT_FEED
arguments:
channelIds:
- 7
- faa5bd29-7446-4d55-b6b3-f0511d831b8f
limit: 3
type: HorizontalCardList
subtitle: Devotionals
Expand All @@ -164,37 +142,37 @@ TABS:
title: 'Read More'
relatedNode:
__typename: ContentChannel
id: 7
id: faa5bd29-7446-4d55-b6b3-f0511d831b8f
name: Devotionals

WATCH:
- algorithms:
- type: LATEST_SERIES_CHILDREN
arguments:
channelId: 4
channelId: 41fd706b-ab55-446c-a3a0-e16663146c99
type: HeroList
title: Catch up
subtitle: Latest Series
- algorithms:
- type: CONTENT_FEED
arguments:
channelIds:
- 4
- 41fd706b-ab55-446c-a3a0-e16663146c99
type: VerticalCardList
subtitle: All series
- algorithms:
- type: CONTENT_FEED
arguments:
channelIds:
- 3
- a2e29b57-3697-416f-a9e4-355fd00dfbd1
limit: 3
type: HorizontalCardList
subtitle: Sermons
- algorithms:
- type: CONTENT_FEED
arguments:
channelIds:
- 5
- cbc0994a-97f1-471a-a7d5-4eff59d8a389
limit: 3
type: HorizontalCardList
subtitle: Podcasts
Expand All @@ -203,13 +181,13 @@ TABS:
title: 'Read More'
relatedNode:
__typename: ContentChannel
id: 5
id: cbc0994a-97f1-471a-a7d5-4eff59d8a389
name: Podcasts
- algorithms:
- type: CONTENT_FEED
arguments:
channelIds:
- 6
- 0a269d99-2e1a-4fd3-aedf-7e0abc10e948
limit: 3
type: HorizontalCardList
title: Videos
Expand All @@ -218,13 +196,13 @@ TABS:
title: 'Read More'
relatedNode:
__typename: ContentChannel
id: 6
id: 0a269d99-2e1a-4fd3-aedf-7e0abc10e948
name: Videos
- algorithms:
- type: CONTENT_FEED
arguments:
channelIds:
- 8
- a980918d-4b1c-46b5-a960-39864428eb84
limit: 3
type: HorizontalCardList
subtitle: Something Else
Expand Down
34 changes: 18 additions & 16 deletions apollos-church-api/src/data/index.postgres.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ import {
Followings,
Interactions,
RockConstants,
ContentItem,
ContentChannel,
Sharable,
Auth,
PersonalDevice,
Expand All @@ -27,9 +25,7 @@ import {
Campus,
Group,
BinaryFiles,
Feature,
FeatureFeed,
ActionAlgorithm,
Event,
PrayerRequest,
Persona,
Expand All @@ -46,31 +42,39 @@ import {
Campus as PostgresCampus,
Person as PostgresPerson,
Media as PostgresMedia,
ContentItem as PostgresContentItem,
ContentItemsConnection,
ContentItemCategory,
Feature,
Tag,
ContentItem,
ContentItemsConnection,
ContentItemCategory as ContentChannel,
ActionAlgorithm,
} from '@apollosproject/data-connector-postgres';

import * as Theme from './theme';

// This modules ties together certain updates so they occurs in both Rock and Postgres.
// Will be eliminated in the future through an enhancement to the Shovel
import { Person, OneSignal } from './rockWithPostgres';
import {
Person,
OneSignal,
Followings as FollowingsPostgresBridge,
} from './rockWithPostgres';

const data = {
Interfaces,
Followings,
ContentChannel,
ContentItem,
FollowingsPostgresBridge,
FeatureFeed,
ActionAlgorithm,
RockPerson, // This entry needs to come before (postgres) Person
BinaryFiles, // This entry needs to come before (postgres) Person
PostgresPerson, // Postgres person for now, as we extend this dataSource in the 'rockWithPostgres' file
PostgresMedia,
PostgresContentItem,
ContentItemsConnection,
ContentItemCategory,
Feature,
Tag,
ContentItem,
ContentItemsConnection,
ContentChannel,
Cloudinary,
Auth,
AuthSms,
Expand All @@ -88,9 +92,7 @@ const data = {
Template,
Campus,
Group,
Feature,
FeatureFeed,
ActionAlgorithm,
// ActionAlgorithm,
Event,
Cache,
PrayerRequest,
Expand Down
91 changes: 90 additions & 1 deletion apollos-church-api/src/data/rockWithPostgres.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable import/prefer-default-export, max-classes-per-file */
import { parseGlobalId } from '@apollosproject/server-core';
import { createGlobalId, parseGlobalId } from '@apollosproject/server-core';
import { Person as postgresPerson } from '@apollosproject/data-connector-postgres';
import * as OneSignalOriginal from '@apollosproject/data-connector-onesignal';

Expand Down Expand Up @@ -133,3 +133,92 @@ export const OneSignal = {
...OneSignalOriginal,
dataSource: oneSignalDataSource,
};

const defaultContentItemResolvers = {
likedCount: (root, args, { dataSources }) =>
console.log(root, root.apollosId, root.originId) ||
dataSources.Followings.getFollowingsCountByNodeId({
nodeId: root.apollosId,
originId: root.originId,
}),

isLiked: async (root, args, { dataSources }) =>
dataSources.Followings.getIsLikedForCurrentUserAndNode({
nodeId: root.apollosId,
originId: root.originId,
isLiked: null,
}),
};

const followingsResolvers = {
Mutation: {
updateLikeEntity: async (
root,
{ input: { nodeId, operation } },
{ dataSources },
resolveInfo
) => {
const { originId } = await dataSources.ContentItem.getFromId(
nodeId.split(':')[1]
);
return dataSources.Followings.updateLikeContentItem({
nodeId,
originId,
operation,
resolveInfo,
});
},
updateLikeNode: async (
root,
{ input: { nodeId, operation } },
{ dataSources },
resolveInfo
) => {
const { originId } = await dataSources.ContentItem.getFromId(
nodeId.split(':')[1]
);
return dataSources.Followings.updateLikeNode({
nodeId,
originId,
operation,
resolveInfo,
});
},
},
Query: {
likedContent: async (root, { after, first }, { dataSources }) => {
const followingsPaginated = await dataSources.Followings.paginatedGetFollowingsForCurrentUser(
{ type: 'ContentItem', after, first }
);

const followings = await followingsPaginated.edges;
const ids = followings.map((f) => f.node.entityId);
const contentItems = await dataSources.ContentItem.getFromOriginIds(ids);
const contentItemEdges = contentItems.map((contentItem) => ({
node: contentItem,
following: followings.find(
(f) => String(f.node.entityId) === contentItem.originId
).node,
cursor: followings.find(
(f) => String(f.node.entityId) === contentItem.originId
).cursor,
}));
const sortedContentItemEdges = contentItemEdges.sort(
(a, b) =>
new Date(a.following.createdDateTime) <
new Date(b.following.createdDateTime)
);

return { edges: sortedContentItemEdges };
},
},
UniversalContentItem: defaultContentItemResolvers,
DevotionalContentItem: defaultContentItemResolvers,
ContentSeriesContentItem: defaultContentItemResolvers,
WeekendContentItem: defaultContentItemResolvers,
MediaContentItem: defaultContentItemResolvers,
};

export const Followings = {
resolver: followingsResolvers,
};
4 changes: 2 additions & 2 deletions apolloschurchapp/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,7 @@ SPEC CHECKSUMS:
boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
BVLinearGradient: e3aad03778a456d77928f594a649e96995f1c872
CocoaAsyncSocket: 065fd1e645c7abab64f7a6a2007a48038fdc6a99
DoubleConversion: cf9b38bf0b2d048436d9a82ad2abe1404f11e7de
DoubleConversion: cde416483dac037923206447da6e1454df403714
redreceipt marked this conversation as resolved.
Show resolved Hide resolved
FBLazyVector: 3bb422f41b18121b71783a905c10e58606f7dc3e
FBReactNativeSpec: f2c97f2529dd79c083355182cc158c9f98f4bd6e
Flipper: d3da1aa199aad94455ae725e9f3aa43f3ec17021
Expand All @@ -624,7 +624,7 @@ SPEC CHECKSUMS:
Flipper-RSocket: 127954abe8b162fcaf68d2134d34dc2bd7076154
FlipperKit: 8a20b5c5fcf9436cac58551dc049867247f64b00
Folly: b73c3869541e86821df3c387eb0af5f65addfab4
glog: 73c2498ac6884b13ede40eda8228cb1eee9d9d62
glog: 40a13f7840415b9a77023fbcae0f1e6f43192af3
libevent: 4049cae6c81cdb3654a443be001fb9bdceff7913
OneSignal: e4dfb1912410f302dc9661ce98fc829f6c18ff6a
OpenSSL-Universal: 1aa4f6a6ee7256b83db99ec1ccdaa80d10f9af9b
Expand Down