@jsb188/graphql 1.0.4 → 1.1.3
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/cache/config.ts +3 -1
- package/cache/index.ts +2 -1
- package/client/index.ts +1 -1
- package/client/request.ts +6 -5
- package/gql/fragments/accountAuthFragments.ts +16 -0
- package/gql/fragments/accountFragments.ts +13 -0
- package/gql/fragments/aiChatFragments.ts +5 -1
- package/gql/fragments/journalFragments.ts +14 -0
- package/gql/fragments/organizationFragments.ts +24 -0
- package/gql/fragments/otherFragments.ts +1 -0
- package/gql/fragments/{authFragments.ts → userAuthFragments.ts} +1 -1
- package/gql/mutations/accountAuthMutations.ts +81 -0
- package/gql/mutations/aiChatMutations.ts +40 -2
- package/gql/mutations/journalMutations.ts +2 -0
- package/gql/mutations/{authMutations.ts → userAuthMutations.ts} +3 -31
- package/gql/queries/aiChatQueries.ts +25 -1
- package/gql/queries/journalQueries.ts +28 -0
- package/gql/queries/organizationQueries.ts +52 -0
- package/{client/hooks.ts → hooks/index.ts} +24 -8
- package/hooks/use-aiChat-qry.ts +160 -0
- package/hooks/use-app-qry.ts +19 -0
- package/hooks/use-auth-mtn.ts +322 -0
- package/hooks/use-journal-qry.ts +50 -0
- package/hooks/use-organization-qry.ts +37 -0
- package/package.json +21 -7
- package/sse.ts +14 -21
- package/types.d.ts +24 -7
- package/utils.ts +13 -10
- /package/gql/queries/{authQueries.ts → appQueries.ts} +0 -0
package/cache/config.ts
CHANGED
|
@@ -19,6 +19,7 @@ export const RULES = {
|
|
|
19
19
|
// List of queries that should be cached
|
|
20
20
|
// NOTE: Fragments are always cached
|
|
21
21
|
aiChat: true,
|
|
22
|
+
aiChatMessages: true,
|
|
22
23
|
alerts: true,
|
|
23
24
|
cardsForUser: true,
|
|
24
25
|
chat: true,
|
|
@@ -35,7 +36,8 @@ export const RULES = {
|
|
|
35
36
|
|
|
36
37
|
// All fragments are cached,
|
|
37
38
|
// but if you want to skip some, add it here
|
|
38
|
-
|
|
39
|
+
accountAuthFragment: false,
|
|
40
|
+
userAuthFragment: false,
|
|
39
41
|
} as {
|
|
40
42
|
__limit: number;
|
|
41
43
|
[key: string]: boolean | number;
|
package/cache/index.ts
CHANGED
|
@@ -116,6 +116,7 @@ function extractFragment(dataObj: any, innerSelection: any[]) {
|
|
|
116
116
|
|
|
117
117
|
export function loadQuery(queryKey: string, referencesOnly?: boolean) {
|
|
118
118
|
const references = QUERIES.get(queryKey);
|
|
119
|
+
|
|
119
120
|
if (referencesOnly) {
|
|
120
121
|
return references;
|
|
121
122
|
} else if (!references) {
|
|
@@ -301,7 +302,7 @@ function makeCacheObject(data: any, selections: any[], variables?: any, cacheMap
|
|
|
301
302
|
*/
|
|
302
303
|
|
|
303
304
|
function saveQueryToMemory(
|
|
304
|
-
requestData: any
|
|
305
|
+
requestData: any,
|
|
305
306
|
selection: any,
|
|
306
307
|
variables: any,
|
|
307
308
|
variablesKey: string,
|
package/client/index.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from '
|
|
1
|
+
export * from '../hooks/index';
|
|
2
2
|
export * from './request';
|
package/client/request.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getENVVariable } from '@jsb188/app';
|
|
2
|
-
import type { ServerErrorObj } from '@jsb188/app/types/app';
|
|
2
|
+
import type { ServerErrorObj } from '@jsb188/app/types/app.d';
|
|
3
3
|
import { getAuthToken, normalizeServerError } from '@jsb188/app/utils/api';
|
|
4
4
|
import { delay } from '@jsb188/app/utils/logic';
|
|
5
5
|
import { setDataToCache } from '../cache/';
|
|
@@ -12,6 +12,7 @@ import { apiRequestHeaders, isServerErrorGQL } from '../utils';
|
|
|
12
12
|
|
|
13
13
|
type GraphQLMutationOptions = Partial<{
|
|
14
14
|
authToken: string;
|
|
15
|
+
ipAddress: string | null; // Only used if SSR
|
|
15
16
|
retryCount: number;
|
|
16
17
|
variables: any;
|
|
17
18
|
cacheMap: any;
|
|
@@ -121,24 +122,24 @@ export async function graphqlRequest(
|
|
|
121
122
|
updateObservers?: UpdateObserversFn,
|
|
122
123
|
): Promise<any> {
|
|
123
124
|
|
|
124
|
-
const { openModalPopUp, onCompleted, onError, authToken, cacheMap } = params || {};
|
|
125
|
+
const { openModalPopUp, onCompleted, onError, authToken, cacheMap, ipAddress } = params || {};
|
|
125
126
|
|
|
126
127
|
if (!gqlQuery?.definitions) {
|
|
127
128
|
console.log(gqlQuery);
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
const operationName = gqlQuery?.definitions?.find((def: any) => def.kind === 'OperationDefinition')?.name?.value;
|
|
131
|
-
const headers = apiRequestHeaders(getENVVariable('IS_BROWSER') ? getAuthToken() : authToken);
|
|
132
|
+
const headers = apiRequestHeaders(getENVVariable('IS_BROWSER') ? getAuthToken() : authToken, ipAddress);
|
|
132
133
|
|
|
133
134
|
// Use this to check queries that are getting double-requested
|
|
134
135
|
// doLog(gqlQuery, 'QUERYING... $0');
|
|
135
136
|
|
|
136
|
-
return fetch(getENVVariable('GQL_SERVER')
|
|
137
|
+
return fetch(getENVVariable('GQL_SERVER') as string, {
|
|
137
138
|
signal: controllerSignal,
|
|
138
139
|
method: 'POST',
|
|
139
140
|
// credentials: 'same-origin',
|
|
140
141
|
// headers: new Headers({
|
|
141
|
-
headers
|
|
142
|
+
headers,
|
|
142
143
|
// headers,
|
|
143
144
|
body: JSON.stringify({
|
|
144
145
|
query: gqlQuery?.loc?.source.body,
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export const accountAuthFragment = `fragment accountAuthFragment on AccountAuth {
|
|
2
|
+
token
|
|
3
|
+
primaryOrganizationId
|
|
4
|
+
activated
|
|
5
|
+
hasPassword
|
|
6
|
+
version
|
|
7
|
+
|
|
8
|
+
settings {
|
|
9
|
+
theme
|
|
10
|
+
lightMode
|
|
11
|
+
timeZone
|
|
12
|
+
showSelfAvatar
|
|
13
|
+
isBubbleOther
|
|
14
|
+
showOtherAvatar
|
|
15
|
+
}
|
|
16
|
+
}`;
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export const aiChatFragment = `fragment aiChatFragment on AIChat {
|
|
2
2
|
id
|
|
3
|
+
organizationId
|
|
4
|
+
accountId
|
|
5
|
+
calDate
|
|
3
6
|
summary
|
|
4
7
|
createdAt
|
|
5
8
|
updatedAt
|
|
@@ -7,7 +10,8 @@ export const aiChatFragment = `fragment aiChatFragment on AIChat {
|
|
|
7
10
|
|
|
8
11
|
export const aiChatMessageFragment = `fragment aiChatMessageFragment on AIChatMessage {
|
|
9
12
|
id
|
|
10
|
-
|
|
13
|
+
accountId
|
|
14
|
+
type
|
|
11
15
|
cursor
|
|
12
16
|
text
|
|
13
17
|
photoUri
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
|
|
2
|
+
export const organizationFragment = `fragment organizationFragment on Organization {
|
|
3
|
+
id
|
|
4
|
+
stripeCustomerId
|
|
5
|
+
name
|
|
6
|
+
domains
|
|
7
|
+
}`;
|
|
8
|
+
|
|
9
|
+
export const organizationRelationshipFragment = `fragment organizationRelationshipFragment on OrganizationRelationship {
|
|
10
|
+
id
|
|
11
|
+
primary
|
|
12
|
+
role
|
|
13
|
+
|
|
14
|
+
acl {
|
|
15
|
+
id
|
|
16
|
+
billing
|
|
17
|
+
journal
|
|
18
|
+
members
|
|
19
|
+
finances
|
|
20
|
+
products
|
|
21
|
+
settings
|
|
22
|
+
integrations
|
|
23
|
+
}
|
|
24
|
+
}`;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { gql } from 'graphql-tag';
|
|
2
|
+
import { accountAuthFragment } from '../fragments/accountAuthFragments';
|
|
3
|
+
import { emailFragment, phoneFragment } from '../fragments/otherFragments';
|
|
4
|
+
import { accountFragment } from '../fragments/accountFragments';
|
|
5
|
+
|
|
6
|
+
const authenticateResultText = `...accountAuthFragment
|
|
7
|
+
|
|
8
|
+
account {
|
|
9
|
+
...accountFragment
|
|
10
|
+
|
|
11
|
+
email {
|
|
12
|
+
...emailFragment
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
phone {
|
|
16
|
+
...phoneFragment
|
|
17
|
+
}
|
|
18
|
+
}`;
|
|
19
|
+
|
|
20
|
+
const authenticateFragments = `
|
|
21
|
+
${accountAuthFragment}
|
|
22
|
+
${accountFragment}
|
|
23
|
+
${emailFragment}
|
|
24
|
+
${phoneFragment}
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
export const authenticateWithPasswordMtn = gql`
|
|
28
|
+
mutation authenticateWithPassword (
|
|
29
|
+
$identifier: String!
|
|
30
|
+
$password: String!
|
|
31
|
+
) {
|
|
32
|
+
authenticateWithPassword (
|
|
33
|
+
identifier: $identifier,
|
|
34
|
+
password: $password
|
|
35
|
+
) {
|
|
36
|
+
${authenticateResultText}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
${authenticateFragments}
|
|
40
|
+
`;
|
|
41
|
+
|
|
42
|
+
export const authenticateWithTokenMtn = gql`
|
|
43
|
+
mutation authenticateWithToken (
|
|
44
|
+
$token: Token!
|
|
45
|
+
) {
|
|
46
|
+
authenticateWithToken (
|
|
47
|
+
token: $token
|
|
48
|
+
) {
|
|
49
|
+
${authenticateResultText}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
${authenticateFragments}
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
export const signInWithGoogleMtn = gql`
|
|
56
|
+
mutation signInWithGoogle (
|
|
57
|
+
$oauthToken: String!
|
|
58
|
+
) {
|
|
59
|
+
signInWithGoogle (
|
|
60
|
+
oauthToken: $oauthToken
|
|
61
|
+
) {
|
|
62
|
+
${authenticateResultText}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
${authenticateFragments}
|
|
66
|
+
`;
|
|
67
|
+
|
|
68
|
+
export const signInWithAppleMtn = gql`
|
|
69
|
+
mutation signInWithApple (
|
|
70
|
+
$code: String!
|
|
71
|
+
$idToken: String!
|
|
72
|
+
) {
|
|
73
|
+
signInWithApple (
|
|
74
|
+
code: $code
|
|
75
|
+
idToken: $idToken
|
|
76
|
+
) {
|
|
77
|
+
${authenticateResultText}
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
${authenticateFragments}
|
|
81
|
+
`;
|
|
@@ -1,16 +1,54 @@
|
|
|
1
1
|
import { gql } from 'graphql-tag';
|
|
2
|
-
import { aiChatFragment } from '../fragments/aiChatFragments';
|
|
2
|
+
import { aiChatFragment, aiChatMessageFragment } from '../fragments/aiChatFragments';
|
|
3
3
|
|
|
4
4
|
export const startAIChatMtn = gql`
|
|
5
5
|
mutation startAIChat (
|
|
6
|
+
$organizationId: GenericID!
|
|
6
7
|
$text: String!
|
|
7
8
|
) {
|
|
8
9
|
startAIChat (
|
|
10
|
+
organizationId: $organizationId
|
|
9
11
|
text: $text
|
|
10
12
|
) {
|
|
11
|
-
|
|
13
|
+
sessionKey
|
|
14
|
+
node {
|
|
15
|
+
...aiChatFragment
|
|
16
|
+
}
|
|
12
17
|
}
|
|
13
18
|
}
|
|
14
19
|
|
|
15
20
|
${aiChatFragment}
|
|
16
21
|
`;
|
|
22
|
+
|
|
23
|
+
export const sendAIChatMessageMtn = gql`
|
|
24
|
+
mutation sendAIChatMessage (
|
|
25
|
+
$aiChatId: GenericID!
|
|
26
|
+
$organizationId: GenericID
|
|
27
|
+
$variablesKey: String
|
|
28
|
+
$text: String!
|
|
29
|
+
) {
|
|
30
|
+
sendAIChatMessage (
|
|
31
|
+
aiChatId: $aiChatId
|
|
32
|
+
organizationId: $organizationId
|
|
33
|
+
variablesKey: $variablesKey
|
|
34
|
+
text: $text
|
|
35
|
+
) {
|
|
36
|
+
sessionKey
|
|
37
|
+
node {
|
|
38
|
+
...aiChatMessageFragment
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
${aiChatMessageFragment}
|
|
44
|
+
`;
|
|
45
|
+
|
|
46
|
+
export const stopAIChatMessageMtn = gql`
|
|
47
|
+
mutation stopAIChatMessage (
|
|
48
|
+
$aiChatId: GenericID!
|
|
49
|
+
) {
|
|
50
|
+
stopAIChatMessage (
|
|
51
|
+
aiChatId: $aiChatId
|
|
52
|
+
)
|
|
53
|
+
}
|
|
54
|
+
`;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { gql } from 'graphql-tag';
|
|
2
|
+
import { userAuthFragment } from '../fragments/userAuthFragments';
|
|
2
3
|
import { emailFragment, phoneFragment } from '../fragments/otherFragments';
|
|
3
4
|
import { plusFragment, userFragment, userPersonaFragment } from '../fragments/userFragments';
|
|
4
|
-
import { authFragment } from '../fragments/authFragments';
|
|
5
5
|
|
|
6
|
-
const signInResultText = `...
|
|
6
|
+
const signInResultText = `...userAuthFragment
|
|
7
7
|
|
|
8
8
|
user {
|
|
9
9
|
...userFragment
|
|
@@ -27,7 +27,7 @@ const signInResultText = `...authFragment
|
|
|
27
27
|
}`;
|
|
28
28
|
|
|
29
29
|
const signInFragments = `
|
|
30
|
-
${
|
|
30
|
+
${userAuthFragment}
|
|
31
31
|
${userFragment}
|
|
32
32
|
${plusFragment}
|
|
33
33
|
${emailFragment}
|
|
@@ -142,19 +142,6 @@ mutation signIn (
|
|
|
142
142
|
${signInFragments}
|
|
143
143
|
`;
|
|
144
144
|
|
|
145
|
-
export const signInWithGoogleMtn = gql`
|
|
146
|
-
mutation signInWithGoogle (
|
|
147
|
-
$oauthToken: String!
|
|
148
|
-
) {
|
|
149
|
-
signInWithGoogle (
|
|
150
|
-
oauthToken: $oauthToken
|
|
151
|
-
) {
|
|
152
|
-
${signInResultText}
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
${signInFragments}
|
|
156
|
-
`;
|
|
157
|
-
|
|
158
145
|
export const signInWithDiscordMtn = gql`
|
|
159
146
|
mutation signInWithDiscord (
|
|
160
147
|
$oauthToken: String!
|
|
@@ -168,21 +155,6 @@ mutation signInWithDiscord (
|
|
|
168
155
|
${signInFragments}
|
|
169
156
|
`;
|
|
170
157
|
|
|
171
|
-
export const signInWithAppleMtn = gql`
|
|
172
|
-
mutation signInWithApple (
|
|
173
|
-
$code: String!
|
|
174
|
-
$idToken: String!
|
|
175
|
-
) {
|
|
176
|
-
signInWithApple (
|
|
177
|
-
code: $code
|
|
178
|
-
idToken: $idToken
|
|
179
|
-
) {
|
|
180
|
-
${signInResultText}
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
${signInFragments}
|
|
184
|
-
`;
|
|
185
|
-
|
|
186
158
|
export const changePasswordMtn = gql`
|
|
187
159
|
mutation changePassword (
|
|
188
160
|
$currentPassword: String!
|
|
@@ -4,13 +4,16 @@ import { aiChatFragment, aiChatMessageFragment } from '../fragments/aiChatFragme
|
|
|
4
4
|
export const aiChatQry = gql`
|
|
5
5
|
query aiChat (
|
|
6
6
|
$aiChatId: GenericID!
|
|
7
|
+
$limit: Int
|
|
7
8
|
) {
|
|
8
9
|
aiChat (
|
|
9
10
|
aiChatId: $aiChatId
|
|
10
11
|
) {
|
|
11
12
|
...aiChatFragment
|
|
12
13
|
|
|
13
|
-
messages
|
|
14
|
+
messages (
|
|
15
|
+
limit: $limit
|
|
16
|
+
) {
|
|
14
17
|
...aiChatMessageFragment
|
|
15
18
|
}
|
|
16
19
|
}
|
|
@@ -39,3 +42,24 @@ query aiChatMessages (
|
|
|
39
42
|
|
|
40
43
|
${aiChatMessageFragment}
|
|
41
44
|
`;
|
|
45
|
+
|
|
46
|
+
export const aiChatsQry = gql`
|
|
47
|
+
query aiChats (
|
|
48
|
+
$filter: AIChatsFilter
|
|
49
|
+
$cursor: Cursor
|
|
50
|
+
$after: Boolean!
|
|
51
|
+
$limit: Int!
|
|
52
|
+
) {
|
|
53
|
+
aiChats (
|
|
54
|
+
filter: $filter
|
|
55
|
+
cursor: $cursor
|
|
56
|
+
after: $after
|
|
57
|
+
limit: $limit
|
|
58
|
+
) {
|
|
59
|
+
cursor
|
|
60
|
+
...aiChatFragment
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
${aiChatFragment}
|
|
65
|
+
`;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { gql } from 'graphql-tag';
|
|
2
|
+
import { accountFragment } from '../fragments/accountFragments';
|
|
3
|
+
import { journalEntryFragment } from '../fragments/journalFragments';
|
|
4
|
+
|
|
5
|
+
export const journalEntriesQry = gql`
|
|
6
|
+
query journalEntries (
|
|
7
|
+
$organizationId: GenericID!
|
|
8
|
+
$cursor: Cursor
|
|
9
|
+
$after: Boolean!
|
|
10
|
+
$limit: Int!
|
|
11
|
+
) {
|
|
12
|
+
journalEntries (
|
|
13
|
+
organizationId: $organizationId
|
|
14
|
+
cursor: $cursor
|
|
15
|
+
after: $after
|
|
16
|
+
limit: $limit
|
|
17
|
+
) {
|
|
18
|
+
...journalEntryFragment
|
|
19
|
+
|
|
20
|
+
account {
|
|
21
|
+
...accountFragment
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
${accountFragment}
|
|
27
|
+
${journalEntryFragment}
|
|
28
|
+
`;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { gql } from 'graphql-tag';
|
|
2
|
+
import { organizationFragment, organizationRelationshipFragment } from '../fragments/organizationFragments';
|
|
3
|
+
|
|
4
|
+
// Always use organizationRelationship() instead
|
|
5
|
+
|
|
6
|
+
// export const organizationQry = gql`
|
|
7
|
+
// query organization (
|
|
8
|
+
// $organizationId: GenericID!
|
|
9
|
+
// ) {
|
|
10
|
+
// organization (
|
|
11
|
+
// organizationId: $organizationId
|
|
12
|
+
// ) {
|
|
13
|
+
// ...organizationFragment
|
|
14
|
+
// }
|
|
15
|
+
// }
|
|
16
|
+
|
|
17
|
+
// ${organizationFragment}
|
|
18
|
+
// `;
|
|
19
|
+
|
|
20
|
+
export const organizationRelationshipQry = gql`
|
|
21
|
+
query organizationRelationship (
|
|
22
|
+
$organizationId: GenericID!
|
|
23
|
+
) {
|
|
24
|
+
organizationRelationship (
|
|
25
|
+
organizationId: $organizationId
|
|
26
|
+
) {
|
|
27
|
+
...organizationRelationshipFragment
|
|
28
|
+
|
|
29
|
+
organization {
|
|
30
|
+
...organizationFragment
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
${organizationFragment}
|
|
36
|
+
${organizationRelationshipFragment}
|
|
37
|
+
`;
|
|
38
|
+
|
|
39
|
+
export const myOrganizationsQry = gql`
|
|
40
|
+
query myOrganizations {
|
|
41
|
+
myOrganizations {
|
|
42
|
+
...organizationRelationshipFragment
|
|
43
|
+
|
|
44
|
+
organization {
|
|
45
|
+
...organizationFragment
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
${organizationFragment}
|
|
51
|
+
${organizationRelationshipFragment}
|
|
52
|
+
`;
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { getENVVariable } from '@jsb188/app';
|
|
2
|
-
import type { ServerErrorObj, SimpleErrorType } from '@jsb188/app/types/app';
|
|
2
|
+
import type { ServerErrorObj, SimpleErrorType } from '@jsb188/app/types/app.d';
|
|
3
|
+
import { normalizeServerError } from '@jsb188/app/utils/api';
|
|
3
4
|
import { delay } from '@jsb188/app/utils/logic';
|
|
4
5
|
import { isServerErrorGQL } from '@jsb188/graphql/utils';
|
|
5
6
|
import { useConnectedToServerValue, useFragmentObserverValue, useQueryObserverValue, useScreenIsFocusedValue, useSetFragmentObserver, useSetQueryObserver } from '@jsb188/react/states';
|
|
6
7
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
7
|
-
import { checkDataCompleteness, fetchCachedData, loadDataFromCache, loadFragment, makeVariablesKey, removeStaleCache } from '../cache
|
|
8
|
+
import { checkDataCompleteness, fetchCachedData, loadDataFromCache, loadFragment, makeVariablesKey, removeStaleCache } from '../cache';
|
|
8
9
|
import { QUERY_EXPIRE_TIMES } from '../cache/config';
|
|
9
|
-
import type { AnyModalPopUpFn, GraphQLHandlers, GraphQLQueryOptions, OnCompletedGQLFn, OnErrorGQLFn, UpdateDataObserverArgs, UpdateObserversFn } from '../types
|
|
10
|
-
import { graphqlRequest } from '
|
|
10
|
+
import type { AnyModalPopUpFn, GraphQLHandlers, GraphQLQueryOptions, OnCompletedGQLFn, OnErrorGQLFn, UpdateDataObserverArgs, UpdateObserversFn } from '../types';
|
|
11
|
+
import { graphqlRequest } from '../client/request';
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* Types; mutation
|
|
15
16
|
*/
|
|
16
17
|
|
|
18
|
+
export type GraphQLMutationFn = (graphqlOptions?: GraphQLRequestOptions, triedCount?: number) => Promise<any>;
|
|
19
|
+
|
|
17
20
|
type GraphQLMutationOptions = Partial<{
|
|
18
21
|
checkMountedBeforeCallback: boolean;
|
|
19
22
|
authToken: string;
|
|
@@ -34,7 +37,7 @@ type GraphQLMutationResult = {
|
|
|
34
37
|
};
|
|
35
38
|
|
|
36
39
|
type GraphQLMutation = [
|
|
37
|
-
|
|
40
|
+
GraphQLMutationFn,
|
|
38
41
|
GraphQLMutationResult,
|
|
39
42
|
GraphQLHandlers,
|
|
40
43
|
UpdateObserversFn,
|
|
@@ -56,6 +59,8 @@ type GraphQLQueryResult = {
|
|
|
56
59
|
error: ServerErrorObj | null;
|
|
57
60
|
refetch: () => void;
|
|
58
61
|
fetchMore: (obj: GraphQLRequestOptions) => Promise<any>;
|
|
62
|
+
queryName: string;
|
|
63
|
+
queryKey: string;
|
|
59
64
|
variablesKey: string;
|
|
60
65
|
updatedCount: number;
|
|
61
66
|
updateObservers: UpdateObserversFn;
|
|
@@ -533,7 +538,7 @@ export function useQuery(
|
|
|
533
538
|
// Multiple queries can be chained using this hook,
|
|
534
539
|
// but only the first query is used for tracking reactivity.
|
|
535
540
|
const queryName = query.definitions?.[0]?.name?.value;
|
|
536
|
-
const queryKey = queryName
|
|
541
|
+
const queryKey = `#${queryName}:${variablesKey}`;
|
|
537
542
|
|
|
538
543
|
const tracker = useRef({
|
|
539
544
|
unique: null as string | null,
|
|
@@ -751,8 +756,17 @@ export function useQuery(
|
|
|
751
756
|
return doQuery();
|
|
752
757
|
}, [doQuery]);
|
|
753
758
|
|
|
754
|
-
const fetchMore = useCallback((obj: GraphQLRequestOptions): Promise<any> => {
|
|
755
|
-
|
|
759
|
+
const fetchMore = useCallback(async(obj: GraphQLRequestOptions): Promise<any> => {
|
|
760
|
+
const result = await doQuery(obj?.variables);
|
|
761
|
+
|
|
762
|
+
if (result.error) {
|
|
763
|
+
return {
|
|
764
|
+
...result,
|
|
765
|
+
error: normalizeServerError(result.error),
|
|
766
|
+
};
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
return result;
|
|
756
770
|
}, [doQuery]);
|
|
757
771
|
|
|
758
772
|
return {
|
|
@@ -764,6 +778,8 @@ export function useQuery(
|
|
|
764
778
|
cacheMap,
|
|
765
779
|
eagerFragmentKeyMap,
|
|
766
780
|
),
|
|
781
|
+
queryName,
|
|
782
|
+
queryKey,
|
|
767
783
|
variablesKey,
|
|
768
784
|
refetch,
|
|
769
785
|
fetchMore,
|