@aws-amplify/api 4.0.33-unstable.7 → 4.0.33

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.
@@ -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.33-unstable.7+a48ddbc3d",
3
+ "version": "4.0.33",
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.22-unstable.7+a48ddbc3d",
55
- "@aws-amplify/api-rest": "2.0.33-unstable.7+a48ddbc3d"
54
+ "@aws-amplify/api-graphql": "2.2.22",
55
+ "@aws-amplify/api-rest": "2.0.33"
56
56
  },
57
57
  "jest": {
58
58
  "globals": {
@@ -98,5 +98,5 @@
98
98
  "lib-esm"
99
99
  ]
100
100
  },
101
- "gitHead": "a48ddbc3de1ce65536fe9467adb3c7dff5181680"
101
+ "gitHead": "163d74a08dfb6bb2c183f9af2bc32b56203ef67a"
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,118 @@ 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
186
  * Cancels an inflight request
159
- * @param {any} request - request to cancel
160
- * @return {boolean} - A boolean indicating if the request was cancelled
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) {
191
+ cancel(request: Promise<any>, message?: string): boolean {
163
192
  return this._restApi.cancel(request, message);
164
193
  }
165
194
 
166
195
  /**
167
196
  * Getting endpoint for API
168
- * @param {string} apiName - The name of the api
169
- * @return {string} - The endpoint of the api
197
+ * @param apiName - The name of the api
198
+ * @return The endpoint of the api
170
199
  */
171
- async endpoint(apiName) {
200
+ async endpoint(apiName: string): Promise<string> {
172
201
  return this._restApi.endpoint(apiName);
173
202
  }
174
203
 
@@ -176,21 +205,32 @@ export class APIClass {
176
205
  * to get the operation type
177
206
  * @param operation
178
207
  */
179
- getGraphqlOperationType(operation) {
208
+ getGraphqlOperationType(operation: GraphQLOperation): OperationTypeNode {
180
209
  return this._graphqlApi.getGraphqlOperationType(operation);
181
210
  }
182
211
 
183
212
  /**
184
213
  * Executes a GraphQL operation
185
214
  *
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>}
215
+ * @param options - GraphQL Options
216
+ * @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config
217
+ * @returns An Observable if queryType is 'subscription', else a promise of the graphql result from the query.
189
218
  */
190
- graphql(
219
+ graphql<T>(
191
220
  options: GraphQLOptions,
192
221
  additionalHeaders?: { [key: string]: string }
193
- ): Promise<GraphQLResult> | Observable<object> {
222
+ ): T extends GraphQLQuery<T>
223
+ ? Promise<GraphQLResult<T>>
224
+ : T extends GraphQLSubscription<T>
225
+ ? Observable<{
226
+ provider: AWSAppSyncRealTimeProvider;
227
+ value: GraphQLResult<T>;
228
+ }>
229
+ : Promise<GraphQLResult<any>> | Observable<object>;
230
+ graphql<T = any>(
231
+ options: GraphQLOptions,
232
+ additionalHeaders?: { [key: string]: string }
233
+ ): Promise<GraphQLResult<any>> | Observable<object> {
194
234
  return this._graphqlApi.graphql(options, additionalHeaders);
195
235
  }
196
236
  }
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
+ };