@messenger-box/platform-client 0.0.1-alpha.390 → 0.0.1-alpha.392

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.
@@ -4,6 +4,7 @@ fragment MessengerUser on UserAccount{
4
4
  familyName
5
5
  email
6
6
  username
7
+ fullName @client
7
8
  picture
8
9
  alias
9
10
  tokens {
@@ -1,8 +1,11 @@
1
1
  fragment Post on Post {
2
+ id
3
+ channel {
4
+ id
5
+ }
2
6
  author {
3
7
  ...MessengerUser
4
8
  }
5
- id
6
9
  isPinned
7
10
  message
8
11
  type
@@ -12,6 +15,7 @@ fragment Post on Post {
12
15
  createdAt
13
16
  fromServer
14
17
  updatedAt
18
+
15
19
  propsConfiguration {
16
20
  ...Configuration
17
21
  }
@@ -1,7 +1,7 @@
1
1
  import { merge } from 'lodash';
2
- import { postPolicies, userPolicies, channelPolicies } from './policies';
2
+ import { postPolicies, userPolicies, channelPolicies,userAccountPolicies,messagesPolicies } from './policies';
3
3
  import { schema } from './schema';
4
4
 
5
- const typePolicies = merge({}, postPolicies, userPolicies, channelPolicies);
5
+ const typePolicies = merge({}, postPolicies, userPolicies, channelPolicies,userAccountPolicies,messagesPolicies);
6
6
  export { schema, typePolicies };
7
7
  export * from './id-generation';
@@ -1,3 +1,5 @@
1
1
  export * from './posts-policies';
2
2
  export * from './user-policies';
3
3
  export * from './channel-policies';
4
+ export * from './user-account-policies'
5
+ export * from './messages-policies'
@@ -0,0 +1,63 @@
1
+ import { TypePolicies } from '@apollo/client';
2
+
3
+ export const messagesPolicies: TypePolicies = {
4
+ Messages: {
5
+ // keyFields: ['messagesRefId'],
6
+ fields: {
7
+ id: {
8
+ read(existing, { variables }) {
9
+ const { channelId, parentId }: any = variables;
10
+ return parentId ? `${channelId}-${parentId}` : `${channelId}`;
11
+ },
12
+ },
13
+ // data: {
14
+ // merge(existing: any[], incoming: any[], { args }) {
15
+ // console.log('existing', JSON.stringify(existing), 'incoming', JSON.stringify(incoming));
16
+ // const merged = existing ? existing.slice(0) : [];
17
+ // // Insert the incoming elements in the right places, according to args.
18
+ // const end = args?.skip + Math.min(args?.limit, incoming.length);
19
+ // for (let i = args?.skip; i < end; ++i) {
20
+ // merged[i] = incoming[i - args?.skip];
21
+ // }
22
+ // return merged;
23
+ // },
24
+ // },
25
+ },
26
+ },
27
+ PostThreadMessages: {
28
+ // keyFields: ['messagesRefId'],
29
+ fields: {
30
+ id: {
31
+ read(existing, { variables }) {
32
+ const { channelId, parentId }: any = variables;
33
+ return parentId ? `${channelId}-${parentId}` : `${channelId}`;
34
+ },
35
+ },
36
+ },
37
+ },
38
+ Query: {
39
+ fields: {
40
+ messages: {
41
+ // keyArgs: ['channelId', 'parentId', 'limit', 'skip'],
42
+ keyArgs: ['channelId', 'parentId'],
43
+ merge(existing, incoming, { args, mergeObjects }) {
44
+ // console.log('existing', JSON.stringify(existing), 'incoming', JSON.stringify(incoming));
45
+ if (!incoming) return existing;
46
+ if (!existing) return incoming;
47
+ //console.log('existing', JSON.stringify(existing), 'incoming', JSON.stringify(incoming));
48
+ const mergedData = existing ? existing?.data?.slice(0) : [];
49
+ // Insert the incoming elements in the right places, according to args.
50
+ const end = args?.skip + Math.min(args?.limit, incoming?.data?.length);
51
+ for (let i = args?.skip; i < end; ++i) {
52
+ mergedData[i] = incoming?.data[i - args?.skip];
53
+ }
54
+
55
+ const merged = { ...incoming, data: mergedData };
56
+ return merged;
57
+ // return mergeObjects(existing, incoming);
58
+ //return existing ? { ...existing, ...incoming } : incoming;
59
+ },
60
+ },
61
+ },
62
+ },
63
+ };
@@ -0,0 +1,15 @@
1
+ import { TypePolicies } from '@apollo/client';
2
+
3
+ export const userAccountPolicies: TypePolicies = {
4
+ UserAccount: {
5
+ fields: {
6
+ fullName: {
7
+ read(_, { readField, toReference, }) {
8
+ const givenName = readField('givenName');
9
+ const familyName = readField('familyName');
10
+ return `${givenName} ${familyName}`;
11
+ },
12
+ },
13
+ },
14
+ },
15
+ };
@@ -1,5 +1,16 @@
1
- query Messages($channelId: ID,$parentId: String, $limit: Int! = 30, $skip: Int! = 0) {
2
- messages(channelId: $channelId,parentId:$parentId, limit: $limit, skip: $skip) {
1
+ query Messages($channelId: ID,$parentId: String, $limit: Int! = 10, $skip: Int! = 0, $sort: Sort) {
2
+ messages(channelId: $channelId,parentId:$parentId, limit: $limit, skip: $skip, sort: $sort) {
3
+ id @client
4
+ data{
5
+ ...Post
6
+ }
7
+ totalCount
8
+ }
9
+ }
10
+
11
+ query PostThreadMessages($channelId: ID,$parentId: String, $limit: Int! = 10, $skip: Int! = 0, $sort: Sort) {
12
+ messages(channelId: $channelId,parentId:$parentId, limit: $limit, skip: $skip, sort: $sort) @connection(key: "threadposts") {
13
+ id @client
3
14
  data{
4
15
  ...Post
5
16
  }
@@ -1,4 +1,6 @@
1
1
  import postSchema from './post.graphql';
2
+ import userAccountSchema from './user-account.graphql'
3
+ import messagesSchema from './messages.graphql'
2
4
 
3
- const schema = [postSchema];
5
+ const schema = [postSchema,userAccountSchema,messagesSchema];
4
6
  export { schema };
@@ -0,0 +1,3 @@
1
+ extend type Messages {
2
+ id: String
3
+ }
@@ -0,0 +1,3 @@
1
+ extend type UserAccount {
2
+ fullName: String
3
+ }