@aws-amplify/api 4.0.29 → 4.0.30-custom-pk.79

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.
@@ -1 +1 @@
1
- {"version":3,"file":"API.js","sourceRoot":"","sources":["../src/API.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,KAAK,MAAM,oBAAoB,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EACN,eAAe,GAGf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACN,OAAO,EACP,aAAa,IAAI,MAAM,EACvB,WAAW,GACX,MAAM,mBAAmB,CAAC;AAG3B,IAAM,MAAM,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;AACjC;;;;GAIG;AACH;IAaC;;;OAGG;IACH,kBAAY,OAAO;QARnB,SAAI,GAAG,IAAI,CAAC;QACZ,UAAK,GAAG,KAAK,CAAC;QACd,gBAAW,GAAG,WAAW,CAAC;QAOzB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,QAAQ,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,CAAC,WAAW,GAAG,IAAI,eAAe,CAAC,OAAO,CAAC,CAAC;QAChD,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5C,CAAC;IAEM,gCAAa,GAApB;QACC,OAAO,KAAK,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,4BAAS,GAAT,UAAU,OAAO;QAChB,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAE1D,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AC,GAAG,CAAC,CAAC"}
@@ -1,4 +1,5 @@
1
1
  import { API } from './API';
2
+ export { GraphQLQuery, GraphQLSubscription } from './types';
2
3
  export { API, APIClass } from './API';
3
4
  export { graphqlOperation, GraphQLAuthError, GRAPHQL_AUTH_MODE, } from '@aws-amplify/api-graphql';
4
5
  export type { GraphQLResult } from '@aws-amplify/api-graphql';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAE5B,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,GACjB,MAAM,0BAA0B,CAAC;AAGlC;;GAEG;AACH,eAAe,GAAG,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,GAAG,EAAE,MAAM,OAAO,CAAC;AAG5B,OAAO,EAAE,GAAG,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,GACjB,MAAM,0BAA0B,CAAC;AAIlC;;GAEG;AACH,eAAe,GAAG,CAAC"}
@@ -4,3 +4,10 @@
4
4
  * This will be removed in future release when CLI and customers moves to recommeneded import styles.
5
5
  */
6
6
  export { graphqlOperation, GraphQLAuthError, GraphQLResult, GRAPHQL_AUTH_MODE, } from '@aws-amplify/api-graphql';
7
+ declare const queryType: unique symbol;
8
+ export declare type GraphQLQuery<T> = T & {
9
+ readonly [queryType]: 'query';
10
+ };
11
+ export declare type GraphQLSubscription<T> = T & {
12
+ readonly [queryType]: 'subscription';
13
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/api",
3
- "version": "4.0.29",
3
+ "version": "4.0.30-custom-pk.79+0b6fc9dc5",
4
4
  "description": "Api category of aws-amplify",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib-esm/index.js",
@@ -51,8 +51,8 @@
51
51
  "@types/zen-observable": "^0.8.0"
52
52
  },
53
53
  "dependencies": {
54
- "@aws-amplify/api-graphql": "2.2.18",
55
- "@aws-amplify/api-rest": "2.0.29"
54
+ "@aws-amplify/api-graphql": "2.2.19-custom-pk.79+0b6fc9dc5",
55
+ "@aws-amplify/api-rest": "2.0.30-custom-pk.79+0b6fc9dc5"
56
56
  },
57
57
  "jest": {
58
58
  "globals": {
@@ -98,5 +98,5 @@
98
98
  "lib-esm"
99
99
  ]
100
100
  },
101
- "gitHead": "b567fc3b9ad28043fd07ce93e78ec5958414e82f"
101
+ "gitHead": "0b6fc9dc572459650749e5beb992c5060eadb920"
102
102
  }
package/src/API.ts CHANGED
@@ -12,11 +12,14 @@
12
12
  */
13
13
  import { Auth } from '@aws-amplify/auth';
14
14
  import Cache from '@aws-amplify/cache';
15
+ import { AWSAppSyncRealTimeProvider } from '@aws-amplify/pubsub';
15
16
  import { RestAPIClass } from '@aws-amplify/api-rest';
16
17
  import {
17
18
  GraphQLAPIClass,
18
19
  GraphQLOptions,
19
20
  GraphQLResult,
21
+ GraphQLOperation,
22
+ OperationTypeNode,
20
23
  } from '@aws-amplify/api-graphql';
21
24
  import {
22
25
  Amplify,
@@ -24,6 +27,7 @@ import {
24
27
  Credentials,
25
28
  } from '@aws-amplify/core';
26
29
  import Observable from 'zen-observable-ts';
30
+ import { GraphQLQuery, GraphQLSubscription } from './types';
27
31
 
28
32
  const logger = new Logger('API');
29
33
  /**
@@ -38,7 +42,7 @@ export class APIClass {
38
42
  */
39
43
  private _options;
40
44
  private _restApi: RestAPIClass;
41
- private _graphqlApi;
45
+ private _graphqlApi: GraphQLAPIClass;
42
46
 
43
47
  Auth = Auth;
44
48
  Cache = Cache;
@@ -82,93 +86,123 @@ export class APIClass {
82
86
 
83
87
  /**
84
88
  * Make a GET request
85
- * @param {string} apiName - The api name of the request
86
- * @param {string} path - The path of the request
87
- * @param {json} [init] - Request extra params
88
- * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
89
+ * @param apiName - The api name of the request
90
+ * @param path - The path of the request
91
+ * @param [init] - Request extra params
92
+ * @return A promise that resolves to an object with response status and JSON data, if successful.
89
93
  */
90
- get(apiName, path, init): Promise<any> {
94
+ get(
95
+ apiName: string,
96
+ path: string,
97
+ init: { [key: string]: any }
98
+ ): Promise<any> {
91
99
  return this._restApi.get(apiName, path, init);
92
100
  }
93
101
 
94
102
  /**
95
103
  * Make a POST request
96
- * @param {string} apiName - The api name of the request
97
- * @param {string} path - The path of the request
98
- * @param {json} [init] - Request extra params
99
- * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
104
+ * @param apiName - The api name of the request
105
+ * @param path - The path of the request
106
+ * @param [init] - Request extra params
107
+ * @return A promise that resolves to an object with response status and JSON data, if successful.
100
108
  */
101
- post(apiName, path, init): Promise<any> {
109
+ post(
110
+ apiName: string,
111
+ path: string,
112
+ init: { [key: string]: any }
113
+ ): Promise<any> {
102
114
  return this._restApi.post(apiName, path, init);
103
115
  }
104
116
 
105
117
  /**
106
118
  * Make a PUT request
107
- * @param {string} apiName - The api name of the request
108
- * @param {string} path - The path of the request
109
- * @param {json} [init] - Request extra params
110
- * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
119
+ * @param apiName - The api name of the request
120
+ * @param path - The path of the request
121
+ * @param [init] - Request extra params
122
+ * @return A promise that resolves to an object with response status and JSON data, if successful.
111
123
  */
112
- put(apiName, path, init): Promise<any> {
124
+ put(
125
+ apiName: string,
126
+ path: string,
127
+ init: { [key: string]: any }
128
+ ): Promise<any> {
113
129
  return this._restApi.put(apiName, path, init);
114
130
  }
115
131
 
116
132
  /**
117
133
  * Make a PATCH request
118
- * @param {string} apiName - The api name of the request
119
- * @param {string} path - The path of the request
120
- * @param {json} [init] - Request extra params
121
- * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
134
+ * @param apiName - The api name of the request
135
+ * @param path - The path of the request
136
+ * @param [init] - Request extra params
137
+ * @return A promise that resolves to an object with response status and JSON data, if successful.
122
138
  */
123
- patch(apiName, path, init): Promise<any> {
139
+ patch(
140
+ apiName: string,
141
+ path: string,
142
+ init: { [key: string]: any }
143
+ ): Promise<any> {
124
144
  return this._restApi.patch(apiName, path, init);
125
145
  }
126
146
 
127
147
  /**
128
148
  * Make a DEL request
129
- * @param {string} apiName - The api name of the request
130
- * @param {string} path - The path of the request
131
- * @param {json} [init] - Request extra params
132
- * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
149
+ * @param apiName - The api name of the request
150
+ * @param path - The path of the request
151
+ * @param [init] - Request extra params
152
+ * @return A promise that resolves to an object with response status and JSON data, if successful.
133
153
  */
134
- del(apiName, path, init): Promise<any> {
154
+ del(
155
+ apiName: string,
156
+ path: string,
157
+ init: { [key: string]: any }
158
+ ): Promise<any> {
135
159
  return this._restApi.del(apiName, path, init);
136
160
  }
137
161
 
138
162
  /**
139
163
  * Make a HEAD request
140
- * @param {string} apiName - The api name of the request
141
- * @param {string} path - The path of the request
142
- * @param {json} [init] - Request extra params
143
- * @return {Promise} - A promise that resolves to an object with response status and JSON data, if successful.
164
+ * @param apiName - The api name of the request
165
+ * @param path - The path of the request
166
+ * @param [init] - Request extra params
167
+ * @return A promise that resolves to an object with response status and JSON data, if successful.
144
168
  */
145
- head(apiName, path, init): Promise<any> {
169
+ head(
170
+ apiName: string,
171
+ path: string,
172
+ init: { [key: string]: any }
173
+ ): Promise<any> {
146
174
  return this._restApi.head(apiName, path, init);
147
175
  }
148
176
 
149
177
  /**
150
178
  * Checks to see if an error thrown is from an api request cancellation
151
- * @param {any} error - Any error
152
- * @return {boolean} - A boolean indicating if the error was from an api request cancellation
179
+ * @param error - Any error
180
+ * @return If the error was from an api request cancellation
153
181
  */
154
- isCancel(error) {
182
+ isCancel(error: any): boolean {
155
183
  return this._restApi.isCancel(error);
156
184
  }
157
185
  /**
158
- * Cancels an inflight request
159
- * @param {any} request - request to cancel
160
- * @return {boolean} - A boolean indicating if the request was cancelled
186
+ * Cancels an inflight request for either a GraphQL request or a Rest API request.
187
+ * @param request - request to cancel
188
+ * @param [message] - custom error message
189
+ * @return If the request was cancelled
161
190
  */
162
- cancel(request: Promise<any>, message?: string) {
163
- return this._restApi.cancel(request, message);
191
+ cancel(request: Promise<any>, message?: string): boolean {
192
+ if (this._restApi.hasCancelToken(request)) {
193
+ return this._restApi.cancel(request, message);
194
+ } else if (this._graphqlApi.hasCancelToken(request)) {
195
+ return this._graphqlApi.cancel(request, message);
196
+ }
197
+ return false;
164
198
  }
165
199
 
166
200
  /**
167
201
  * Getting endpoint for API
168
- * @param {string} apiName - The name of the api
169
- * @return {string} - The endpoint of the api
202
+ * @param apiName - The name of the api
203
+ * @return The endpoint of the api
170
204
  */
171
- async endpoint(apiName) {
205
+ async endpoint(apiName: string): Promise<string> {
172
206
  return this._restApi.endpoint(apiName);
173
207
  }
174
208
 
@@ -176,21 +210,32 @@ export class APIClass {
176
210
  * to get the operation type
177
211
  * @param operation
178
212
  */
179
- getGraphqlOperationType(operation) {
213
+ getGraphqlOperationType(operation: GraphQLOperation): OperationTypeNode {
180
214
  return this._graphqlApi.getGraphqlOperationType(operation);
181
215
  }
182
216
 
183
217
  /**
184
218
  * Executes a GraphQL operation
185
219
  *
186
- * @param {GraphQLOptions} GraphQL Options
187
- * @param {object} additionalHeaders headers to merge in after any `graphql_headers` set in the config
188
- * @returns {Promise<GraphQLResult> | Observable<object>}
220
+ * @param options - GraphQL Options
221
+ * @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config
222
+ * @returns An Observable if queryType is 'subscription', else a promise of the graphql result from the query.
189
223
  */
190
- graphql(
224
+ graphql<T>(
191
225
  options: GraphQLOptions,
192
226
  additionalHeaders?: { [key: string]: string }
193
- ): Promise<GraphQLResult> | Observable<object> {
227
+ ): T extends GraphQLQuery<T>
228
+ ? Promise<GraphQLResult<T>>
229
+ : T extends GraphQLSubscription<T>
230
+ ? Observable<{
231
+ provider: AWSAppSyncRealTimeProvider;
232
+ value: GraphQLResult<T>;
233
+ }>
234
+ : Promise<GraphQLResult<any>> | Observable<object>;
235
+ graphql<T = any>(
236
+ options: GraphQLOptions,
237
+ additionalHeaders?: { [key: string]: string }
238
+ ): Promise<GraphQLResult<any>> | Observable<object> {
194
239
  return this._graphqlApi.graphql(options, additionalHeaders);
195
240
  }
196
241
  }
package/src/index.ts CHANGED
@@ -13,6 +13,7 @@
13
13
 
14
14
  import { API } from './API';
15
15
 
16
+ export { GraphQLQuery, GraphQLSubscription } from './types';
16
17
  export { API, APIClass } from './API';
17
18
  export {
18
19
  graphqlOperation,
@@ -21,6 +22,7 @@ export {
21
22
  } from '@aws-amplify/api-graphql';
22
23
 
23
24
  export type { GraphQLResult } from '@aws-amplify/api-graphql';
25
+
24
26
  /*
25
27
  * @deprecated use named import
26
28
  */
@@ -22,3 +22,11 @@ export {
22
22
  GraphQLResult,
23
23
  GRAPHQL_AUTH_MODE,
24
24
  } from '@aws-amplify/api-graphql';
25
+
26
+ // Opaque type used for determining the graphql query type
27
+ declare const queryType: unique symbol;
28
+
29
+ export type GraphQLQuery<T> = T & { readonly [queryType]: 'query' };
30
+ export type GraphQLSubscription<T> = T & {
31
+ readonly [queryType]: 'subscription';
32
+ };