@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/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: any) => void;
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
- // GraphQL query hook options
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 type { ServerErrorObj } from '@jsb188/app/types/app';
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
@@ -1,2 +0,0 @@
1
- export * from './cache/';
2
- export * from './cache/config';
File without changes