@jsb188/graphql 1.0.0 → 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
@@ -45,12 +45,4 @@ export const PARTIALS_MAP = {
45
45
  chatPartial: 'chatFragment',
46
46
  chatStatusPartial: 'chatFragment',
47
47
  userPartial: 'userFragment',
48
- };
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
- }
48
+ } as Record<string, string>;
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
+ `;
@@ -188,10 +188,38 @@ mutation changePassword (
188
188
  $currentPassword: String!
189
189
  $password: String!
190
190
  $passwordRepeat: String!
191
+ $token: Token
191
192
  ) {
192
193
  changePassword (
193
194
  currentPassword: $currentPassword
194
195
  password: $password
195
196
  passwordRepeat: $passwordRepeat
197
+ token: $token
198
+ )
199
+ }`;
200
+
201
+ export const requestTokenizedEmailMtn = gql`
202
+ mutation requestTokenizedEmail (
203
+ $email: String!
204
+ $requestType: TokenType!
205
+ ) {
206
+ requestTokenizedEmail (
207
+ email: $email
208
+ requestType: $requestType
196
209
  )
197
210
  }`;
211
+
212
+ export const consumeTokenMtn = gql`
213
+ mutation consumeToken (
214
+ $token: Token!
215
+ $expected: TokenType
216
+ ) {
217
+ consumeToken (
218
+ token: $token
219
+ expected: $expected
220
+ ) {
221
+ id
222
+ success
223
+ value
224
+ }
225
+ }`;
@@ -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.0",
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,6 +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;
25
+
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'>;
44
+
45
+ // Params for most GraphQL (mutation) hooks
46
+
47
+ export type UseMutationParams = Partial<{
48
+ onCompleted: OnCompletedGQLFn;
49
+ onError: OnErrorGQLFn;
50
+ }>;
51
+
52
+
53
+ // Params for most GraphQL hooks with these options
54
+
55
+ export type UseMutationParamsExtra = Partial<{
56
+ checkMountedBeforeCallback?: boolean;
57
+ }> & UseMutationParams;