@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-esm/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
|
|
@@ -7,7 +7,7 @@ import { APIValidationErrorCode, assertValidationError } from './errors';
|
|
|
7
7
|
*/
|
|
8
8
|
export var resolveConfig = function () {
|
|
9
9
|
var _a, _b;
|
|
10
|
-
var _c = (_b = (_a = Amplify.getConfig().API) === null || _a === void 0 ? void 0 : _a.
|
|
10
|
+
var _c = (_b = (_a = 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;
|
|
11
11
|
assertValidationError(!!endpoint, APIValidationErrorCode.NoAppId);
|
|
12
12
|
assertValidationError(!!region, APIValidationErrorCode.NoRegion);
|
|
13
13
|
assertValidationError(!!defaultAuthMode, APIValidationErrorCode.NoDefaultAuthMode);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/api-graphql",
|
|
3
|
-
"version": "4.0.1-console-preview.
|
|
3
|
+
"version": "4.0.1-console-preview.4ae78ed.0+4ae78ed",
|
|
4
4
|
"description": "Api-graphql category of aws-amplify",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib-esm/index.js",
|
|
@@ -47,13 +47,14 @@
|
|
|
47
47
|
"internals"
|
|
48
48
|
],
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@aws-amplify/api-rest": "4.0.1-console-preview.
|
|
51
|
-
"@aws-amplify/auth": "6.0.1-console-preview.
|
|
52
|
-
"@aws-amplify/core": "6.0.1-console-preview.
|
|
50
|
+
"@aws-amplify/api-rest": "4.0.1-console-preview.4ae78ed.0+4ae78ed",
|
|
51
|
+
"@aws-amplify/auth": "6.0.1-console-preview.4ae78ed.0+4ae78ed",
|
|
52
|
+
"@aws-amplify/core": "6.0.1-console-preview.4ae78ed.0+4ae78ed",
|
|
53
53
|
"@aws-sdk/types": "3.387.0",
|
|
54
54
|
"graphql": "15.8.0",
|
|
55
55
|
"rxjs": "^7.8.1",
|
|
56
56
|
"tslib": "^1.8.0",
|
|
57
|
+
"url": "0.11.0",
|
|
57
58
|
"uuid": "^3.2.1"
|
|
58
59
|
},
|
|
59
60
|
"size-limit": [
|
|
@@ -120,5 +121,5 @@
|
|
|
120
121
|
"<rootDir>/__tests__"
|
|
121
122
|
]
|
|
122
123
|
},
|
|
123
|
-
"gitHead": "
|
|
124
|
+
"gitHead": "4ae78ed23fc03ae718488c98fc48782d2bd6f5f3"
|
|
124
125
|
}
|
package/src/GraphQLAPI.ts
CHANGED
|
@@ -35,6 +35,24 @@ export class GraphQLAPIClass extends InternalGraphQLAPIClass {
|
|
|
35
35
|
): Observable<GraphQLResult<T>> | Promise<GraphQLResult<T>> {
|
|
36
36
|
return super.graphql(options, additionalHeaders);
|
|
37
37
|
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Checks to see if an error thrown is from an api request cancellation
|
|
41
|
+
* @param error - Any error
|
|
42
|
+
* @returns A boolean indicating if the error was from an api request cancellation
|
|
43
|
+
*/
|
|
44
|
+
isCancelError(error: any): boolean {
|
|
45
|
+
return super.isCancelError(error);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Cancels an inflight request. Only applicable for graphql queries and mutations
|
|
50
|
+
* @param {any} request - request to cancel
|
|
51
|
+
* @returns A boolean indicating if the request was cancelled
|
|
52
|
+
*/
|
|
53
|
+
cancel(request: Promise<any>, message?: string): boolean {
|
|
54
|
+
return super.cancel(request, message);
|
|
55
|
+
}
|
|
38
56
|
}
|
|
39
57
|
|
|
40
58
|
export const GraphQLAPI = new GraphQLAPIClass(null);
|
|
@@ -6,16 +6,24 @@ import * as url from 'url';
|
|
|
6
6
|
import { v4 as uuid } from 'uuid';
|
|
7
7
|
import { Buffer } from 'buffer';
|
|
8
8
|
import { Hub, fetchAuthSession } from '@aws-amplify/core';
|
|
9
|
+
import { signRequest } from '@aws-amplify/core/internals/aws-client-utils';
|
|
10
|
+
import {
|
|
11
|
+
APIAuthMode,
|
|
12
|
+
CustomUserAgentDetails,
|
|
13
|
+
Logger,
|
|
14
|
+
NonRetryableError,
|
|
15
|
+
USER_AGENT_HEADER,
|
|
16
|
+
getAmplifyUserAgent,
|
|
17
|
+
isNonRetryableError,
|
|
18
|
+
jitteredExponentialRetry,
|
|
19
|
+
DocumentType,
|
|
20
|
+
} from '@aws-amplify/core/internals/utils';
|
|
9
21
|
|
|
10
22
|
import {
|
|
11
23
|
CONTROL_MSG,
|
|
12
24
|
ConnectionState,
|
|
13
|
-
PubSubContent,
|
|
14
25
|
PubSubContentObserver,
|
|
15
26
|
} from '../../types/PubSub';
|
|
16
|
-
|
|
17
|
-
import { signRequest } from '@aws-amplify/core/internals/aws-client-utils';
|
|
18
|
-
|
|
19
27
|
import {
|
|
20
28
|
AMPLIFY_SYMBOL,
|
|
21
29
|
AWS_APPSYNC_REALTIME_HEADERS,
|
|
@@ -39,18 +47,6 @@ import {
|
|
|
39
47
|
ReconnectionMonitor,
|
|
40
48
|
} from '../../utils/ReconnectionMonitor';
|
|
41
49
|
|
|
42
|
-
import {
|
|
43
|
-
CustomUserAgentDetails,
|
|
44
|
-
Logger,
|
|
45
|
-
NonRetryableError,
|
|
46
|
-
USER_AGENT_HEADER,
|
|
47
|
-
getAmplifyUserAgent,
|
|
48
|
-
isNonRetryableError,
|
|
49
|
-
jitteredExponentialRetry,
|
|
50
|
-
GraphQLAuthMode,
|
|
51
|
-
} from '@aws-amplify/core/internals/utils';
|
|
52
|
-
import { DocumentType } from '@aws-amplify/api-rest';
|
|
53
|
-
|
|
54
50
|
const logger = new Logger('AWSAppSyncRealTimeProvider');
|
|
55
51
|
|
|
56
52
|
const dispatchApiEvent = payload => {
|
|
@@ -92,7 +88,7 @@ type ParsedMessagePayload = {
|
|
|
92
88
|
|
|
93
89
|
export interface AWSAppSyncRealTimeProviderOptions {
|
|
94
90
|
appSyncGraphqlEndpoint?: string;
|
|
95
|
-
authenticationType?:
|
|
91
|
+
authenticationType?: APIAuthMode;
|
|
96
92
|
query?: string;
|
|
97
93
|
variables?: Record<string, DocumentType>;
|
|
98
94
|
apiKey?: string;
|
|
@@ -197,6 +193,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
197
193
|
variables,
|
|
198
194
|
authenticationType,
|
|
199
195
|
additionalHeaders,
|
|
196
|
+
apiKey,
|
|
200
197
|
} = options || {};
|
|
201
198
|
|
|
202
199
|
return new Observable(observer => {
|
|
@@ -227,6 +224,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
227
224
|
authenticationType,
|
|
228
225
|
appSyncGraphqlEndpoint,
|
|
229
226
|
additionalHeaders,
|
|
227
|
+
apiKey,
|
|
230
228
|
},
|
|
231
229
|
observer,
|
|
232
230
|
subscriptionId,
|
|
@@ -875,6 +873,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
875
873
|
}
|
|
876
874
|
|
|
877
875
|
private async _awsRealTimeHeaderBasedAuth({
|
|
876
|
+
apiKey,
|
|
878
877
|
authenticationType,
|
|
879
878
|
payload,
|
|
880
879
|
canonicalUri,
|
|
@@ -885,32 +884,34 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
885
884
|
Record<string, unknown> | undefined
|
|
886
885
|
> {
|
|
887
886
|
const headerHandler: {
|
|
888
|
-
[key
|
|
887
|
+
[key in APIAuthMode]: (arg0: AWSAppSyncRealTimeAuthInput) => {};
|
|
889
888
|
} = {
|
|
890
889
|
apiKey: this._awsRealTimeApiKeyHeader.bind(this),
|
|
891
890
|
iam: this._awsRealTimeIAMHeader.bind(this),
|
|
892
|
-
|
|
893
|
-
|
|
891
|
+
oidc: this._awsAuthTokenHeader.bind(this),
|
|
892
|
+
userPool: this._awsAuthTokenHeader.bind(this),
|
|
893
|
+
lambda: this._customAuthHeader,
|
|
894
|
+
none: this._customAuthHeader,
|
|
894
895
|
};
|
|
895
896
|
|
|
896
|
-
if (!authenticationType || !headerHandler[authenticationType
|
|
897
|
+
if (!authenticationType || !headerHandler[authenticationType]) {
|
|
897
898
|
logger.debug(`Authentication type ${authenticationType} not supported`);
|
|
898
899
|
return undefined;
|
|
899
900
|
} else {
|
|
900
|
-
const handler = headerHandler[authenticationType
|
|
901
|
+
const handler = headerHandler[authenticationType];
|
|
901
902
|
|
|
902
903
|
const { host } = url.parse(appSyncGraphqlEndpoint ?? '');
|
|
903
904
|
|
|
904
905
|
logger.debug(`Authenticating with ${JSON.stringify(authenticationType)}`);
|
|
905
|
-
let
|
|
906
|
-
if (authenticationType
|
|
907
|
-
|
|
906
|
+
let resolvedApiKey;
|
|
907
|
+
if (authenticationType === 'apiKey') {
|
|
908
|
+
resolvedApiKey = apiKey;
|
|
908
909
|
}
|
|
909
910
|
const result = await handler({
|
|
910
911
|
payload,
|
|
911
912
|
canonicalUri,
|
|
912
913
|
appSyncGraphqlEndpoint,
|
|
913
|
-
apiKey,
|
|
914
|
+
apiKey: resolvedApiKey,
|
|
914
915
|
region,
|
|
915
916
|
host,
|
|
916
917
|
additionalHeaders,
|
|
@@ -920,9 +921,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
920
921
|
}
|
|
921
922
|
}
|
|
922
923
|
|
|
923
|
-
private async
|
|
924
|
-
host,
|
|
925
|
-
}: AWSAppSyncRealTimeAuthInput) {
|
|
924
|
+
private async _awsAuthTokenHeader({ host }: AWSAppSyncRealTimeAuthInput) {
|
|
926
925
|
const session = await fetchAuthSession();
|
|
927
926
|
|
|
928
927
|
return {
|
|
@@ -11,6 +11,7 @@ import {
|
|
|
11
11
|
import { Observable } from 'rxjs';
|
|
12
12
|
import { Amplify, Cache, fetchAuthSession } from '@aws-amplify/core';
|
|
13
13
|
import {
|
|
14
|
+
APIAuthMode,
|
|
14
15
|
CustomUserAgentDetails,
|
|
15
16
|
ConsoleLogger as Logger,
|
|
16
17
|
getAmplifyUserAgent,
|
|
@@ -21,7 +22,12 @@ import {
|
|
|
21
22
|
GraphQLOperation,
|
|
22
23
|
GraphQLOptions,
|
|
23
24
|
} from '../types';
|
|
24
|
-
import {
|
|
25
|
+
import { isCancelError as isCancelErrorREST } from '@aws-amplify/api-rest';
|
|
26
|
+
import {
|
|
27
|
+
post,
|
|
28
|
+
cancel as cancelREST,
|
|
29
|
+
updateRequestToBeCancellable,
|
|
30
|
+
} from '@aws-amplify/api-rest/internals';
|
|
25
31
|
import { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvider';
|
|
26
32
|
|
|
27
33
|
const USER_AGENT_HEADER = 'x-amz-user-agent';
|
|
@@ -49,7 +55,7 @@ export class InternalGraphQLAPIClass {
|
|
|
49
55
|
private appSyncRealTime: AWSAppSyncRealTimeProvider | null;
|
|
50
56
|
|
|
51
57
|
Cache = Cache;
|
|
52
|
-
private _api = { post };
|
|
58
|
+
private _api = { post, updateRequestToBeCancellable };
|
|
53
59
|
|
|
54
60
|
/**
|
|
55
61
|
* Initialize GraphQL API with AWS configuration
|
|
@@ -65,26 +71,27 @@ export class InternalGraphQLAPIClass {
|
|
|
65
71
|
}
|
|
66
72
|
|
|
67
73
|
private async _headerBasedAuth(
|
|
68
|
-
|
|
69
|
-
additionalHeaders: { [key: string]: string } = {}
|
|
70
|
-
customUserAgentDetails?: CustomUserAgentDetails
|
|
74
|
+
authMode: APIAuthMode,
|
|
75
|
+
additionalHeaders: { [key: string]: string } = {}
|
|
71
76
|
) {
|
|
72
77
|
const config = Amplify.getConfig();
|
|
73
78
|
const {
|
|
74
79
|
region: region,
|
|
75
80
|
endpoint: appSyncGraphqlEndpoint,
|
|
76
|
-
|
|
77
|
-
|
|
81
|
+
apiKey,
|
|
82
|
+
defaultAuthMode,
|
|
83
|
+
} = config.API.GraphQL;
|
|
78
84
|
|
|
85
|
+
const authenticationType = authMode || defaultAuthMode || 'iam';
|
|
79
86
|
let headers = {};
|
|
80
87
|
|
|
81
|
-
switch (authenticationType
|
|
88
|
+
switch (authenticationType) {
|
|
82
89
|
case 'apiKey':
|
|
83
|
-
if (!
|
|
90
|
+
if (!apiKey) {
|
|
84
91
|
throw new Error(GraphQLAuthError.NO_API_KEY);
|
|
85
92
|
}
|
|
86
93
|
headers = {
|
|
87
|
-
'X-Api-Key':
|
|
94
|
+
'X-Api-Key': apiKey,
|
|
88
95
|
};
|
|
89
96
|
break;
|
|
90
97
|
case 'iam':
|
|
@@ -93,7 +100,8 @@ export class InternalGraphQLAPIClass {
|
|
|
93
100
|
throw new Error(GraphQLAuthError.NO_CREDENTIALS);
|
|
94
101
|
}
|
|
95
102
|
break;
|
|
96
|
-
case '
|
|
103
|
+
case 'oidc':
|
|
104
|
+
case 'userPool':
|
|
97
105
|
try {
|
|
98
106
|
let token;
|
|
99
107
|
|
|
@@ -109,7 +117,7 @@ export class InternalGraphQLAPIClass {
|
|
|
109
117
|
throw new Error(GraphQLAuthError.NO_CURRENT_USER);
|
|
110
118
|
}
|
|
111
119
|
break;
|
|
112
|
-
case '
|
|
120
|
+
case 'lambda':
|
|
113
121
|
if (!additionalHeaders.Authorization) {
|
|
114
122
|
throw new Error(GraphQLAuthError.NO_AUTH_TOKEN);
|
|
115
123
|
}
|
|
@@ -117,6 +125,8 @@ export class InternalGraphQLAPIClass {
|
|
|
117
125
|
Authorization: additionalHeaders.Authorization,
|
|
118
126
|
};
|
|
119
127
|
break;
|
|
128
|
+
case 'none':
|
|
129
|
+
break;
|
|
120
130
|
default:
|
|
121
131
|
headers = {
|
|
122
132
|
Authorization: null,
|
|
@@ -173,11 +183,17 @@ export class InternalGraphQLAPIClass {
|
|
|
173
183
|
switch (operationType) {
|
|
174
184
|
case 'query':
|
|
175
185
|
case 'mutation':
|
|
186
|
+
const abortController = new AbortController();
|
|
176
187
|
const responsePromise = this._graphql<T>(
|
|
177
188
|
{ query, variables, authMode },
|
|
178
189
|
headers,
|
|
190
|
+
abortController,
|
|
179
191
|
customUserAgentDetails
|
|
180
192
|
);
|
|
193
|
+
this._api.updateRequestToBeCancellable(
|
|
194
|
+
responsePromise,
|
|
195
|
+
abortController
|
|
196
|
+
);
|
|
181
197
|
return responsePromise;
|
|
182
198
|
case 'subscription':
|
|
183
199
|
return this._graphqlSubscribe(
|
|
@@ -193,30 +209,23 @@ export class InternalGraphQLAPIClass {
|
|
|
193
209
|
private async _graphql<T = any>(
|
|
194
210
|
{ query, variables, authMode }: GraphQLOptions,
|
|
195
211
|
additionalHeaders = {},
|
|
212
|
+
abortController: AbortController,
|
|
196
213
|
customUserAgentDetails?: CustomUserAgentDetails
|
|
197
214
|
): Promise<GraphQLResult<T>> {
|
|
198
215
|
const config = Amplify.getConfig();
|
|
199
216
|
|
|
200
217
|
const { region: region, endpoint: appSyncGraphqlEndpoint } =
|
|
201
|
-
config.API.
|
|
218
|
+
config.API.GraphQL;
|
|
202
219
|
|
|
203
220
|
const customGraphqlEndpoint = null;
|
|
204
221
|
const customEndpointRegion = null;
|
|
205
222
|
|
|
206
223
|
const headers = {
|
|
207
224
|
...(!customGraphqlEndpoint &&
|
|
208
|
-
(await this._headerBasedAuth(
|
|
209
|
-
authMode,
|
|
210
|
-
additionalHeaders,
|
|
211
|
-
customUserAgentDetails
|
|
212
|
-
))),
|
|
225
|
+
(await this._headerBasedAuth(authMode, additionalHeaders))),
|
|
213
226
|
...(customGraphqlEndpoint &&
|
|
214
227
|
(customEndpointRegion
|
|
215
|
-
? await this._headerBasedAuth(
|
|
216
|
-
authMode,
|
|
217
|
-
additionalHeaders,
|
|
218
|
-
customUserAgentDetails
|
|
219
|
-
)
|
|
228
|
+
? await this._headerBasedAuth(authMode, additionalHeaders)
|
|
220
229
|
: { Authorization: null })),
|
|
221
230
|
...additionalHeaders,
|
|
222
231
|
...(!customGraphqlEndpoint && {
|
|
@@ -242,13 +251,30 @@ export class InternalGraphQLAPIClass {
|
|
|
242
251
|
|
|
243
252
|
let response;
|
|
244
253
|
try {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
254
|
+
const { body: responseBody } = await this._api.post({
|
|
255
|
+
url: new URL(endpoint),
|
|
256
|
+
options: {
|
|
257
|
+
headers,
|
|
258
|
+
body,
|
|
259
|
+
signingServiceInfo: {
|
|
260
|
+
service: 'appsync',
|
|
261
|
+
region,
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
abortController,
|
|
250
265
|
});
|
|
266
|
+
|
|
267
|
+
const result = await responseBody.json();
|
|
268
|
+
|
|
269
|
+
response = result;
|
|
251
270
|
} catch (err) {
|
|
271
|
+
// If the exception is because user intentionally
|
|
272
|
+
// cancelled the request, do not modify the exception
|
|
273
|
+
// so that clients can identify the exception correctly.
|
|
274
|
+
if (isCancelErrorREST(err)) {
|
|
275
|
+
throw err;
|
|
276
|
+
}
|
|
277
|
+
|
|
252
278
|
response = {
|
|
253
279
|
data: {},
|
|
254
280
|
errors: [new GraphQLError(err.message, null, null, null, null, err)],
|
|
@@ -264,27 +290,45 @@ export class InternalGraphQLAPIClass {
|
|
|
264
290
|
return response;
|
|
265
291
|
}
|
|
266
292
|
|
|
293
|
+
/**
|
|
294
|
+
* Checks to see if an error thrown is from an api request cancellation
|
|
295
|
+
* @param {any} error - Any error
|
|
296
|
+
* @return {boolean} - A boolean indicating if the error was from an api request cancellation
|
|
297
|
+
*/
|
|
298
|
+
isCancelError(error: any): boolean {
|
|
299
|
+
return isCancelErrorREST(error);
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/**
|
|
303
|
+
* Cancels an inflight request. Only applicable for graphql queries and mutations
|
|
304
|
+
* @param {any} request - request to cancel
|
|
305
|
+
* @returns - A boolean indicating if the request was cancelled
|
|
306
|
+
*/
|
|
307
|
+
cancel(request: Promise<any>, message?: string): boolean {
|
|
308
|
+
return cancelREST(request, message);
|
|
309
|
+
}
|
|
310
|
+
|
|
267
311
|
private _graphqlSubscribe(
|
|
268
|
-
{
|
|
269
|
-
query,
|
|
270
|
-
variables,
|
|
271
|
-
authMode: defaultAuthenticationType,
|
|
272
|
-
authToken,
|
|
273
|
-
}: GraphQLOptions,
|
|
312
|
+
{ query, variables, authMode }: GraphQLOptions,
|
|
274
313
|
additionalHeaders = {},
|
|
275
314
|
customUserAgentDetails?: CustomUserAgentDetails
|
|
276
315
|
): Observable<any> {
|
|
277
|
-
const {
|
|
316
|
+
const { GraphQL } = Amplify.getConfig().API ?? {};
|
|
278
317
|
if (!this.appSyncRealTime) {
|
|
279
318
|
this.appSyncRealTime = new AWSAppSyncRealTimeProvider();
|
|
280
319
|
}
|
|
281
|
-
return this.appSyncRealTime.subscribe(
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
320
|
+
return this.appSyncRealTime.subscribe(
|
|
321
|
+
{
|
|
322
|
+
query: print(query as DocumentNode),
|
|
323
|
+
variables,
|
|
324
|
+
appSyncGraphqlEndpoint: GraphQL?.endpoint,
|
|
325
|
+
region: GraphQL?.region,
|
|
326
|
+
authenticationType: authMode ?? GraphQL?.defaultAuthMode,
|
|
327
|
+
apiKey: GraphQL?.apiKey,
|
|
328
|
+
additionalHeaders,
|
|
329
|
+
},
|
|
330
|
+
customUserAgentDetails
|
|
331
|
+
);
|
|
288
332
|
}
|
|
289
333
|
}
|
|
290
334
|
|
package/src/internals/index.ts
CHANGED
package/src/internals/v6.ts
CHANGED
|
@@ -103,4 +103,22 @@ export function graphql<
|
|
|
103
103
|
return result as any;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
+
/**
|
|
107
|
+
* Cancels an inflight request. Only applicable for graphql queries and mutations
|
|
108
|
+
* @param {any} request - request to cancel
|
|
109
|
+
* @returns - A boolean indicating if the request was cancelled
|
|
110
|
+
*/
|
|
111
|
+
export function cancel(promise: Promise<any>, message?: string): boolean {
|
|
112
|
+
return GraphQLAPI.cancel(promise, message);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Checks to see if an error thrown is from an api request cancellation
|
|
117
|
+
* @param {any} error - Any error
|
|
118
|
+
* @returns - A boolean indicating if the error was from an api request cancellation
|
|
119
|
+
*/
|
|
120
|
+
export function isCancelError(error: any): boolean {
|
|
121
|
+
return GraphQLAPI.isCancelError(error);
|
|
122
|
+
}
|
|
123
|
+
|
|
106
124
|
export { GraphQLOptionsV6, GraphQLResponseV6 };
|
package/src/types/index.ts
CHANGED
|
@@ -4,8 +4,7 @@ import { Source, DocumentNode, GraphQLError } from 'graphql';
|
|
|
4
4
|
export { OperationTypeNode } from 'graphql';
|
|
5
5
|
import { Observable } from 'rxjs';
|
|
6
6
|
|
|
7
|
-
import { DocumentType } from '@aws-amplify/
|
|
8
|
-
import { GraphQLAuthModeKeys } from '@aws-amplify/core/internals/utils';
|
|
7
|
+
import { APIAuthMode, DocumentType } from '@aws-amplify/core/internals/utils';
|
|
9
8
|
export { CONTROL_MSG, ConnectionState } from './PubSub';
|
|
10
9
|
/**
|
|
11
10
|
* Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
|
|
@@ -13,7 +12,7 @@ export { CONTROL_MSG, ConnectionState } from './PubSub';
|
|
|
13
12
|
export interface GraphQLOptions {
|
|
14
13
|
query: string | DocumentNode;
|
|
15
14
|
variables?: Record<string, DocumentType>;
|
|
16
|
-
authMode?:
|
|
15
|
+
authMode?: APIAuthMode;
|
|
17
16
|
authToken?: string;
|
|
18
17
|
/**
|
|
19
18
|
* @deprecated This property should not be used
|
|
@@ -83,7 +82,7 @@ export type GraphqlSubscriptionMessage<T> = {
|
|
|
83
82
|
|
|
84
83
|
export interface AWSAppSyncRealTimeProviderOptions {
|
|
85
84
|
appSyncGraphqlEndpoint?: string;
|
|
86
|
-
authenticationType?:
|
|
85
|
+
authenticationType?: APIAuthMode;
|
|
87
86
|
query?: string;
|
|
88
87
|
variables?: Record<string, unknown>;
|
|
89
88
|
apiKey?: string;
|
|
@@ -122,7 +121,7 @@ export interface GraphQLOptionsV6<
|
|
|
122
121
|
> {
|
|
123
122
|
query: TYPED_GQL_STRING | DocumentNode;
|
|
124
123
|
variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
125
|
-
authMode?:
|
|
124
|
+
authMode?: APIAuthMode;
|
|
126
125
|
authToken?: string;
|
|
127
126
|
/**
|
|
128
127
|
* @deprecated This property should not be used
|
|
@@ -9,7 +9,7 @@ import { APIValidationErrorCode, assertValidationError } from './errors';
|
|
|
9
9
|
*/
|
|
10
10
|
export const resolveConfig = () => {
|
|
11
11
|
const { region, defaultAuthMode, endpoint } =
|
|
12
|
-
Amplify.getConfig().API?.
|
|
12
|
+
Amplify.getConfig().API?.GraphQL ?? {};
|
|
13
13
|
assertValidationError(!!endpoint, APIValidationErrorCode.NoAppId);
|
|
14
14
|
assertValidationError(!!region, APIValidationErrorCode.NoRegion);
|
|
15
15
|
assertValidationError(
|