@jsb188/graphql 1.1.5 → 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.
Files changed (39) hide show
  1. package/cache/config.ts +12 -5
  2. package/cache/index.ts +258 -109
  3. package/gql/fragments/actionFragments.ts +16 -0
  4. package/gql/fragments/logFragments.ts +72 -2
  5. package/gql/fragments/organizationFragments.ts +64 -5
  6. package/gql/fragments/otherFragments.ts +10 -8
  7. package/gql/fragments/productFragments.ts +63 -0
  8. package/gql/fragments/reportFragments.ts +48 -0
  9. package/gql/fragments/storageFragments.ts +11 -0
  10. package/gql/mutations/accountMutations.ts +10 -0
  11. package/gql/mutations/authMutations.ts +11 -16
  12. package/gql/mutations/index.ts +2 -1
  13. package/gql/mutations/logMutations.ts +20 -6
  14. package/gql/mutations/organizationMutations.ts +42 -0
  15. package/gql/mutations/storageMutations.ts +36 -0
  16. package/gql/mutations/userAuthMutations.ts +0 -12
  17. package/gql/queries/aiChatQueries.ts +3 -0
  18. package/gql/queries/index.ts +6 -0
  19. package/gql/queries/logQueries.ts +60 -11
  20. package/gql/queries/organizationQueries.ts +61 -1
  21. package/gql/queries/productQueries.ts +70 -0
  22. package/gql/queries/reportQueries.ts +66 -0
  23. package/hooks/index.ts +146 -45
  24. package/hooks/use-account-mtn.ts +26 -1
  25. package/hooks/use-aiChat-mtn.ts +17 -1
  26. package/hooks/use-aiChat-qry.ts +19 -10
  27. package/hooks/use-auth-mtn.ts +25 -2
  28. package/hooks/use-log-mtn.ts +4 -4
  29. package/hooks/use-log-qry.ts +47 -16
  30. package/hooks/use-organization-mtn.ts +105 -0
  31. package/hooks/use-organization-qry.ts +119 -15
  32. package/hooks/use-product-qry.ts +109 -0
  33. package/hooks/use-report-qry.ts +69 -0
  34. package/hooks/use-storage-mtn.ts +56 -0
  35. package/hooks/use-storage-qry.ts +21 -0
  36. package/package.json +14 -11
  37. package/sse.ts +11 -0
  38. package/gql/mutations/otherMutations.ts +0 -46
  39. package/gql/queries/otherQueries.ts +0 -12
@@ -0,0 +1,69 @@
1
+ import type { ReportsFilterArgs, ReportsSortEnum } from '@jsb188/mday/types/report.d';
2
+ import { useQuery, useReactiveFragment } from '../client';
3
+ import { availableReportsQry, reportsQry } from '../gql/queries/reportQueries';
4
+ import type { UseQueryParams } from '../types';
5
+
6
+ /**
7
+ * Get reactive report fragment
8
+ */
9
+
10
+ export function useReactiveReportFragment(reportId: string, currentData?: any, queryCount?: number) {
11
+ return useReactiveFragment(
12
+ currentData,
13
+ [
14
+ `$reportFragment:${reportId}`,
15
+ ],
16
+ queryCount,
17
+ );
18
+ }
19
+
20
+ /**
21
+ * Fetch list of reports by type and period
22
+ */
23
+
24
+ export function useReports(
25
+ variables: {
26
+ organizationId: string;
27
+ filter: ReportsFilterArgs;
28
+ sort: ReportsSortEnum;
29
+ },
30
+ params: UseQueryParams = {},
31
+ ) {
32
+
33
+ const { organizationId, filter } = variables;
34
+ const { skip, ...restParams } = params;
35
+ const { data, ...rest } = useQuery(reportsQry, {
36
+ variables,
37
+ skip: skip || !organizationId || !filter,
38
+ ...restParams,
39
+ });
40
+
41
+ return {
42
+ reports: data?.reports,
43
+ ...rest
44
+ };
45
+ }
46
+
47
+ /**
48
+ * Fetch list of available reports statuses
49
+ */
50
+
51
+ export function useAvailableReports(
52
+ organizationId: string | null,
53
+ params: UseQueryParams = {},
54
+ ) {
55
+
56
+ const { skip, ...restParams } = params;
57
+ const { data, ...rest } = useQuery(availableReportsQry, {
58
+ variables: {
59
+ organizationId,
60
+ },
61
+ skip: skip || !organizationId,
62
+ ...restParams,
63
+ });
64
+
65
+ return {
66
+ availableReports: data?.availableReports,
67
+ ...rest
68
+ };
69
+ }
@@ -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.5",
3
+ "version": "1.1.7",
4
4
  "description": "GraphQL client for react, using recoil",
5
5
  "license": "ISC",
6
6
  "author": "jsb188",
@@ -14,23 +14,26 @@
14
14
  "./fragments/log": "./gql/fragments/logFragments.ts",
15
15
  "./fragments/organization": "./gql/fragments/organizationFragments.ts",
16
16
  "./fragments/other": "./gql/fragments/otherFragments.ts",
17
+ "./fragments/product": "./gql/fragments/productFragments.ts",
18
+ "./fragments/report": "./gql/fragments/reportFragments.ts",
19
+ "./fragments/storage": "./gql/fragments/storageFragments.ts",
17
20
  "./hooks": "./hooks/",
21
+ "./hooks/use-action-qry": "./hooks/use-action-qry.ts",
18
22
  "./hooks/use-aiChat-qry": "./hooks/use-aiChat-qry.ts",
19
23
  "./hooks/use-app-qry": "./hooks/use-app-qry.ts",
20
24
  "./hooks/use-log-qry": "./hooks/use-log-qry.ts",
21
25
  "./hooks/use-organization-qry": "./hooks/use-organization-qry.ts",
26
+ "./hooks/use-product-qry": "./hooks/use-product-qry.ts",
27
+ "./hooks/use-report-qry": "./hooks/use-report-qry.ts",
28
+ "./hooks/use-storage-qry": "./hooks/use-storage-qry.ts",
22
29
  "./hooks/use-account-mtn": "./hooks/use-account-mtn.ts",
23
30
  "./hooks/use-aiChat-mtn": "./hooks/use-aiChat-mtn.ts",
24
31
  "./hooks/use-auth-mtn": "./hooks/use-auth-mtn.ts",
25
32
  "./hooks/use-log-mtn": "./hooks/use-log-mtn.ts",
33
+ "./hooks/use-organization-mtn": "./hooks/use-organization-mtn.ts",
34
+ "./hooks/use-storage-mtn": "./hooks/use-storage-mtn.ts",
26
35
  "./mutations": "./gql/mutations/index.ts",
27
- "./queries/aiChat": "./gql/queries/aiChatQueries.ts",
28
- "./queries/app": "./gql/queries/appQueries.ts",
29
- "./queries/billing": "./gql/queries/billingQueries.ts",
30
- "./queries/log": "./gql/queries/logQueries.ts",
31
- "./queries/organization": "./gql/queries/organizationQueries.ts",
32
- "./queries/other": "./gql/queries/otherQueries.ts",
33
- "./queries/user": "./gql/queries/userQueries.ts",
36
+ "./queries": "./gql/queries/index.ts",
34
37
  "./cache": "./cache/index.ts",
35
38
  "./client": "./client/index.ts",
36
39
  "./sse": "./sse.ts",
@@ -41,11 +44,11 @@
41
44
  "test": "echo \"Error: no test specified\" && exit 1"
42
45
  },
43
46
  "dependencies": {
44
- "graphql": "^16.10.0",
47
+ "graphql": "^16.11.0",
45
48
  "graphql-tag": "^2.12.6"
46
49
  },
47
50
  "peerDependencies": {
48
- "@jsb188/app": "1.1.5",
49
- "@jsb188/react": "1.1.5"
51
+ "@jsb188/app": "1.1.7",
52
+ "@jsb188/react": "1.1.7"
50
53
  }
51
54
  }
package/sse.ts CHANGED
@@ -42,6 +42,16 @@ function handleQueryConcat(payload: PublishPayload, updateObservers?: UpdateObse
42
42
  ) {
43
43
  addFragmentToCache(dataFragmentKey, data);
44
44
  const updatedList = isAppend ? [...currentList, [dataFragmentKey]] : [[dataFragmentKey], ...currentList];
45
+
46
+ // console.log('UPDATED !!!!')
47
+ // console.log('UPDATED !!!!')
48
+ // console.log('UPDATED !!!!')
49
+ // console.log('UPDATED !!!!')
50
+ // console.log(fragmentNamespace, {
51
+ // ...currentData?.[fragmentNamespace],
52
+ // data: updatedList
53
+ // });
54
+
45
55
  return {
46
56
  ...currentData,
47
57
  ...otherData,
@@ -111,6 +121,7 @@ function handleFragmentUpdate(payload: PublishPayload, updateObservers?: UpdateO
111
121
  */
112
122
 
113
123
  function handleSSEData(payload: PublishPayload, updateObservers?: UpdateObserversFn) {
124
+
114
125
  switch (payload.__type) {
115
126
  case 'CONNECTED':
116
127
  // Do nothing
@@ -1,46 +0,0 @@
1
- import { gql } from 'graphql-tag';
2
- import { alertFragment } from '../fragments/otherFragments';
3
-
4
- export const prepareFileUploadMtn = gql`
5
- mutation prepareFileUpload (
6
- $files: [FilePrepareInput]!
7
- ) {
8
- prepareFileUpload (
9
- files: $files
10
- ) {
11
- id
12
- fileName
13
- uri
14
- token
15
- }
16
- }
17
- `;
18
-
19
- export const finishFileUploadMtn = gql`
20
- mutation finishFileUpload (
21
- $fileIds: [GenericID]!
22
- ) {
23
- finishFileUpload (
24
- fileIds: $fileIds
25
- ) {
26
- id
27
- uri
28
- }
29
- }
30
- `;
31
-
32
- export const alertCallToActionMtn = gql`
33
- mutation alertCallToAction (
34
- $alertId: GenericID!
35
- $approve: Boolean!
36
- ) {
37
- alertCallToAction (
38
- alertId: $alertId
39
- approve: $approve
40
- ) {
41
- ...alertFragment
42
- }
43
- }
44
-
45
- ${alertFragment}
46
- `;
@@ -1,12 +0,0 @@
1
- import { gql } from 'graphql-tag';
2
- import { alertFragment } from '../fragments/otherFragments';
3
-
4
- export const alertsQry = gql`
5
- query alerts {
6
- alerts {
7
- ...alertFragment
8
- }
9
- }
10
-
11
- ${alertFragment}
12
- `;