@aws-amplify/api-graphql 4.0.1-console-preview.11cf989.0 → 4.0.1-console-preview.4ae78ed.0
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/lib/GraphQLAPI.d.ts +12 -0
- package/lib/GraphQLAPI.js +16 -0
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +3 -4
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +17 -14
- package/lib/internals/InternalGraphQLAPI.d.ts +12 -0
- package/lib/internals/InternalGraphQLAPI.js +80 -39
- package/lib/internals/index.d.ts +1 -1
- package/lib/internals/index.js +2 -0
- package/lib/internals/v6.d.ts +12 -0
- package/lib/internals/v6.js +18 -0
- package/lib/tsconfig.tsbuildinfo +1064 -871
- package/lib/types/index.d.ts +4 -5
- package/lib/utils/resolveConfig.d.ts +1 -1
- package/lib/utils/resolveConfig.js +1 -1
- package/lib-esm/GraphQLAPI.d.ts +12 -0
- package/lib-esm/GraphQLAPI.js +16 -0
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +3 -4
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +17 -14
- package/lib-esm/internals/InternalGraphQLAPI.d.ts +12 -0
- package/lib-esm/internals/InternalGraphQLAPI.js +81 -40
- package/lib-esm/internals/index.d.ts +1 -1
- package/lib-esm/internals/index.js +1 -1
- package/lib-esm/internals/v6.d.ts +12 -0
- package/lib-esm/internals/v6.js +16 -0
- package/lib-esm/tsconfig.tsbuildinfo +1064 -871
- package/lib-esm/types/index.d.ts +4 -5
- package/lib-esm/utils/resolveConfig.d.ts +1 -1
- package/lib-esm/utils/resolveConfig.js +1 -1
- package/package.json +6 -5
- package/src/GraphQLAPI.ts +18 -0
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +28 -29
- package/src/internals/InternalGraphQLAPI.ts +86 -42
- package/src/internals/index.ts +1 -1
- package/src/internals/v6.ts +18 -0
- package/src/types/index.ts +4 -5
- package/src/utils/resolveConfig.ts +1 -1
package/lib/types/index.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Source, DocumentNode, GraphQLError } from 'graphql';
|
|
2
2
|
export { OperationTypeNode } from 'graphql';
|
|
3
3
|
import { Observable } from 'rxjs';
|
|
4
|
-
import { DocumentType } from '@aws-amplify/
|
|
5
|
-
import { GraphQLAuthModeKeys } from '@aws-amplify/core/internals/utils';
|
|
4
|
+
import { APIAuthMode, DocumentType } from '@aws-amplify/core/internals/utils';
|
|
6
5
|
export { CONTROL_MSG, ConnectionState } from './PubSub';
|
|
7
6
|
/**
|
|
8
7
|
* Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
|
|
@@ -10,7 +9,7 @@ export { CONTROL_MSG, ConnectionState } from './PubSub';
|
|
|
10
9
|
export interface GraphQLOptions {
|
|
11
10
|
query: string | DocumentNode;
|
|
12
11
|
variables?: Record<string, DocumentType>;
|
|
13
|
-
authMode?:
|
|
12
|
+
authMode?: APIAuthMode;
|
|
14
13
|
authToken?: string;
|
|
15
14
|
/**
|
|
16
15
|
* @deprecated This property should not be used
|
|
@@ -73,7 +72,7 @@ export declare type GraphqlSubscriptionMessage<T> = {
|
|
|
73
72
|
};
|
|
74
73
|
export interface AWSAppSyncRealTimeProviderOptions {
|
|
75
74
|
appSyncGraphqlEndpoint?: string;
|
|
76
|
-
authenticationType?:
|
|
75
|
+
authenticationType?: APIAuthMode;
|
|
77
76
|
query?: string;
|
|
78
77
|
variables?: Record<string, unknown>;
|
|
79
78
|
apiKey?: string;
|
|
@@ -105,7 +104,7 @@ export declare type GraphQLOperation = Source | string;
|
|
|
105
104
|
export interface GraphQLOptionsV6<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string> {
|
|
106
105
|
query: TYPED_GQL_STRING | DocumentNode;
|
|
107
106
|
variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
108
|
-
authMode?:
|
|
107
|
+
authMode?: APIAuthMode;
|
|
109
108
|
authToken?: string;
|
|
110
109
|
/**
|
|
111
110
|
* @deprecated This property should not be used
|
|
@@ -9,7 +9,7 @@ var errors_1 = require("./errors");
|
|
|
9
9
|
*/
|
|
10
10
|
exports.resolveConfig = function () {
|
|
11
11
|
var _a, _b;
|
|
12
|
-
var _c = (_b = (_a = core_1.Amplify.getConfig().API) === null || _a === void 0 ? void 0 : _a.
|
|
12
|
+
var _c = (_b = (_a = core_1.Amplify.getConfig().API) === null || _a === void 0 ? void 0 : _a.GraphQL) !== null && _b !== void 0 ? _b : {}, region = _c.region, defaultAuthMode = _c.defaultAuthMode, endpoint = _c.endpoint;
|
|
13
13
|
errors_1.assertValidationError(!!endpoint, errors_1.APIValidationErrorCode.NoAppId);
|
|
14
14
|
errors_1.assertValidationError(!!region, errors_1.APIValidationErrorCode.NoRegion);
|
|
15
15
|
errors_1.assertValidationError(!!defaultAuthMode, errors_1.APIValidationErrorCode.NoDefaultAuthMode);
|
package/lib-esm/GraphQLAPI.d.ts
CHANGED
|
@@ -21,5 +21,17 @@ export declare class GraphQLAPIClass extends InternalGraphQLAPIClass {
|
|
|
21
21
|
graphql<T = any>(options: GraphQLOptions, additionalHeaders?: {
|
|
22
22
|
[key: string]: string;
|
|
23
23
|
}): Observable<GraphQLResult<T>> | Promise<GraphQLResult<T>>;
|
|
24
|
+
/**
|
|
25
|
+
* Checks to see if an error thrown is from an api request cancellation
|
|
26
|
+
* @param error - Any error
|
|
27
|
+
* @returns A boolean indicating if the error was from an api request cancellation
|
|
28
|
+
*/
|
|
29
|
+
isCancelError(error: any): boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Cancels an inflight request. Only applicable for graphql queries and mutations
|
|
32
|
+
* @param {any} request - request to cancel
|
|
33
|
+
* @returns A boolean indicating if the request was cancelled
|
|
34
|
+
*/
|
|
35
|
+
cancel(request: Promise<any>, message?: string): boolean;
|
|
24
36
|
}
|
|
25
37
|
export declare const GraphQLAPI: GraphQLAPIClass;
|
package/lib-esm/GraphQLAPI.js
CHANGED
|
@@ -29,6 +29,22 @@ var GraphQLAPIClass = /** @class */ (function (_super) {
|
|
|
29
29
|
GraphQLAPIClass.prototype.graphql = function (options, additionalHeaders) {
|
|
30
30
|
return _super.prototype.graphql.call(this, options, additionalHeaders);
|
|
31
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* Checks to see if an error thrown is from an api request cancellation
|
|
34
|
+
* @param error - Any error
|
|
35
|
+
* @returns A boolean indicating if the error was from an api request cancellation
|
|
36
|
+
*/
|
|
37
|
+
GraphQLAPIClass.prototype.isCancelError = function (error) {
|
|
38
|
+
return _super.prototype.isCancelError.call(this, error);
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Cancels an inflight request. Only applicable for graphql queries and mutations
|
|
42
|
+
* @param {any} request - request to cancel
|
|
43
|
+
* @returns A boolean indicating if the request was cancelled
|
|
44
|
+
*/
|
|
45
|
+
GraphQLAPIClass.prototype.cancel = function (request, message) {
|
|
46
|
+
return _super.prototype.cancel.call(this, request, message);
|
|
47
|
+
};
|
|
32
48
|
return GraphQLAPIClass;
|
|
33
49
|
}(InternalGraphQLAPIClass));
|
|
34
50
|
export { GraphQLAPIClass };
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
|
+
import { APIAuthMode, CustomUserAgentDetails, DocumentType } from '@aws-amplify/core/internals/utils';
|
|
2
3
|
import { PubSubContentObserver } from '../../types/PubSub';
|
|
3
4
|
import { SUBSCRIPTION_STATUS } from '../constants';
|
|
4
|
-
import { CustomUserAgentDetails, GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
|
|
5
|
-
import { DocumentType } from '@aws-amplify/api-rest';
|
|
6
5
|
export declare type ObserverQuery = {
|
|
7
6
|
observer: PubSubContentObserver;
|
|
8
7
|
query: string;
|
|
@@ -14,7 +13,7 @@ export declare type ObserverQuery = {
|
|
|
14
13
|
};
|
|
15
14
|
export interface AWSAppSyncRealTimeProviderOptions {
|
|
16
15
|
appSyncGraphqlEndpoint?: string;
|
|
17
|
-
authenticationType?:
|
|
16
|
+
authenticationType?: APIAuthMode;
|
|
18
17
|
query?: string;
|
|
19
18
|
variables?: Record<string, DocumentType>;
|
|
20
19
|
apiKey?: string;
|
|
@@ -58,7 +57,7 @@ export declare class AWSAppSyncRealTimeProvider {
|
|
|
58
57
|
private _initializeRetryableHandshake;
|
|
59
58
|
private _initializeHandshake;
|
|
60
59
|
private _awsRealTimeHeaderBasedAuth;
|
|
61
|
-
private
|
|
60
|
+
private _awsAuthTokenHeader;
|
|
62
61
|
private _awsRealTimeApiKeyHeader;
|
|
63
62
|
private _awsRealTimeIAMHeader;
|
|
64
63
|
private _customAuthHeader;
|
|
@@ -7,12 +7,12 @@ import * as url from 'url';
|
|
|
7
7
|
import { v4 as uuid } from 'uuid';
|
|
8
8
|
import { Buffer } from 'buffer';
|
|
9
9
|
import { Hub, fetchAuthSession } from '@aws-amplify/core';
|
|
10
|
-
import { CONTROL_MSG, ConnectionState, } from '../../types/PubSub';
|
|
11
10
|
import { signRequest } from '@aws-amplify/core/internals/aws-client-utils';
|
|
11
|
+
import { Logger, NonRetryableError, USER_AGENT_HEADER, getAmplifyUserAgent, isNonRetryableError, jitteredExponentialRetry, } from '@aws-amplify/core/internals/utils';
|
|
12
|
+
import { CONTROL_MSG, ConnectionState, } from '../../types/PubSub';
|
|
12
13
|
import { AMPLIFY_SYMBOL, AWS_APPSYNC_REALTIME_HEADERS, CONNECTION_INIT_TIMEOUT, DEFAULT_KEEP_ALIVE_TIMEOUT, DEFAULT_KEEP_ALIVE_ALERT_TIMEOUT, MAX_DELAY_MS, MESSAGE_TYPES, NON_RETRYABLE_CODES, SOCKET_STATUS, START_ACK_TIMEOUT, SUBSCRIPTION_STATUS, CONNECTION_STATE_CHANGE, } from '../constants';
|
|
13
14
|
import { ConnectionStateMonitor, CONNECTION_CHANGE, } from '../../utils/ConnectionStateMonitor';
|
|
14
15
|
import { ReconnectEvent, ReconnectionMonitor, } from '../../utils/ReconnectionMonitor';
|
|
15
|
-
import { Logger, NonRetryableError, USER_AGENT_HEADER, getAmplifyUserAgent, isNonRetryableError, jitteredExponentialRetry, } from '@aws-amplify/core/internals/utils';
|
|
16
16
|
var logger = new Logger('AWSAppSyncRealTimeProvider');
|
|
17
17
|
var dispatchApiEvent = function (payload) {
|
|
18
18
|
Hub.dispatch('api', payload, 'PubSub', AMPLIFY_SYMBOL);
|
|
@@ -83,7 +83,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
83
83
|
};
|
|
84
84
|
AWSAppSyncRealTimeProvider.prototype.subscribe = function (options, customUserAgentDetails) {
|
|
85
85
|
var _this = this;
|
|
86
|
-
var _a = options || {}, appSyncGraphqlEndpoint = _a.appSyncGraphqlEndpoint, region = _a.region, query = _a.query, variables = _a.variables, authenticationType = _a.authenticationType, additionalHeaders = _a.additionalHeaders;
|
|
86
|
+
var _a = options || {}, appSyncGraphqlEndpoint = _a.appSyncGraphqlEndpoint, region = _a.region, query = _a.query, variables = _a.variables, authenticationType = _a.authenticationType, additionalHeaders = _a.additionalHeaders, apiKey = _a.apiKey;
|
|
87
87
|
return new Observable(function (observer) {
|
|
88
88
|
if (!options || !appSyncGraphqlEndpoint) {
|
|
89
89
|
observer.error({
|
|
@@ -107,6 +107,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
107
107
|
authenticationType: authenticationType,
|
|
108
108
|
appSyncGraphqlEndpoint: appSyncGraphqlEndpoint,
|
|
109
109
|
additionalHeaders: additionalHeaders,
|
|
110
|
+
apiKey: apiKey,
|
|
110
111
|
},
|
|
111
112
|
observer: observer,
|
|
112
113
|
subscriptionId: subscriptionId_1,
|
|
@@ -678,34 +679,36 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
678
679
|
});
|
|
679
680
|
};
|
|
680
681
|
AWSAppSyncRealTimeProvider.prototype._awsRealTimeHeaderBasedAuth = function (_a) {
|
|
681
|
-
var authenticationType = _a.authenticationType, payload = _a.payload, canonicalUri = _a.canonicalUri, appSyncGraphqlEndpoint = _a.appSyncGraphqlEndpoint, region = _a.region, additionalHeaders = _a.additionalHeaders;
|
|
682
|
+
var apiKey = _a.apiKey, authenticationType = _a.authenticationType, payload = _a.payload, canonicalUri = _a.canonicalUri, appSyncGraphqlEndpoint = _a.appSyncGraphqlEndpoint, region = _a.region, additionalHeaders = _a.additionalHeaders;
|
|
682
683
|
return __awaiter(this, void 0, void 0, function () {
|
|
683
|
-
var headerHandler, handler, host,
|
|
684
|
+
var headerHandler, handler, host, resolvedApiKey, result;
|
|
684
685
|
return __generator(this, function (_b) {
|
|
685
686
|
switch (_b.label) {
|
|
686
687
|
case 0:
|
|
687
688
|
headerHandler = {
|
|
688
689
|
apiKey: this._awsRealTimeApiKeyHeader.bind(this),
|
|
689
690
|
iam: this._awsRealTimeIAMHeader.bind(this),
|
|
690
|
-
|
|
691
|
-
|
|
691
|
+
oidc: this._awsAuthTokenHeader.bind(this),
|
|
692
|
+
userPool: this._awsAuthTokenHeader.bind(this),
|
|
693
|
+
lambda: this._customAuthHeader,
|
|
694
|
+
none: this._customAuthHeader,
|
|
692
695
|
};
|
|
693
|
-
if (!(!authenticationType || !headerHandler[authenticationType
|
|
696
|
+
if (!(!authenticationType || !headerHandler[authenticationType])) return [3 /*break*/, 1];
|
|
694
697
|
logger.debug("Authentication type " + authenticationType + " not supported");
|
|
695
698
|
return [2 /*return*/, undefined];
|
|
696
699
|
case 1:
|
|
697
|
-
handler = headerHandler[authenticationType
|
|
700
|
+
handler = headerHandler[authenticationType];
|
|
698
701
|
host = url.parse(appSyncGraphqlEndpoint !== null && appSyncGraphqlEndpoint !== void 0 ? appSyncGraphqlEndpoint : '').host;
|
|
699
702
|
logger.debug("Authenticating with " + JSON.stringify(authenticationType));
|
|
700
|
-
|
|
701
|
-
if (authenticationType
|
|
702
|
-
|
|
703
|
+
resolvedApiKey = void 0;
|
|
704
|
+
if (authenticationType === 'apiKey') {
|
|
705
|
+
resolvedApiKey = apiKey;
|
|
703
706
|
}
|
|
704
707
|
return [4 /*yield*/, handler({
|
|
705
708
|
payload: payload,
|
|
706
709
|
canonicalUri: canonicalUri,
|
|
707
710
|
appSyncGraphqlEndpoint: appSyncGraphqlEndpoint,
|
|
708
|
-
apiKey:
|
|
711
|
+
apiKey: resolvedApiKey,
|
|
709
712
|
region: region,
|
|
710
713
|
host: host,
|
|
711
714
|
additionalHeaders: additionalHeaders,
|
|
@@ -717,7 +720,7 @@ var AWSAppSyncRealTimeProvider = /** @class */ (function () {
|
|
|
717
720
|
});
|
|
718
721
|
});
|
|
719
722
|
};
|
|
720
|
-
AWSAppSyncRealTimeProvider.prototype.
|
|
723
|
+
AWSAppSyncRealTimeProvider.prototype._awsAuthTokenHeader = function (_a) {
|
|
721
724
|
var host = _a.host;
|
|
722
725
|
var _b, _c;
|
|
723
726
|
return __awaiter(this, void 0, void 0, function () {
|
|
@@ -41,6 +41,18 @@ export declare class InternalGraphQLAPIClass {
|
|
|
41
41
|
[key: string]: string;
|
|
42
42
|
}, customUserAgentDetails?: CustomUserAgentDetails): Observable<GraphQLResult<T>> | Promise<GraphQLResult<T>>;
|
|
43
43
|
private _graphql;
|
|
44
|
+
/**
|
|
45
|
+
* Checks to see if an error thrown is from an api request cancellation
|
|
46
|
+
* @param {any} error - Any error
|
|
47
|
+
* @return {boolean} - A boolean indicating if the error was from an api request cancellation
|
|
48
|
+
*/
|
|
49
|
+
isCancelError(error: any): boolean;
|
|
50
|
+
/**
|
|
51
|
+
* Cancels an inflight request. Only applicable for graphql queries and mutations
|
|
52
|
+
* @param {any} request - request to cancel
|
|
53
|
+
* @returns - A boolean indicating if the request was cancelled
|
|
54
|
+
*/
|
|
55
|
+
cancel(request: Promise<any>, message?: string): boolean;
|
|
44
56
|
private _graphqlSubscribe;
|
|
45
57
|
}
|
|
46
58
|
export declare const InternalGraphQLAPI: InternalGraphQLAPIClass;
|
|
@@ -5,7 +5,8 @@ import { print, parse, GraphQLError, } from 'graphql';
|
|
|
5
5
|
import { Amplify, Cache, fetchAuthSession } from '@aws-amplify/core';
|
|
6
6
|
import { ConsoleLogger as Logger, getAmplifyUserAgent, } from '@aws-amplify/core/internals/utils';
|
|
7
7
|
import { GraphQLAuthError, } from '../types';
|
|
8
|
-
import {
|
|
8
|
+
import { isCancelError as isCancelErrorREST } from '@aws-amplify/api-rest';
|
|
9
|
+
import { post, cancel as cancelREST, updateRequestToBeCancellable, } from '@aws-amplify/api-rest/internals';
|
|
9
10
|
import { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvider';
|
|
10
11
|
var USER_AGENT_HEADER = 'x-amz-user-agent';
|
|
11
12
|
var logger = new Logger('GraphQLAPI');
|
|
@@ -27,47 +28,50 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
27
28
|
*/
|
|
28
29
|
function InternalGraphQLAPIClass(options) {
|
|
29
30
|
this.Cache = Cache;
|
|
30
|
-
this._api = { post: post };
|
|
31
|
+
this._api = { post: post, updateRequestToBeCancellable: updateRequestToBeCancellable };
|
|
31
32
|
this._options = options;
|
|
32
33
|
logger.debug('API Options', this._options);
|
|
33
34
|
}
|
|
34
35
|
InternalGraphQLAPIClass.prototype.getModuleName = function () {
|
|
35
36
|
return 'InternalGraphQLAPI';
|
|
36
37
|
};
|
|
37
|
-
InternalGraphQLAPIClass.prototype._headerBasedAuth = function (
|
|
38
|
+
InternalGraphQLAPIClass.prototype._headerBasedAuth = function (authMode, additionalHeaders) {
|
|
38
39
|
if (additionalHeaders === void 0) { additionalHeaders = {}; }
|
|
39
40
|
var _a;
|
|
40
41
|
return __awaiter(this, void 0, void 0, function () {
|
|
41
|
-
var config, _b, region, appSyncGraphqlEndpoint, authenticationType, headers, _c, session, token, e_1;
|
|
42
|
+
var config, _b, region, appSyncGraphqlEndpoint, apiKey, defaultAuthMode, authenticationType, headers, _c, session, token, e_1;
|
|
42
43
|
return __generator(this, function (_d) {
|
|
43
44
|
switch (_d.label) {
|
|
44
45
|
case 0:
|
|
45
46
|
config = Amplify.getConfig();
|
|
46
|
-
_b = config.API.
|
|
47
|
+
_b = config.API.GraphQL, region = _b.region, appSyncGraphqlEndpoint = _b.endpoint, apiKey = _b.apiKey, defaultAuthMode = _b.defaultAuthMode;
|
|
48
|
+
authenticationType = authMode || defaultAuthMode || 'iam';
|
|
47
49
|
headers = {};
|
|
48
|
-
_c = authenticationType
|
|
50
|
+
_c = authenticationType;
|
|
49
51
|
switch (_c) {
|
|
50
52
|
case 'apiKey': return [3 /*break*/, 1];
|
|
51
53
|
case 'iam': return [3 /*break*/, 2];
|
|
52
|
-
case '
|
|
53
|
-
case '
|
|
54
|
+
case 'oidc': return [3 /*break*/, 4];
|
|
55
|
+
case 'userPool': return [3 /*break*/, 4];
|
|
56
|
+
case 'lambda': return [3 /*break*/, 8];
|
|
57
|
+
case 'none': return [3 /*break*/, 9];
|
|
54
58
|
}
|
|
55
|
-
return [3 /*break*/,
|
|
59
|
+
return [3 /*break*/, 10];
|
|
56
60
|
case 1:
|
|
57
|
-
if (!
|
|
61
|
+
if (!apiKey) {
|
|
58
62
|
throw new Error(GraphQLAuthError.NO_API_KEY);
|
|
59
63
|
}
|
|
60
64
|
headers = {
|
|
61
|
-
'X-Api-Key':
|
|
65
|
+
'X-Api-Key': apiKey,
|
|
62
66
|
};
|
|
63
|
-
return [3 /*break*/,
|
|
67
|
+
return [3 /*break*/, 11];
|
|
64
68
|
case 2: return [4 /*yield*/, fetchAuthSession()];
|
|
65
69
|
case 3:
|
|
66
70
|
session = _d.sent();
|
|
67
71
|
if (session.credentials === undefined) {
|
|
68
72
|
throw new Error(GraphQLAuthError.NO_CREDENTIALS);
|
|
69
73
|
}
|
|
70
|
-
return [3 /*break*/,
|
|
74
|
+
return [3 /*break*/, 11];
|
|
71
75
|
case 4:
|
|
72
76
|
_d.trys.push([4, 6, , 7]);
|
|
73
77
|
token = void 0;
|
|
@@ -84,7 +88,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
84
88
|
case 6:
|
|
85
89
|
e_1 = _d.sent();
|
|
86
90
|
throw new Error(GraphQLAuthError.NO_CURRENT_USER);
|
|
87
|
-
case 7: return [3 /*break*/,
|
|
91
|
+
case 7: return [3 /*break*/, 11];
|
|
88
92
|
case 8:
|
|
89
93
|
if (!additionalHeaders.Authorization) {
|
|
90
94
|
throw new Error(GraphQLAuthError.NO_AUTH_TOKEN);
|
|
@@ -92,13 +96,14 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
92
96
|
headers = {
|
|
93
97
|
Authorization: additionalHeaders.Authorization,
|
|
94
98
|
};
|
|
95
|
-
return [3 /*break*/,
|
|
96
|
-
case 9:
|
|
99
|
+
return [3 /*break*/, 11];
|
|
100
|
+
case 9: return [3 /*break*/, 11];
|
|
101
|
+
case 10:
|
|
97
102
|
headers = {
|
|
98
103
|
Authorization: null,
|
|
99
104
|
};
|
|
100
|
-
return [3 /*break*/,
|
|
101
|
-
case
|
|
105
|
+
return [3 /*break*/, 11];
|
|
106
|
+
case 11: return [2 /*return*/, headers];
|
|
102
107
|
}
|
|
103
108
|
});
|
|
104
109
|
});
|
|
@@ -135,7 +140,9 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
135
140
|
switch (operationType) {
|
|
136
141
|
case 'query':
|
|
137
142
|
case 'mutation':
|
|
138
|
-
var
|
|
143
|
+
var abortController = new AbortController();
|
|
144
|
+
var responsePromise = this._graphql({ query: query, variables: variables, authMode: authMode }, headers, abortController, customUserAgentDetails);
|
|
145
|
+
this._api.updateRequestToBeCancellable(responsePromise, abortController);
|
|
139
146
|
return responsePromise;
|
|
140
147
|
case 'subscription':
|
|
141
148
|
return this._graphqlSubscribe({ query: query, variables: variables, authMode: authMode }, headers, customUserAgentDetails);
|
|
@@ -143,23 +150,23 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
143
150
|
throw new Error("invalid operation type: " + operationType);
|
|
144
151
|
}
|
|
145
152
|
};
|
|
146
|
-
InternalGraphQLAPIClass.prototype._graphql = function (_a, additionalHeaders, customUserAgentDetails) {
|
|
153
|
+
InternalGraphQLAPIClass.prototype._graphql = function (_a, additionalHeaders, abortController, customUserAgentDetails) {
|
|
147
154
|
var query = _a.query, variables = _a.variables, authMode = _a.authMode;
|
|
148
155
|
if (additionalHeaders === void 0) { additionalHeaders = {}; }
|
|
149
156
|
return __awaiter(this, void 0, void 0, function () {
|
|
150
|
-
var config, _b, region, appSyncGraphqlEndpoint, customGraphqlEndpoint, customEndpointRegion, headers, _c, _d, _e, _f, _g, body, endpoint, error, response, err_1, errors;
|
|
157
|
+
var config, _b, region, appSyncGraphqlEndpoint, customGraphqlEndpoint, customEndpointRegion, headers, _c, _d, _e, _f, _g, body, endpoint, error, response, responseBody, result, err_1, errors;
|
|
151
158
|
var _h;
|
|
152
159
|
return __generator(this, function (_j) {
|
|
153
160
|
switch (_j.label) {
|
|
154
161
|
case 0:
|
|
155
162
|
config = Amplify.getConfig();
|
|
156
|
-
_b = config.API.
|
|
163
|
+
_b = config.API.GraphQL, region = _b.region, appSyncGraphqlEndpoint = _b.endpoint;
|
|
157
164
|
customGraphqlEndpoint = null;
|
|
158
165
|
customEndpointRegion = null;
|
|
159
166
|
_c = [{}];
|
|
160
167
|
_d = !customGraphqlEndpoint;
|
|
161
168
|
if (!_d) return [3 /*break*/, 2];
|
|
162
|
-
return [4 /*yield*/, this._headerBasedAuth(authMode, additionalHeaders
|
|
169
|
+
return [4 /*yield*/, this._headerBasedAuth(authMode, additionalHeaders)];
|
|
163
170
|
case 1:
|
|
164
171
|
_d = (_j.sent());
|
|
165
172
|
_j.label = 2;
|
|
@@ -168,7 +175,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
168
175
|
_f = customGraphqlEndpoint;
|
|
169
176
|
if (!_f) return [3 /*break*/, 6];
|
|
170
177
|
if (!customEndpointRegion) return [3 /*break*/, 4];
|
|
171
|
-
return [4 /*yield*/, this._headerBasedAuth(authMode, additionalHeaders
|
|
178
|
+
return [4 /*yield*/, this._headerBasedAuth(authMode, additionalHeaders)];
|
|
172
179
|
case 3:
|
|
173
180
|
_g = _j.sent();
|
|
174
181
|
return [3 /*break*/, 5];
|
|
@@ -196,24 +203,40 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
196
203
|
}
|
|
197
204
|
_j.label = 7;
|
|
198
205
|
case 7:
|
|
199
|
-
_j.trys.push([7,
|
|
200
|
-
return [4 /*yield*/, this._api.post(
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
206
|
+
_j.trys.push([7, 10, , 11]);
|
|
207
|
+
return [4 /*yield*/, this._api.post({
|
|
208
|
+
url: new URL(endpoint),
|
|
209
|
+
options: {
|
|
210
|
+
headers: headers,
|
|
211
|
+
body: body,
|
|
212
|
+
signingServiceInfo: {
|
|
213
|
+
service: 'appsync',
|
|
214
|
+
region: region,
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
abortController: abortController,
|
|
205
218
|
})];
|
|
206
219
|
case 8:
|
|
207
|
-
|
|
208
|
-
return [
|
|
220
|
+
responseBody = (_j.sent()).body;
|
|
221
|
+
return [4 /*yield*/, responseBody.json()];
|
|
209
222
|
case 9:
|
|
223
|
+
result = _j.sent();
|
|
224
|
+
response = result;
|
|
225
|
+
return [3 /*break*/, 11];
|
|
226
|
+
case 10:
|
|
210
227
|
err_1 = _j.sent();
|
|
228
|
+
// If the exception is because user intentionally
|
|
229
|
+
// cancelled the request, do not modify the exception
|
|
230
|
+
// so that clients can identify the exception correctly.
|
|
231
|
+
if (isCancelErrorREST(err_1)) {
|
|
232
|
+
throw err_1;
|
|
233
|
+
}
|
|
211
234
|
response = {
|
|
212
235
|
data: {},
|
|
213
236
|
errors: [new GraphQLError(err_1.message, null, null, null, null, err_1)],
|
|
214
237
|
};
|
|
215
|
-
return [3 /*break*/,
|
|
216
|
-
case
|
|
238
|
+
return [3 /*break*/, 11];
|
|
239
|
+
case 11:
|
|
217
240
|
errors = response.errors;
|
|
218
241
|
if (errors && errors.length) {
|
|
219
242
|
throw response;
|
|
@@ -223,21 +246,39 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
|
|
|
223
246
|
});
|
|
224
247
|
});
|
|
225
248
|
};
|
|
249
|
+
/**
|
|
250
|
+
* Checks to see if an error thrown is from an api request cancellation
|
|
251
|
+
* @param {any} error - Any error
|
|
252
|
+
* @return {boolean} - A boolean indicating if the error was from an api request cancellation
|
|
253
|
+
*/
|
|
254
|
+
InternalGraphQLAPIClass.prototype.isCancelError = function (error) {
|
|
255
|
+
return isCancelErrorREST(error);
|
|
256
|
+
};
|
|
257
|
+
/**
|
|
258
|
+
* Cancels an inflight request. Only applicable for graphql queries and mutations
|
|
259
|
+
* @param {any} request - request to cancel
|
|
260
|
+
* @returns - A boolean indicating if the request was cancelled
|
|
261
|
+
*/
|
|
262
|
+
InternalGraphQLAPIClass.prototype.cancel = function (request, message) {
|
|
263
|
+
return cancelREST(request, message);
|
|
264
|
+
};
|
|
226
265
|
InternalGraphQLAPIClass.prototype._graphqlSubscribe = function (_a, additionalHeaders, customUserAgentDetails) {
|
|
227
|
-
var query = _a.query, variables = _a.variables,
|
|
266
|
+
var query = _a.query, variables = _a.variables, authMode = _a.authMode;
|
|
228
267
|
if (additionalHeaders === void 0) { additionalHeaders = {}; }
|
|
229
268
|
var _b;
|
|
230
|
-
var
|
|
269
|
+
var GraphQL = ((_b = Amplify.getConfig().API) !== null && _b !== void 0 ? _b : {}).GraphQL;
|
|
231
270
|
if (!this.appSyncRealTime) {
|
|
232
271
|
this.appSyncRealTime = new AWSAppSyncRealTimeProvider();
|
|
233
272
|
}
|
|
234
273
|
return this.appSyncRealTime.subscribe({
|
|
235
274
|
query: print(query),
|
|
236
275
|
variables: variables,
|
|
237
|
-
appSyncGraphqlEndpoint:
|
|
238
|
-
region:
|
|
239
|
-
authenticationType:
|
|
240
|
-
|
|
276
|
+
appSyncGraphqlEndpoint: GraphQL === null || GraphQL === void 0 ? void 0 : GraphQL.endpoint,
|
|
277
|
+
region: GraphQL === null || GraphQL === void 0 ? void 0 : GraphQL.region,
|
|
278
|
+
authenticationType: authMode !== null && authMode !== void 0 ? authMode : GraphQL === null || GraphQL === void 0 ? void 0 : GraphQL.defaultAuthMode,
|
|
279
|
+
apiKey: GraphQL === null || GraphQL === void 0 ? void 0 : GraphQL.apiKey,
|
|
280
|
+
additionalHeaders: additionalHeaders,
|
|
281
|
+
}, customUserAgentDetails);
|
|
241
282
|
};
|
|
242
283
|
return InternalGraphQLAPIClass;
|
|
243
284
|
}());
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { InternalGraphQLAPI, InternalGraphQLAPIClass, } from './InternalGraphQLAPI';
|
|
2
|
-
export { graphql } from './v6';
|
|
2
|
+
export { graphql, cancel, isCancelError } from './v6';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
export { InternalGraphQLAPI, InternalGraphQLAPIClass, } from './InternalGraphQLAPI';
|
|
4
|
-
export { graphql } from './v6';
|
|
4
|
+
export { graphql, cancel, isCancelError } from './v6';
|
|
@@ -86,4 +86,16 @@ import { GraphQLOptionsV6, GraphQLResponseV6 } from '../types';
|
|
|
86
86
|
export declare function graphql<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
|
|
87
87
|
[key: string]: string;
|
|
88
88
|
}): GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
89
|
+
/**
|
|
90
|
+
* Cancels an inflight request. Only applicable for graphql queries and mutations
|
|
91
|
+
* @param {any} request - request to cancel
|
|
92
|
+
* @returns - A boolean indicating if the request was cancelled
|
|
93
|
+
*/
|
|
94
|
+
export declare function cancel(promise: Promise<any>, message?: string): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Checks to see if an error thrown is from an api request cancellation
|
|
97
|
+
* @param {any} error - Any error
|
|
98
|
+
* @returns - A boolean indicating if the error was from an api request cancellation
|
|
99
|
+
*/
|
|
100
|
+
export declare function isCancelError(error: any): boolean;
|
|
89
101
|
export { GraphQLOptionsV6, GraphQLResponseV6 };
|
package/lib-esm/internals/v6.js
CHANGED
|
@@ -94,3 +94,19 @@ export function graphql(options, additionalHeaders) {
|
|
|
94
94
|
var result = GraphQLAPI.graphql(options, additionalHeaders);
|
|
95
95
|
return result;
|
|
96
96
|
}
|
|
97
|
+
/**
|
|
98
|
+
* Cancels an inflight request. Only applicable for graphql queries and mutations
|
|
99
|
+
* @param {any} request - request to cancel
|
|
100
|
+
* @returns - A boolean indicating if the request was cancelled
|
|
101
|
+
*/
|
|
102
|
+
export function cancel(promise, message) {
|
|
103
|
+
return GraphQLAPI.cancel(promise, message);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Checks to see if an error thrown is from an api request cancellation
|
|
107
|
+
* @param {any} error - Any error
|
|
108
|
+
* @returns - A boolean indicating if the error was from an api request cancellation
|
|
109
|
+
*/
|
|
110
|
+
export function isCancelError(error) {
|
|
111
|
+
return GraphQLAPI.isCancelError(error);
|
|
112
|
+
}
|