@jsb188/graphql 1.0.1 → 1.0.2

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 CHANGED
@@ -46,11 +46,3 @@ export const PARTIALS_MAP = {
46
46
  chatStatusPartial: 'chatFragment',
47
47
  userPartial: 'userFragment',
48
48
  } as Record<string, string>;
49
-
50
- /**
51
- * Set up config, so the package can use app's variables
52
- */
53
-
54
- export function configGraphQL(_rules: any) {
55
- // Do something with rules and partials map here
56
- }
package/cache/utils.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ServerErrorObj } from '../types.d';
1
+ import type { ServerErrorObj } from '@jsb188/app/types/app';
2
2
 
3
3
  const TIME_TRACKER = new Map();
4
4
 
@@ -0,0 +1,16 @@
1
+ export const aiChatFragment = `fragment aiChatFragment on AIChat {
2
+ id
3
+ summary
4
+ createdAt
5
+ updatedAt
6
+ }`;
7
+
8
+ export const aiChatMessageFragment = `fragment aiChatMessageFragment on AIChatMessage {
9
+ id
10
+ userId
11
+ cursor
12
+ text
13
+ photoUri
14
+ finished
15
+ at
16
+ }`;
@@ -0,0 +1,16 @@
1
+ import { gql } from 'graphql-tag';
2
+ import { aiChatFragment } from '../fragments/aiChatFragments';
3
+
4
+ export const startAIChatMtn = gql`
5
+ mutation startAIChat (
6
+ $text: String!
7
+ ) {
8
+ startAIChat (
9
+ text: $text
10
+ ) {
11
+ ...aiChatFragment
12
+ }
13
+ }
14
+
15
+ ${aiChatFragment}
16
+ `;
@@ -0,0 +1,29 @@
1
+ import { gql } from 'graphql-tag';
2
+ import { aiChatFragment, aiChatMessageFragment } from '../fragments/aiChatFragments';
3
+
4
+ export const aiChatQry = gql`
5
+ query aiChat (
6
+ $aiChatId: GenericID!
7
+ $cursor: Cursor
8
+ $after: Boolean!
9
+ $limit: Int!
10
+ ) {
11
+ aiChat (
12
+ aiChatId: $aiChatId
13
+ ) {
14
+ ...aiChatFragment
15
+
16
+ messages (
17
+ cursor: $cursor
18
+ after: $after
19
+ limit: $limit
20
+ ) {
21
+ cursor
22
+ ...aiChatMessageFragment
23
+ }
24
+ }
25
+ }
26
+
27
+ ${aiChatFragment}
28
+ ${aiChatMessageFragment}
29
+ `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsb188/graphql",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "GraphQL client for react, using recoil",
5
5
  "license": "ISC",
6
6
  "author": "jsb188",
@@ -10,16 +10,19 @@
10
10
  "exports": {
11
11
  ".": "./main.ts",
12
12
  "./fragments/auth": "./gql/fragments/authFragments.ts",
13
+ "./fragments/aiChat": "./gql/fragments/aiChatFragments.ts",
13
14
  "./fragments/billing": "./gql/fragments/billingFragments.ts",
14
15
  "./fragments/card": "./gql/fragments/cardFragments.ts",
15
16
  "./fragments/chat": "./gql/fragments/chatFragments.ts",
16
17
  "./fragments/other": "./gql/fragments/otherFragments.ts",
17
18
  "./fragments/user": "./gql/fragments/userFragments.ts",
19
+ "./mutations/aiChat": "./gql/mutations/aiChatMutations.ts",
18
20
  "./mutations/auth": "./gql/mutations/authMutations.ts",
19
21
  "./mutations/billing": "./gql/mutations/billingMutations.ts",
20
22
  "./mutations/chat": "./gql/mutations/chatMutations.ts",
21
23
  "./mutations/other": "./gql/mutations/otherMutations.ts",
22
24
  "./mutations/user": "./gql/mutations/userMutations.ts",
25
+ "./queries/aiChat": "./gql/queries/aiChatQueries.ts",
23
26
  "./queries/auth": "./gql/queries/authQueries.ts",
24
27
  "./queries/billing": "./gql/queries/billingQueries.ts",
25
28
  "./queries/card": "./gql/queries/cardQueries.ts",
@@ -33,6 +36,7 @@
33
36
  "test": "echo \"Error: no test specified\" && exit 1"
34
37
  },
35
38
  "dependencies": {
36
- "graphql-tag": "^2.12.6"
39
+ "graphql-tag": "^2.12.6",
40
+ "@jsb188/app": "^1.0.2"
37
41
  }
38
42
  }
package/types.d.ts CHANGED
@@ -1,18 +1,4 @@
1
-
2
- export interface ServerErrorObj {
3
- statusCode: number;
4
- errorCode: string;
5
- errorValue?: string;
6
- iconName?: string;
7
- title: string;
8
- message: string;
9
- }
10
-
11
- export interface SimpleErrorType {
12
- iconName?: string;
13
- title?: string;
14
- message: string;
15
- }
1
+ import type { ServerErrorObj, SimpleErrorType } from '@jsb188/app/types/app';
16
2
 
17
3
  export interface APIRequestOutput {
18
4
  aborted?: boolean;
@@ -26,19 +12,46 @@ export interface GraphQLHandlers {
26
12
  refetch: () => void;
27
13
  }
28
14
 
15
+ export interface UpdateDataObserverArgs {
16
+ queryId?: string | null;
17
+ fragmentIds?: (string | null)[];
18
+ forceRefetch?: boolean;
19
+ }
20
+
21
+ export type AnyModalPopUpFn = (data: any, err?: ServerErrorObj) => void;
29
22
  export type UpdateObserversFn = (args: UpdateDataObserverArgs) => void;
30
23
  export type OnCompletedGQLFn = (data: any, error: ServerErrorObj | null, variables: any) => void;
31
24
  export type OnErrorGQLFn = (error: ServerErrorObj | null, variables: any) => void;
32
25
 
33
- // Params for most GraphQL hooks
26
+ // GraphQL query hook options
27
+
28
+ export interface GraphQLQueryOptions {
29
+ name?: string;
30
+ eagerFragmentKeyMap?: any;
31
+ retryCount?: number;
32
+ variables?: Record<string, any> | null;
33
+ cacheMap?: any;
34
+ skip?: boolean;
35
+ testMode?: boolean;
36
+ openModalPopUp?: AnyModalPopUpFn | null;
37
+ onCompleted?: OnCompletedGQLFn
38
+ onError?: OnErrorGQLFn;
39
+ }
40
+
41
+ // Params for most GraphQL (query) hooks
42
+
43
+ export type UseQueryParams = Omit<GraphQLQueryOptions, 'name' | 'retryCount' | 'cacheMap'>;
34
44
 
35
- export type UseGraphQLParams = Partial<{
45
+ // Params for most GraphQL (mutation) hooks
46
+
47
+ export type UseMutationParams = Partial<{
36
48
  onCompleted: OnCompletedGQLFn;
37
49
  onError: OnErrorGQLFn;
38
50
  }>;
39
51
 
52
+
40
53
  // Params for most GraphQL hooks with these options
41
54
 
42
- export type UseGraphQLParamsExtra = Partial<{
55
+ export type UseMutationParamsExtra = Partial<{
43
56
  checkMountedBeforeCallback?: boolean;
44
- }> & UseGraphQLParams;
57
+ }> & UseMutationParams;