@jsb188/graphql 1.0.2 → 1.1.1
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 +4 -1
- package/cache/index.ts +25 -33
- package/client/index.ts +2 -0
- package/client/request.ts +195 -0
- package/gql/fragments/accountAuthFragments.ts +16 -0
- package/gql/fragments/accountFragments.ts +10 -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/{authFragments.ts → userAuthFragments.ts} +1 -1
- package/gql/mutations/accountAuthMutations.ts +53 -0
- package/gql/mutations/aiChatMutations.ts +40 -2
- package/gql/mutations/journalMutations.ts +2 -0
- package/gql/mutations/{authMutations.ts → userAuthMutations.ts} +3 -3
- package/gql/queries/aiChatQueries.ts +42 -6
- package/gql/queries/journalQueries.ts +22 -0
- package/gql/queries/organizationQueries.ts +52 -0
- package/hooks/index.ts +791 -0
- package/hooks/use-aiChat-qry.ts +160 -0
- package/hooks/use-app-qry.ts +19 -0
- package/hooks/use-auth-mtn.ts +234 -0
- package/hooks/use-journal-qry.ts +49 -0
- package/hooks/use-organization-qry.ts +37 -0
- package/package.json +29 -10
- package/sse.ts +132 -0
- package/types.d.ts +24 -7
- package/{cache/utils.ts → utils.ts} +32 -1
- package/main.ts +0 -2
- /package/gql/queries/{authQueries.ts → appQueries.ts} +0 -0
package/types.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import type { ServerErrorObj, SimpleErrorType } from '@jsb188/app/types/app';
|
|
1
|
+
import type { ServerErrorObj, SimpleErrorType } from '@jsb188/app/types/app.d';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GraphQL API requests
|
|
5
|
+
*/
|
|
2
6
|
|
|
3
7
|
export interface APIRequestOutput {
|
|
4
8
|
aborted?: boolean;
|
|
@@ -18,12 +22,18 @@ export interface UpdateDataObserverArgs {
|
|
|
18
22
|
forceRefetch?: boolean;
|
|
19
23
|
}
|
|
20
24
|
|
|
25
|
+
/**
|
|
26
|
+
* GraphQL client handlers
|
|
27
|
+
*/
|
|
28
|
+
|
|
21
29
|
export type AnyModalPopUpFn = (data: any, err?: ServerErrorObj) => void;
|
|
22
30
|
export type UpdateObserversFn = (args: UpdateDataObserverArgs) => void;
|
|
23
|
-
export type OnCompletedGQLFn = (data: any, error: ServerErrorObj | null, variables
|
|
31
|
+
export type OnCompletedGQLFn = (data: any, error: ServerErrorObj | null, variables?: any) => void;
|
|
24
32
|
export type OnErrorGQLFn = (error: ServerErrorObj | null, variables: any) => void;
|
|
25
33
|
|
|
26
|
-
|
|
34
|
+
/**
|
|
35
|
+
* GraphQL query hook params
|
|
36
|
+
*/
|
|
27
37
|
|
|
28
38
|
export interface GraphQLQueryOptions {
|
|
29
39
|
name?: string;
|
|
@@ -39,19 +49,26 @@ export interface GraphQLQueryOptions {
|
|
|
39
49
|
}
|
|
40
50
|
|
|
41
51
|
// Params for most GraphQL (query) hooks
|
|
42
|
-
|
|
43
52
|
export type UseQueryParams = Omit<GraphQLQueryOptions, 'name' | 'retryCount' | 'cacheMap'>;
|
|
44
53
|
|
|
45
54
|
// Params for most GraphQL (mutation) hooks
|
|
46
|
-
|
|
47
55
|
export type UseMutationParams = Partial<{
|
|
48
56
|
onCompleted: OnCompletedGQLFn;
|
|
49
57
|
onError: OnErrorGQLFn;
|
|
50
58
|
}>;
|
|
51
59
|
|
|
52
|
-
|
|
53
60
|
// Params for most GraphQL hooks with these options
|
|
54
|
-
|
|
55
61
|
export type UseMutationParamsExtra = Partial<{
|
|
56
62
|
checkMountedBeforeCallback?: boolean;
|
|
57
63
|
}> & UseMutationParams;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Common query patterns
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
export type PaginationArgs = Partial<{
|
|
70
|
+
cursor: [number | null, number | null];
|
|
71
|
+
after: boolean;
|
|
72
|
+
limit: number;
|
|
73
|
+
doNotThrowError: boolean;
|
|
74
|
+
}>;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { getENVVariable } from '@jsb188/app';
|
|
2
|
+
import type { ServerErrorObj } from '@jsb188/app/types/app.d';
|
|
2
3
|
|
|
3
4
|
const TIME_TRACKER = new Map();
|
|
4
5
|
|
|
@@ -54,3 +55,33 @@ export function isServerErrorGQL(apiResult: any): boolean {
|
|
|
54
55
|
apiResult?.error?.errorCode === 'network_error'
|
|
55
56
|
);
|
|
56
57
|
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Headers for all network requests
|
|
61
|
+
*/
|
|
62
|
+
|
|
63
|
+
export function apiRequestHeaders(authorization?: string | null, ipAddress?: string | null): Headers {
|
|
64
|
+
const headers: Record<string, string> = {
|
|
65
|
+
'Content-Type': 'application/json; charset=utf-8',
|
|
66
|
+
api_key: String(getENVVariable('GQL_API_KEY') || ''),
|
|
67
|
+
origin: String(getENVVariable('APP_URL') || ''),
|
|
68
|
+
'Access-Control-Allow-Origin': String(getENVVariable('APP_URL') || ''),
|
|
69
|
+
// recaptcha: ? // Not sure if we're going to do this later any more
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
if (!getENVVariable('IS_BROWSER')) {
|
|
73
|
+
headers.ssr = '1';
|
|
74
|
+
|
|
75
|
+
if (ipAddress) {
|
|
76
|
+
// Do not allow undefined or null, it becomes a String type
|
|
77
|
+
headers['x-ssr-ip'] = ipAddress;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
if (authorization) {
|
|
82
|
+
// Do not send undefined or null, it becomes a String type
|
|
83
|
+
headers.authorization = authorization;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return new Headers(headers);
|
|
87
|
+
}
|
package/main.ts
DELETED
|
File without changes
|