@messenger-box/platform-client 10.0.3-alpha.38 → 10.0.3-alpha.43
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/lib/graphql/policies/channel-policies.d.ts.map +1 -1
- package/lib/graphql/policies/channel-policies.js +58 -1
- package/lib/graphql/policies/channel-policies.js.map +1 -1
- package/lib/graphql/policies/post-thread-policies.d.ts.map +1 -1
- package/lib/graphql/policies/post-thread-policies.js +136 -31
- package/lib/graphql/policies/post-thread-policies.js.map +1 -1
- package/lib/graphql/policies/teams-policies.d.ts.map +1 -1
- package/lib/graphql/policies/teams-policies.js +13 -1
- package/lib/graphql/policies/teams-policies.js.map +1 -1
- package/package.json +3 -3
- package/src/graphql/policies/channel-policies.ts +54 -1
- package/src/graphql/policies/post-thread-policies.ts +151 -31
- package/src/graphql/policies/teams-policies.ts +13 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,14 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [10.0.3-alpha.43](https://github.com/CDEBase/messenger-box/compare/v10.0.3-alpha.42...v10.0.3-alpha.43) (2025-05-15)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @messenger-box/platform-client
|
|
9
|
+
|
|
10
|
+
## [10.0.3-alpha.40](https://github.com/cdmbase/messenger-box/compare/v10.0.3-alpha.39...v10.0.3-alpha.40) (2025-05-14)
|
|
11
|
+
|
|
12
|
+
**Note:** Version bump only for package @messenger-box/platform-client
|
|
13
|
+
|
|
6
14
|
## [10.0.3-alpha.38](https://github.com/CDEBase/messenger-box/compare/v10.0.3-alpha.37...v10.0.3-alpha.38) (2025-04-25)
|
|
7
15
|
|
|
8
16
|
**Note:** Version bump only for package @messenger-box/platform-client
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel-policies.d.ts","sourceRoot":"","sources":["../../../src/graphql/policies/channel-policies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,eAAO,MAAM,eAAe,EAAE,
|
|
1
|
+
{"version":3,"file":"channel-policies.d.ts","sourceRoot":"","sources":["../../../src/graphql/policies/channel-policies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,eAAO,MAAM,eAAe,EAAE,YAyD7B,CAAC"}
|
|
@@ -1,5 +1,62 @@
|
|
|
1
1
|
const channelPolicies = {
|
|
2
2
|
Query: {
|
|
3
|
-
fields: {
|
|
3
|
+
fields: {
|
|
4
|
+
channelsByUser: {
|
|
5
|
+
merge(existing = [], incoming) {
|
|
6
|
+
// Use newer data from server to completely replace existing data
|
|
7
|
+
return incoming;
|
|
8
|
+
},
|
|
9
|
+
// Enable pagination with keyArgs to correctly identify cache entries
|
|
10
|
+
keyArgs: ['criteria', 'role', 'limit'],
|
|
11
|
+
// Add a read function for more control over cache reads
|
|
12
|
+
read(existing, {
|
|
13
|
+
args
|
|
14
|
+
}) {
|
|
15
|
+
// Return undefined to force a network request if data doesn't exist
|
|
16
|
+
if (!existing) return undefined;
|
|
17
|
+
return existing;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
Channel: {
|
|
23
|
+
keyFields: ['id'],
|
|
24
|
+
fields: {
|
|
25
|
+
members: {
|
|
26
|
+
merge(existing = [], incoming) {
|
|
27
|
+
return incoming;
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
// Add field policies for other Channel fields if needed
|
|
31
|
+
title: {
|
|
32
|
+
read(title) {
|
|
33
|
+
return title || '';
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
displayName: {
|
|
37
|
+
read(displayName) {
|
|
38
|
+
return displayName || '';
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
// Add computed fields if needed
|
|
42
|
+
memberCount: {
|
|
43
|
+
read(_, {
|
|
44
|
+
readField
|
|
45
|
+
}) {
|
|
46
|
+
const members = readField('members');
|
|
47
|
+
return members && Array.isArray(members) ? members.length : 0;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
// Add policies for ChannelMember type
|
|
53
|
+
ChannelMember: {
|
|
54
|
+
keyFields: ['id'],
|
|
55
|
+
fields: {
|
|
56
|
+
user: {
|
|
57
|
+
// Ensure user references are properly merged
|
|
58
|
+
merge: true
|
|
59
|
+
}
|
|
60
|
+
}
|
|
4
61
|
}
|
|
5
62
|
};export{channelPolicies};//# sourceMappingURL=channel-policies.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"channel-policies.js","sources":["../../../src/graphql/policies/channel-policies.ts"],"sourcesContent":[null],"names":[],"mappings":"AAEa,MAAA,eAAe,GAAiB;AACzC,EAAA,KAAA,EAAK;AACD,IAAA,MAAA,EAAA;AACH;"}
|
|
1
|
+
{"version":3,"file":"channel-policies.js","sources":["../../../src/graphql/policies/channel-policies.ts"],"sourcesContent":[null],"names":[],"mappings":"AAEa,MAAA,eAAe,GAAiB;AACzC,EAAA,KAAA,EAAK;AACD,IAAA,MAAA,EAAA;AACI,MAAA,cAAA,EAAA;AACI,QAAA,KAAA,CAAA,QAAM,GAAA,EAAA,EAAA,QAAe,EAAQ;;AAEzB,UAAA,OAAA,QAAA;;;AAGJ,QAAA,OAAA,EAAA,CAAA,UAAU,EAAA,MAAU,EAAE,OAAM,CAAE;;AAE9B,QAAA,IAAA,CAAA,QAAK,EAAA;;AAED,SAAA,EAAA;AAAe;AACf,UAAA,IAAA,CAAA,QAAA,EAAA,gBAAgB;iBACnB,QAAA;AACJ;AACJ;AACJ;AACD,GAAA;SACa,EAAA;AACT,IAAA,SAAA,EAAQ,CAAA,IAAA,CAAA;AACJ,IAAA,MAAA,EAAA;AACI,MAAA,OAAA,EAAA;AACI,QAAA,KAAA,CAAA,QAAA,GAAA,EAAO,UAAS,EAAA;iBACnB,QAAA;AACJ;;AAED;AACI,MAAA,KAAA,EAAA;oBACI;iBACH,KAAA,IAAA,EAAA;AACJ;AACD,OAAA;AACI,MAAA,WAAA,EAAA;wBACW,EAAA;iBACV,WAAA,IAAA,EAAA;AACJ;;AAED;AACI,MAAA,WAAA,EAAA;AACI,QAAA,IAAA,CAAA,CAAA,EAAA;AACA,UAAA;;AAEP,UAAA,MAAA,OAAA,GAAA,SAAA,CAAA,SAAA,CAAA;AACJ,UAAA,OAAA,OAAA,IAAA,KAAA,CAAA,OAAA,CAAA,OAAA,CAAA,GAAA,OAAA,CAAA,MAAA,GAAA,CAAA;AACJ;;AAED;;AAEI;AACI,EAAA,aAAA,EAAM;gBACF,IAA6C,CAAA;AAC7C,IAAA,MAAA,EAAA;AACH,MAAA,IAAA,EAAA;AACJ;AACJ,QAAA,KAAA,EAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-thread-policies.d.ts","sourceRoot":"","sources":["../../../src/graphql/policies/post-thread-policies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"post-thread-policies.d.ts","sourceRoot":"","sources":["../../../src/graphql/policies/post-thread-policies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAa9C,eAAO,MAAM,kBAAkB,EAAE,YAqKhC,CAAC"}
|
|
@@ -1,57 +1,162 @@
|
|
|
1
|
+
import {gql}from'@apollo/client/index.js';// Define the fragment we'll use for cache operations
|
|
2
|
+
gql`
|
|
3
|
+
fragment PostThreadInfo on PostThread {
|
|
4
|
+
replies
|
|
5
|
+
replyCount
|
|
6
|
+
lastReplyAt
|
|
7
|
+
updatedAt
|
|
8
|
+
}
|
|
9
|
+
`;
|
|
1
10
|
const postThreadPolicies = {
|
|
2
11
|
ThreadMessages: {
|
|
3
|
-
// keyFields: ['messagesRefId'],
|
|
4
|
-
//keyFields: [],
|
|
5
12
|
keyFields: ['data', ['channel', ['id']]],
|
|
6
13
|
fields: {
|
|
7
14
|
data: {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
merge: (existing = [], incoming = [], {
|
|
16
|
+
readField
|
|
17
|
+
}) => {
|
|
18
|
+
// Create a map for efficient lookups
|
|
19
|
+
const threadMap = new Map();
|
|
20
|
+
// Store existing threads
|
|
21
|
+
if (existing && existing.length > 0) {
|
|
22
|
+
for (const item of existing) {
|
|
23
|
+
const id = readField('id', item);
|
|
24
|
+
if (id) threadMap.set(id, item);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
// Add or update with incoming threads
|
|
28
|
+
if (incoming && incoming.length > 0) {
|
|
29
|
+
for (const item of incoming) {
|
|
30
|
+
const id = readField('id', item);
|
|
31
|
+
if (id) threadMap.set(id, item);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
// Convert back to array
|
|
35
|
+
return Array.from(threadMap.values());
|
|
36
|
+
}
|
|
24
37
|
},
|
|
25
38
|
totalCount: {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
39
|
+
merge(existing, incoming) {
|
|
40
|
+
// Take the higher of the two counts
|
|
41
|
+
return incoming !== undefined ? Math.max(existing || 0, incoming) : existing;
|
|
42
|
+
}
|
|
30
43
|
}
|
|
31
44
|
}
|
|
32
45
|
},
|
|
33
46
|
Query: {
|
|
34
47
|
fields: {
|
|
35
48
|
threadMessages: {
|
|
36
|
-
// keyArgs: ['channelId', 'parentId', 'limit', 'skip'],
|
|
37
49
|
keyArgs: ['channelId'],
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
50
|
+
merge(existing, incoming, {
|
|
51
|
+
readField
|
|
52
|
+
}) {
|
|
53
|
+
if (!existing) return incoming;
|
|
54
|
+
if (!incoming) return existing;
|
|
41
55
|
return {
|
|
42
56
|
...incoming,
|
|
43
|
-
data: [...(existing?.data
|
|
57
|
+
data: [...(existing?.data || []), ...(incoming.data || [])].filter((item, index, self) =>
|
|
58
|
+
// Filter out duplicates
|
|
59
|
+
index === self.findIndex(t => readField('id', t) === readField('id', item)))
|
|
44
60
|
};
|
|
45
61
|
}
|
|
46
62
|
},
|
|
47
63
|
getPostThread: {
|
|
48
|
-
|
|
49
|
-
keyArgs: ['channelId', 'postParentId', 'limit', 'skip', 'role'],
|
|
64
|
+
keyArgs: ['channelId', 'postParentId', 'role'],
|
|
50
65
|
merge(existing, incoming, {
|
|
51
66
|
mergeObjects
|
|
52
67
|
}) {
|
|
53
|
-
|
|
54
|
-
|
|
68
|
+
if (!existing) return incoming;
|
|
69
|
+
if (!incoming) return existing;
|
|
70
|
+
// Carefully merge the two objects
|
|
71
|
+
const result = mergeObjects(existing, incoming);
|
|
72
|
+
// Special handling for replies to avoid duplicates
|
|
73
|
+
if (existing.replies && incoming.replies) {
|
|
74
|
+
const uniqueReplies = new Map();
|
|
75
|
+
// Add existing replies
|
|
76
|
+
for (const reply of existing.replies) {
|
|
77
|
+
uniqueReplies.set(reply.id, reply);
|
|
78
|
+
}
|
|
79
|
+
// Add incoming replies, overwriting existing ones
|
|
80
|
+
for (const reply of incoming.replies) {
|
|
81
|
+
uniqueReplies.set(reply.id, reply);
|
|
82
|
+
}
|
|
83
|
+
// Replace replies with deduplicated list
|
|
84
|
+
result.replies = Array.from(uniqueReplies.values());
|
|
85
|
+
}
|
|
86
|
+
return result;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
// Mutation: {
|
|
92
|
+
// fields: {
|
|
93
|
+
// createPostThread: {
|
|
94
|
+
// merge(existing, incoming, { cache, args, readField }) {
|
|
95
|
+
// // Early return if not enough data
|
|
96
|
+
// if (!incoming?.lastMessage || !incoming?.data || !args?.channelId || !args?.postParentId) {
|
|
97
|
+
// return incoming;
|
|
98
|
+
// }
|
|
99
|
+
// try {
|
|
100
|
+
// // Use type policies to handle the cache update instead of direct manipulation
|
|
101
|
+
// const queryRef = cache.identify({
|
|
102
|
+
// __typename: 'Query',
|
|
103
|
+
// getPostThread: {
|
|
104
|
+
// channelId: args.channelId,
|
|
105
|
+
// postParentId: args.postParentId,
|
|
106
|
+
// role: args.threadMessageInput?.role
|
|
107
|
+
// }
|
|
108
|
+
// });
|
|
109
|
+
// // Use cache.modify which doesn't require fragments
|
|
110
|
+
// if (queryRef) {
|
|
111
|
+
// cache.modify({
|
|
112
|
+
// id: queryRef,
|
|
113
|
+
// fields: {
|
|
114
|
+
// getPostThread(existingThread = {}) {
|
|
115
|
+
// if (!existingThread) return existingThread;
|
|
116
|
+
// // Create a new object with the updated properties
|
|
117
|
+
// return {
|
|
118
|
+
// ...existingThread,
|
|
119
|
+
// replies: [incoming.lastMessage, ...(existingThread.replies || [])],
|
|
120
|
+
// replyCount: (existingThread.replyCount || 0) + 1,
|
|
121
|
+
// lastReplyAt: incoming.lastMessage.createdAt,
|
|
122
|
+
// updatedAt: incoming.lastMessage.createdAt
|
|
123
|
+
// };
|
|
124
|
+
// }
|
|
125
|
+
// }
|
|
126
|
+
// });
|
|
127
|
+
// }
|
|
128
|
+
// } catch (error) {
|
|
129
|
+
// console.error('Error updating cache in createPostThread policy:', error);
|
|
130
|
+
// }
|
|
131
|
+
// return incoming;
|
|
132
|
+
// },
|
|
133
|
+
// },
|
|
134
|
+
// },
|
|
135
|
+
// },
|
|
136
|
+
PostThread: {
|
|
137
|
+
fields: {
|
|
138
|
+
replies: {
|
|
139
|
+
merge(existing = [], incoming = [], {
|
|
140
|
+
readField
|
|
141
|
+
}) {
|
|
142
|
+
// Use a map for fast deduplication
|
|
143
|
+
const replyMap = new Map();
|
|
144
|
+
// Add existing replies
|
|
145
|
+
if (existing && existing.length > 0) {
|
|
146
|
+
for (const reply of existing) {
|
|
147
|
+
const id = readField('id', reply);
|
|
148
|
+
if (id) replyMap.set(id, reply);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// Add or update with incoming replies
|
|
152
|
+
if (incoming && incoming.length > 0) {
|
|
153
|
+
for (const reply of incoming) {
|
|
154
|
+
const id = readField('id', reply);
|
|
155
|
+
if (id) replyMap.set(id, reply);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
// Convert back to array
|
|
159
|
+
return Array.from(replyMap.values());
|
|
55
160
|
}
|
|
56
161
|
}
|
|
57
162
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"post-thread-policies.js","sources":["../../../src/graphql/policies/post-thread-policies.ts"],"sourcesContent":[null],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"post-thread-policies.js","sources":["../../../src/graphql/policies/post-thread-policies.ts"],"sourcesContent":[null],"names":[],"mappings":"0CAGA;AAC6B,GAAG;;;;;;;;AASnB,MAAA,kBAAkB,GAAiB;AAC5C,EAAA,cAAA,EAAc;aACD,EAAA,CAAA,MAAG,EAAA,CAAA,SAAkB,EAAA,CAAA,IAAG,CAAA,CAAA,CAAA;AACjC,IAAA,MAAA,EAAA;AACI,MAAA,IAAA,EAAA;AACI,QAAA,KAAA,EAAA,CAAA,QAAQ,GAAQ,EAAA,EAAA,QAAO,GAAA,EAAA,EAAA;;AAEnB,SAAA,KAAA;;yBAGI,GAAA,IAAQ,KAAY;AACpB;kCACU,CAAA,MAAc,GAAA,CAAA,EAAA;AACpB,YAAA,KAAA,MAAA,IAAA,IAAA,QAAM,EAAA;AAAE,cAAA,MAAA,EAAA,GAAA,SAAA,CAAA,IAAA,EAAS,IAAI,CAAC;+BACzB,CAAA,GAAA,CAAA,EAAA,EAAA,IAAA,CAAA;;;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,CAAA,IAAA,CAAA,QAAU,CAAA,SAAS;;AAEjC;AACJ;AACJ;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"teams-policies.d.ts","sourceRoot":"","sources":["../../../src/graphql/policies/teams-policies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,eAAO,MAAM,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"teams-policies.d.ts","sourceRoot":"","sources":["../../../src/graphql/policies/teams-policies.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,eAAO,MAAM,YAAY,EAAE,YAgB1B,CAAC"}
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
const teamPolicies = {
|
|
2
2
|
Query: {
|
|
3
|
-
fields: {
|
|
3
|
+
fields: {
|
|
4
|
+
getOrganizationTeams: {
|
|
5
|
+
merge(existing = [], incoming) {
|
|
6
|
+
return incoming;
|
|
7
|
+
},
|
|
8
|
+
read(existing) {
|
|
9
|
+
return existing;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
AccountTeam: {
|
|
15
|
+
keyFields: ['_id']
|
|
4
16
|
}
|
|
5
17
|
};export{teamPolicies};//# sourceMappingURL=teams-policies.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"teams-policies.js","sources":["../../../src/graphql/policies/teams-policies.ts"],"sourcesContent":[null],"names":[],"mappings":"AAEa,MAAA,YAAY,GAAiB;AACtC,EAAA,KAAA,EAAK;AACD,IAAA,MAAA,EAAA;
|
|
1
|
+
{"version":3,"file":"teams-policies.js","sources":["../../../src/graphql/policies/teams-policies.ts"],"sourcesContent":[null],"names":[],"mappings":"AAEa,MAAA,YAAY,GAAiB;AACtC,EAAA,KAAA,EAAK;AACD,IAAA,MAAA,EAAA;AACI,MAAA,oBAAA,EAAA;AACI,QAAA,KAAA,CAAA,QAAM,GAAA,EAAA,EAAA,QAAe,EAAQ;AACzB,UAAA,OAAA,QAAA;;AAEJ,QAAA,IAAA,CAAA,QAAK,EAAQ;AACT,UAAA,OAAA,QAAA;;AAEP;AACJ;AACJ,GAAA;AACD,EAAA,WAAA,EAAW;aACE,EAAA,CAAA,KAAG;AACf;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@messenger-box/platform-client",
|
|
3
|
-
"version": "10.0.3-alpha.
|
|
3
|
+
"version": "10.0.3-alpha.43",
|
|
4
4
|
"description": "Sample core for higher packages to depend on",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "CDMBase LLC",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
},
|
|
22
22
|
"dependencies": {
|
|
23
23
|
"@container-stack/file-info-client": "^5.4.1-alpha.6",
|
|
24
|
-
"@messenger-box/core": "10.0.3-alpha.
|
|
24
|
+
"@messenger-box/core": "10.0.3-alpha.40",
|
|
25
25
|
"key-mirror": "1.0.1",
|
|
26
26
|
"moment-timezone": "0.5.33"
|
|
27
27
|
},
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"typescript": {
|
|
36
36
|
"definition": "lib/index.d.ts"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "e70bc5ae7e2b6570406b8aaf73de5ba4ebed691a"
|
|
39
39
|
}
|
|
@@ -2,6 +2,59 @@ import { TypePolicies } from '@apollo/client';
|
|
|
2
2
|
|
|
3
3
|
export const channelPolicies: TypePolicies = {
|
|
4
4
|
Query: {
|
|
5
|
-
fields: {
|
|
5
|
+
fields: {
|
|
6
|
+
channelsByUser: {
|
|
7
|
+
merge(existing = [], incoming) {
|
|
8
|
+
// Use newer data from server to completely replace existing data
|
|
9
|
+
return incoming;
|
|
10
|
+
},
|
|
11
|
+
// Enable pagination with keyArgs to correctly identify cache entries
|
|
12
|
+
keyArgs: ['criteria', 'role', 'limit'],
|
|
13
|
+
// Add a read function for more control over cache reads
|
|
14
|
+
read(existing, { args }) {
|
|
15
|
+
// Return undefined to force a network request if data doesn't exist
|
|
16
|
+
if (!existing) return undefined;
|
|
17
|
+
return existing;
|
|
18
|
+
},
|
|
19
|
+
},
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
Channel: {
|
|
23
|
+
keyFields: ['id'],
|
|
24
|
+
fields: {
|
|
25
|
+
members: {
|
|
26
|
+
merge(existing = [], incoming) {
|
|
27
|
+
return incoming;
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
// Add field policies for other Channel fields if needed
|
|
31
|
+
title: {
|
|
32
|
+
read(title) {
|
|
33
|
+
return title || '';
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
displayName: {
|
|
37
|
+
read(displayName) {
|
|
38
|
+
return displayName || '';
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
// Add computed fields if needed
|
|
42
|
+
memberCount: {
|
|
43
|
+
read(_, { readField }) {
|
|
44
|
+
const members = readField('members') as any[];
|
|
45
|
+
return members && Array.isArray(members) ? members.length : 0;
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
// Add policies for ChannelMember type
|
|
51
|
+
ChannelMember: {
|
|
52
|
+
keyFields: ['id'],
|
|
53
|
+
fields: {
|
|
54
|
+
user: {
|
|
55
|
+
// Ensure user references are properly merged
|
|
56
|
+
merge: true,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
6
59
|
},
|
|
7
60
|
};
|
|
@@ -1,57 +1,177 @@
|
|
|
1
1
|
import { TypePolicies } from '@apollo/client';
|
|
2
|
+
import { gql } from '@apollo/client';
|
|
3
|
+
|
|
4
|
+
// Define the fragment we'll use for cache operations
|
|
5
|
+
const POST_THREAD_FRAGMENT = gql`
|
|
6
|
+
fragment PostThreadInfo on PostThread {
|
|
7
|
+
replies
|
|
8
|
+
replyCount
|
|
9
|
+
lastReplyAt
|
|
10
|
+
updatedAt
|
|
11
|
+
}
|
|
12
|
+
`;
|
|
2
13
|
|
|
3
14
|
export const postThreadPolicies: TypePolicies = {
|
|
4
15
|
ThreadMessages: {
|
|
5
|
-
// keyFields: ['messagesRefId'],
|
|
6
|
-
//keyFields: [],
|
|
7
16
|
keyFields: ['data', ['channel', ['id']]],
|
|
8
17
|
fields: {
|
|
9
18
|
data: {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
merge: (existing = [], incoming = [], { readField }) => {
|
|
20
|
+
// Create a map for efficient lookups
|
|
21
|
+
const threadMap = new Map();
|
|
22
|
+
|
|
23
|
+
// Store existing threads
|
|
24
|
+
if (existing && existing.length > 0) {
|
|
25
|
+
for (const item of existing) {
|
|
26
|
+
const id = readField('id', item);
|
|
27
|
+
if (id) threadMap.set(id, item);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Add or update with incoming threads
|
|
32
|
+
if (incoming && incoming.length > 0) {
|
|
33
|
+
for (const item of incoming) {
|
|
34
|
+
const id = readField('id', item);
|
|
35
|
+
if (id) threadMap.set(id, item);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Convert back to array
|
|
40
|
+
return Array.from(threadMap.values());
|
|
41
|
+
},
|
|
26
42
|
},
|
|
27
43
|
totalCount: {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
44
|
+
merge(existing, incoming) {
|
|
45
|
+
// Take the higher of the two counts
|
|
46
|
+
return incoming !== undefined ? Math.max(existing || 0, incoming) : existing;
|
|
47
|
+
},
|
|
32
48
|
},
|
|
33
49
|
},
|
|
34
50
|
},
|
|
35
51
|
Query: {
|
|
36
52
|
fields: {
|
|
37
53
|
threadMessages: {
|
|
38
|
-
// keyArgs: ['channelId', 'parentId', 'limit', 'skip'],
|
|
39
54
|
keyArgs: ['channelId'],
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
55
|
+
merge(existing, incoming, { readField }) {
|
|
56
|
+
if (!existing) return incoming;
|
|
57
|
+
if (!incoming) return existing;
|
|
58
|
+
|
|
43
59
|
return {
|
|
44
60
|
...incoming,
|
|
45
|
-
data: [...(existing?.data
|
|
61
|
+
data: [...(existing?.data || []), ...(incoming.data || [])].filter(
|
|
62
|
+
(item, index, self) =>
|
|
63
|
+
// Filter out duplicates
|
|
64
|
+
index === self.findIndex((t) => readField('id', t) === readField('id', item)),
|
|
65
|
+
),
|
|
46
66
|
};
|
|
47
67
|
},
|
|
48
68
|
},
|
|
49
69
|
getPostThread: {
|
|
50
|
-
|
|
51
|
-
keyArgs: ['channelId', 'postParentId', 'limit', 'skip', 'role'],
|
|
70
|
+
keyArgs: ['channelId', 'postParentId', 'role'],
|
|
52
71
|
merge(existing, incoming, { mergeObjects }) {
|
|
53
|
-
|
|
54
|
-
|
|
72
|
+
if (!existing) return incoming;
|
|
73
|
+
if (!incoming) return existing;
|
|
74
|
+
|
|
75
|
+
// Carefully merge the two objects
|
|
76
|
+
const result = mergeObjects(existing, incoming);
|
|
77
|
+
|
|
78
|
+
// Special handling for replies to avoid duplicates
|
|
79
|
+
if (existing.replies && incoming.replies) {
|
|
80
|
+
const uniqueReplies = new Map();
|
|
81
|
+
|
|
82
|
+
// Add existing replies
|
|
83
|
+
for (const reply of existing.replies) {
|
|
84
|
+
uniqueReplies.set(reply.id, reply);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Add incoming replies, overwriting existing ones
|
|
88
|
+
for (const reply of incoming.replies) {
|
|
89
|
+
uniqueReplies.set(reply.id, reply);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Replace replies with deduplicated list
|
|
93
|
+
result.replies = Array.from(uniqueReplies.values());
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return result;
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
// Mutation: {
|
|
102
|
+
// fields: {
|
|
103
|
+
// createPostThread: {
|
|
104
|
+
// merge(existing, incoming, { cache, args, readField }) {
|
|
105
|
+
// // Early return if not enough data
|
|
106
|
+
// if (!incoming?.lastMessage || !incoming?.data || !args?.channelId || !args?.postParentId) {
|
|
107
|
+
// return incoming;
|
|
108
|
+
// }
|
|
109
|
+
|
|
110
|
+
// try {
|
|
111
|
+
// // Use type policies to handle the cache update instead of direct manipulation
|
|
112
|
+
// const queryRef = cache.identify({
|
|
113
|
+
// __typename: 'Query',
|
|
114
|
+
// getPostThread: {
|
|
115
|
+
// channelId: args.channelId,
|
|
116
|
+
// postParentId: args.postParentId,
|
|
117
|
+
// role: args.threadMessageInput?.role
|
|
118
|
+
// }
|
|
119
|
+
// });
|
|
120
|
+
|
|
121
|
+
// // Use cache.modify which doesn't require fragments
|
|
122
|
+
// if (queryRef) {
|
|
123
|
+
// cache.modify({
|
|
124
|
+
// id: queryRef,
|
|
125
|
+
// fields: {
|
|
126
|
+
// getPostThread(existingThread = {}) {
|
|
127
|
+
// if (!existingThread) return existingThread;
|
|
128
|
+
|
|
129
|
+
// // Create a new object with the updated properties
|
|
130
|
+
// return {
|
|
131
|
+
// ...existingThread,
|
|
132
|
+
// replies: [incoming.lastMessage, ...(existingThread.replies || [])],
|
|
133
|
+
// replyCount: (existingThread.replyCount || 0) + 1,
|
|
134
|
+
// lastReplyAt: incoming.lastMessage.createdAt,
|
|
135
|
+
// updatedAt: incoming.lastMessage.createdAt
|
|
136
|
+
// };
|
|
137
|
+
// }
|
|
138
|
+
// }
|
|
139
|
+
// });
|
|
140
|
+
// }
|
|
141
|
+
// } catch (error) {
|
|
142
|
+
// console.error('Error updating cache in createPostThread policy:', error);
|
|
143
|
+
// }
|
|
144
|
+
|
|
145
|
+
// return incoming;
|
|
146
|
+
// },
|
|
147
|
+
// },
|
|
148
|
+
// },
|
|
149
|
+
// },
|
|
150
|
+
PostThread: {
|
|
151
|
+
fields: {
|
|
152
|
+
replies: {
|
|
153
|
+
merge(existing = [], incoming = [], { readField }) {
|
|
154
|
+
// Use a map for fast deduplication
|
|
155
|
+
const replyMap = new Map();
|
|
156
|
+
|
|
157
|
+
// Add existing replies
|
|
158
|
+
if (existing && existing.length > 0) {
|
|
159
|
+
for (const reply of existing) {
|
|
160
|
+
const id = readField('id', reply);
|
|
161
|
+
if (id) replyMap.set(id, reply);
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Add or update with incoming replies
|
|
166
|
+
if (incoming && incoming.length > 0) {
|
|
167
|
+
for (const reply of incoming) {
|
|
168
|
+
const id = readField('id', reply);
|
|
169
|
+
if (id) replyMap.set(id, reply);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// Convert back to array
|
|
174
|
+
return Array.from(replyMap.values());
|
|
55
175
|
},
|
|
56
176
|
},
|
|
57
177
|
},
|
|
@@ -2,6 +2,18 @@ import { TypePolicies } from '@apollo/client';
|
|
|
2
2
|
|
|
3
3
|
export const teamPolicies: TypePolicies = {
|
|
4
4
|
Query: {
|
|
5
|
-
fields: {
|
|
5
|
+
fields: {
|
|
6
|
+
getOrganizationTeams: {
|
|
7
|
+
merge(existing = [], incoming) {
|
|
8
|
+
return incoming;
|
|
9
|
+
},
|
|
10
|
+
read(existing) {
|
|
11
|
+
return existing;
|
|
12
|
+
},
|
|
13
|
+
},
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
AccountTeam: {
|
|
17
|
+
keyFields: ['_id'],
|
|
6
18
|
},
|
|
7
19
|
};
|