@jsb188/graphql 1.1.6 → 1.1.7
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 +1 -1
- package/cache/index.ts +12 -9
- package/gql/fragments/reportFragments.ts +1 -0
- package/gql/fragments/storageFragments.ts +11 -0
- package/gql/mutations/index.ts +1 -1
- package/gql/mutations/storageMutations.ts +36 -0
- package/gql/queries/reportQueries.ts +6 -0
- package/hooks/index.ts +18 -4
- package/hooks/use-report-qry.ts +1 -1
- package/hooks/use-storage-mtn.ts +56 -0
- package/hooks/use-storage-qry.ts +21 -0
- package/package.json +6 -3
- package/gql/mutations/otherMutations.ts +0 -29
package/cache/config.ts
CHANGED
package/cache/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { makeVariablesKey } from '@jsb188/app/utils/logic';
|
|
2
|
-
import { cloneArrayLike, mapArrayLikeObjects } from '@jsb188/app/utils/object';
|
|
2
|
+
import { cloneArrayLike, mapArrayLikeObjects, uniq } from '@jsb188/app/utils/object';
|
|
3
3
|
import type { UpdateObserversFn } from '../types.d';
|
|
4
4
|
import { PARTIALS_MAP, RULES } from './config';
|
|
5
5
|
|
|
@@ -40,7 +40,7 @@ function enforceArrayType(obj: any): any {
|
|
|
40
40
|
* Merge nested objects together
|
|
41
41
|
*/
|
|
42
42
|
|
|
43
|
-
|
|
43
|
+
function mergeNestedObjects(obj1: any, obj2: any) {
|
|
44
44
|
if (!obj1) {
|
|
45
45
|
return { ...obj2 };
|
|
46
46
|
}
|
|
@@ -63,7 +63,7 @@ export function mergeNestedObjects(obj1: any, obj2: any) {
|
|
|
63
63
|
* Make Object for fragment, omitting what you don't need
|
|
64
64
|
*/
|
|
65
65
|
|
|
66
|
-
function extractFragment(dataObj: any, innerSelection: any[]) {
|
|
66
|
+
function extractFragment(dataObj: any, innerSelection: any[], isTest?: boolean) {
|
|
67
67
|
if (innerSelection.length <= 1) {
|
|
68
68
|
return dataObj;
|
|
69
69
|
}
|
|
@@ -227,6 +227,7 @@ function mapSelections(data: any, innerSelections: any[], updatedKeys: string[]
|
|
|
227
227
|
// These are fragment spreads
|
|
228
228
|
const frgName = inner.name.value;
|
|
229
229
|
const frgMap = PARTIALS_MAP[frgName];
|
|
230
|
+
|
|
230
231
|
fragmentKey = `$${frgMap || frgName}:${data.id || 'none'}`;
|
|
231
232
|
|
|
232
233
|
} else if (inner.kind === 'Field' && inner.selectionSet && inner.selectionSet.selections?.length) {
|
|
@@ -269,7 +270,8 @@ function mapSelections(data: any, innerSelections: any[], updatedKeys: string[]
|
|
|
269
270
|
// console.log(extractFragment(data, innerSelections));
|
|
270
271
|
// }
|
|
271
272
|
|
|
272
|
-
|
|
273
|
+
const fragmentFromData = extractFragment(data, innerSelections);
|
|
274
|
+
FRAGMENTS.set(fragmentKey, mergeNestedObjects(currentData, fragmentFromData));
|
|
273
275
|
updatedKeys.push(fragmentKey);
|
|
274
276
|
|
|
275
277
|
return fragmentKey;
|
|
@@ -405,7 +407,6 @@ function makeCacheObject(data: any, selections: any[], variables?: any, cacheMap
|
|
|
405
407
|
// console.log(data);
|
|
406
408
|
// console.log(spreads);
|
|
407
409
|
// }
|
|
408
|
-
|
|
409
410
|
FRAGMENTS.set(spreadsFragmentKey, spreads);
|
|
410
411
|
}
|
|
411
412
|
}
|
|
@@ -983,7 +984,7 @@ export function resetQuery(queryId: string, forceRefetch?: boolean, updateObserv
|
|
|
983
984
|
export function updateFragment(
|
|
984
985
|
updateFragmentKey: string,
|
|
985
986
|
update: any | ((cache: any) => any),
|
|
986
|
-
|
|
987
|
+
replacementFragmentKey?: string | null,
|
|
987
988
|
doNotTriggerObserver?: boolean,
|
|
988
989
|
updateObservers?: UpdateObserversFn,
|
|
989
990
|
otherUpdatedFragmentKeys?: string[],
|
|
@@ -999,16 +1000,18 @@ export function updateFragment(
|
|
|
999
1000
|
}
|
|
1000
1001
|
|
|
1001
1002
|
const updatedObj = { ...cache, ...updateObj };
|
|
1003
|
+
|
|
1002
1004
|
FRAGMENTS.set(updateFragmentKey, updatedObj);
|
|
1005
|
+
console.dev('✅ FRAGMENT UPDATED ->', updateFragmentKey, updatedObj);
|
|
1003
1006
|
|
|
1004
|
-
if (
|
|
1005
|
-
FRAGMENTS.set(
|
|
1007
|
+
if (replacementFragmentKey && replacementFragmentKey !== updateFragmentKey) {
|
|
1008
|
+
FRAGMENTS.set(replacementFragmentKey, updatedObj);
|
|
1006
1009
|
}
|
|
1007
1010
|
|
|
1008
1011
|
if (!doNotTriggerObserver && updateObservers) {
|
|
1009
1012
|
let observingFragmentIds = [updateFragmentKey];
|
|
1010
1013
|
if (Array.isArray(otherUpdatedFragmentKeys)) {
|
|
1011
|
-
observingFragmentIds = observingFragmentIds.concat(otherUpdatedFragmentKeys);
|
|
1014
|
+
observingFragmentIds = uniq(observingFragmentIds.concat(otherUpdatedFragmentKeys));
|
|
1012
1015
|
}
|
|
1013
1016
|
|
|
1014
1017
|
updateObservers({
|
package/gql/mutations/index.ts
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { gql } from 'graphql-tag';
|
|
2
|
+
|
|
3
|
+
export const createSignedUploadUrlMtn = gql`
|
|
4
|
+
mutation createSignedUploadUrl (
|
|
5
|
+
$temporaryId: String!
|
|
6
|
+
$organizationId: GenericID!
|
|
7
|
+
$fileName: String!
|
|
8
|
+
$contentType: String!
|
|
9
|
+
$fileSize: Int!
|
|
10
|
+
$uploadIntent: StorageIntentObject!
|
|
11
|
+
) {
|
|
12
|
+
createSignedUploadUrl (
|
|
13
|
+
temporaryId: $temporaryId
|
|
14
|
+
organizationId: $organizationId
|
|
15
|
+
fileName: $fileName
|
|
16
|
+
contentType: $contentType
|
|
17
|
+
fileSize: $fileSize
|
|
18
|
+
uploadIntent: $uploadIntent
|
|
19
|
+
) {
|
|
20
|
+
signedUrl
|
|
21
|
+
fileUri
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
`;
|
|
25
|
+
|
|
26
|
+
export const deleteStorageFileMtn = gql`
|
|
27
|
+
mutation deleteStorageFile (
|
|
28
|
+
$organizationId: GenericID!
|
|
29
|
+
$fileUri: String!
|
|
30
|
+
) {
|
|
31
|
+
deleteStorageFile (
|
|
32
|
+
organizationId: $organizationId
|
|
33
|
+
fileUri: $fileUri
|
|
34
|
+
)
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { gql } from 'graphql-tag';
|
|
2
2
|
import { reportColumnDataFragment, reportFragment, reportAvailabilityFragment, reportRowDataFragment, reportSectionFragment } from '../fragments/reportFragments';
|
|
3
|
+
import { storageFileFragment } from '../fragments/storageFragments';
|
|
3
4
|
|
|
4
5
|
export const reportsQry = gql`
|
|
5
6
|
query reports (
|
|
@@ -17,6 +18,10 @@ query reports (
|
|
|
17
18
|
sections {
|
|
18
19
|
...reportSectionFragment
|
|
19
20
|
|
|
21
|
+
files {
|
|
22
|
+
...storageFileFragment
|
|
23
|
+
}
|
|
24
|
+
|
|
20
25
|
rows {
|
|
21
26
|
...reportRowDataFragment
|
|
22
27
|
|
|
@@ -41,6 +46,7 @@ query reports (
|
|
|
41
46
|
|
|
42
47
|
${reportFragment}
|
|
43
48
|
${reportSectionFragment}
|
|
49
|
+
${storageFileFragment}
|
|
44
50
|
${reportRowDataFragment}
|
|
45
51
|
${reportColumnDataFragment}
|
|
46
52
|
`;
|
package/hooks/index.ts
CHANGED
|
@@ -149,6 +149,7 @@ export function useWatchQuery(
|
|
|
149
149
|
|
|
150
150
|
if (qryTriggerTime) {
|
|
151
151
|
clearQueryResetStatus(queryName, variablesKey);
|
|
152
|
+
console.dev(`... (1) Query [${queryName}:${variablesKey}] is being force refetched via observer.`);
|
|
152
153
|
return [lastUpdatedCount + 1, true, qryTriggerTime];
|
|
153
154
|
}
|
|
154
155
|
}
|
|
@@ -172,6 +173,10 @@ export function useWatchQuery(
|
|
|
172
173
|
newUpdatedCount += 1;
|
|
173
174
|
}
|
|
174
175
|
|
|
176
|
+
if (forceRefetch) {
|
|
177
|
+
console.dev(`... (2) Query [${matchedQueryId}] is being force refetched via observer.`);
|
|
178
|
+
}
|
|
179
|
+
|
|
175
180
|
return [newUpdatedCount, forceRefetch, ''];
|
|
176
181
|
}
|
|
177
182
|
|
|
@@ -220,7 +225,7 @@ export function useReactiveFragment(
|
|
|
220
225
|
qryObsCount?: number | boolean,
|
|
221
226
|
otherCheck?: (latestData: any, updatedKeys: any[]) => boolean,
|
|
222
227
|
ignoreIDWarning?: boolean,
|
|
223
|
-
|
|
228
|
+
isTest?: boolean
|
|
224
229
|
) {
|
|
225
230
|
|
|
226
231
|
const fragmentObserver = useFragmentObserverValue();
|
|
@@ -332,8 +337,11 @@ export function useReactiveFragment(
|
|
|
332
337
|
}
|
|
333
338
|
|
|
334
339
|
const fragmentData = loadFragment(isMapped ? key[0] : key);
|
|
335
|
-
|
|
336
|
-
//
|
|
340
|
+
|
|
341
|
+
// if (isTest) {
|
|
342
|
+
// console.log('fragmentKey', key);
|
|
343
|
+
// console.log('fragmentData', fragmentData);
|
|
344
|
+
// }
|
|
337
345
|
|
|
338
346
|
if (fragmentData) {
|
|
339
347
|
if (isMapped) {
|
|
@@ -378,6 +386,12 @@ export function useReactiveFragment(
|
|
|
378
386
|
// }
|
|
379
387
|
// }, [updateQueryCount]);
|
|
380
388
|
|
|
389
|
+
// if (isTest) {
|
|
390
|
+
// console.log('dataId', dataId);
|
|
391
|
+
// console.log('1', changedData);
|
|
392
|
+
// console.log('2', data);
|
|
393
|
+
// }
|
|
394
|
+
|
|
381
395
|
return changedData.data ?? null;
|
|
382
396
|
}
|
|
383
397
|
|
|
@@ -863,7 +877,7 @@ export function useQuery(
|
|
|
863
877
|
timeThresh = QUERY_EXPIRE_TIMES[queryName] || QUERY_EXPIRE_TIMES.__default;
|
|
864
878
|
}
|
|
865
879
|
|
|
866
|
-
// console.log('>>', queryName, timeDiff, timeThresh);
|
|
880
|
+
// console.log('>>', queryName, timeDiff, timeThresh, timeDiff > timeThresh);
|
|
867
881
|
|
|
868
882
|
if (
|
|
869
883
|
tracker.current.init &&
|
package/hooks/use-report-qry.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { availableReportsQry, reportsQry } from '../gql/queries/reportQueries';
|
|
|
4
4
|
import type { UseQueryParams } from '../types';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
|
-
* Get reactive
|
|
7
|
+
* Get reactive report fragment
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
export function useReactiveReportFragment(reportId: string, currentData?: any, queryCount?: number) {
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { UseMutationParams } from '@jsb188/graphql/types.d';
|
|
2
|
+
import { OpenModalPopUpFn } from '@jsb188/react/states';
|
|
3
|
+
import { updateFragment } from '../cache/index';
|
|
4
|
+
import { createSignedUploadUrlMtn, deleteStorageFileMtn } from '../gql/mutations/storageMutations';
|
|
5
|
+
import { useMutation } from './index';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Get signed URL for file uploads
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export function useCreateSignedUploadUrl(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
12
|
+
|
|
13
|
+
const [createSignedUploadUrl, mtnValues, mtnHandlers, updateObservers] = useMutation(
|
|
14
|
+
createSignedUploadUrlMtn,
|
|
15
|
+
{
|
|
16
|
+
openModalPopUp,
|
|
17
|
+
...params,
|
|
18
|
+
},
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
return {
|
|
22
|
+
createSignedUploadUrl,
|
|
23
|
+
updateObservers,
|
|
24
|
+
...mtnValues,
|
|
25
|
+
...mtnHandlers,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Delete a storage file
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
export function useDeleteStorageFile(params: UseMutationParams = {}, openModalPopUp?: OpenModalPopUpFn) {
|
|
34
|
+
|
|
35
|
+
const { onCompleted, ...rest } = params;
|
|
36
|
+
const [deleteStorageFile, mtnValues, mtnHandlers, updateObservers] = useMutation(
|
|
37
|
+
deleteStorageFileMtn,
|
|
38
|
+
{
|
|
39
|
+
openModalPopUp,
|
|
40
|
+
onCompleted: (data, dataMtnValues, variables) => {
|
|
41
|
+
if (data?.deleteStorageFile) {
|
|
42
|
+
updateFragment(`$storageFileFragment:${variables.fileUri}`, { __deleted: true }, null, false, updateObservers);
|
|
43
|
+
}
|
|
44
|
+
onCompleted?.(data, dataMtnValues, variables);
|
|
45
|
+
},
|
|
46
|
+
...rest,
|
|
47
|
+
},
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
return {
|
|
51
|
+
deleteStorageFile,
|
|
52
|
+
updateObservers,
|
|
53
|
+
...mtnValues,
|
|
54
|
+
...mtnHandlers,
|
|
55
|
+
};
|
|
56
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { useReactiveFragment } from '../client';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get reactive log fragment
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export function useReactiveStorageFragment(storageId: string, currentData?: any, queryCount?: number) {
|
|
8
|
+
return useReactiveFragment(
|
|
9
|
+
currentData,
|
|
10
|
+
[
|
|
11
|
+
`$storageFileFragment:${storageId}`,
|
|
12
|
+
|
|
13
|
+
// By having the second paramter as null, we only observe the reactive changes without setting the data
|
|
14
|
+
// [`$logArableFragment:${storageId}`, null],
|
|
15
|
+
|
|
16
|
+
// This is not needed because $logEntryFragment has spread data
|
|
17
|
+
// [`$accountFragment:${storageId}`, 'account']
|
|
18
|
+
],
|
|
19
|
+
queryCount,
|
|
20
|
+
);
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsb188/graphql",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "GraphQL client for react, using recoil",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "jsb188",
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
"./fragments/other": "./gql/fragments/otherFragments.ts",
|
|
17
17
|
"./fragments/product": "./gql/fragments/productFragments.ts",
|
|
18
18
|
"./fragments/report": "./gql/fragments/reportFragments.ts",
|
|
19
|
+
"./fragments/storage": "./gql/fragments/storageFragments.ts",
|
|
19
20
|
"./hooks": "./hooks/",
|
|
20
21
|
"./hooks/use-action-qry": "./hooks/use-action-qry.ts",
|
|
21
22
|
"./hooks/use-aiChat-qry": "./hooks/use-aiChat-qry.ts",
|
|
@@ -24,11 +25,13 @@
|
|
|
24
25
|
"./hooks/use-organization-qry": "./hooks/use-organization-qry.ts",
|
|
25
26
|
"./hooks/use-product-qry": "./hooks/use-product-qry.ts",
|
|
26
27
|
"./hooks/use-report-qry": "./hooks/use-report-qry.ts",
|
|
28
|
+
"./hooks/use-storage-qry": "./hooks/use-storage-qry.ts",
|
|
27
29
|
"./hooks/use-account-mtn": "./hooks/use-account-mtn.ts",
|
|
28
30
|
"./hooks/use-aiChat-mtn": "./hooks/use-aiChat-mtn.ts",
|
|
29
31
|
"./hooks/use-auth-mtn": "./hooks/use-auth-mtn.ts",
|
|
30
32
|
"./hooks/use-log-mtn": "./hooks/use-log-mtn.ts",
|
|
31
33
|
"./hooks/use-organization-mtn": "./hooks/use-organization-mtn.ts",
|
|
34
|
+
"./hooks/use-storage-mtn": "./hooks/use-storage-mtn.ts",
|
|
32
35
|
"./mutations": "./gql/mutations/index.ts",
|
|
33
36
|
"./queries": "./gql/queries/index.ts",
|
|
34
37
|
"./cache": "./cache/index.ts",
|
|
@@ -45,7 +48,7 @@
|
|
|
45
48
|
"graphql-tag": "^2.12.6"
|
|
46
49
|
},
|
|
47
50
|
"peerDependencies": {
|
|
48
|
-
"@jsb188/app": "1.1.
|
|
49
|
-
"@jsb188/react": "1.1.
|
|
51
|
+
"@jsb188/app": "1.1.7",
|
|
52
|
+
"@jsb188/react": "1.1.7"
|
|
50
53
|
}
|
|
51
54
|
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { gql } from 'graphql-tag';
|
|
2
|
-
|
|
3
|
-
export const prepareFileUploadMtn = gql`
|
|
4
|
-
mutation prepareFileUpload (
|
|
5
|
-
$files: [FilePrepareInput]!
|
|
6
|
-
) {
|
|
7
|
-
prepareFileUpload (
|
|
8
|
-
files: $files
|
|
9
|
-
) {
|
|
10
|
-
id
|
|
11
|
-
fileName
|
|
12
|
-
uri
|
|
13
|
-
token
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
`;
|
|
17
|
-
|
|
18
|
-
export const finishFileUploadMtn = gql`
|
|
19
|
-
mutation finishFileUpload (
|
|
20
|
-
$fileIds: [GenericID]!
|
|
21
|
-
) {
|
|
22
|
-
finishFileUpload (
|
|
23
|
-
fileIds: $fileIds
|
|
24
|
-
) {
|
|
25
|
-
id
|
|
26
|
-
uri
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
`;
|