@aws-amplify/api-graphql 4.0.1-console-preview.deaebd5.0 → 4.0.1-console-preview.b5a42af.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/Providers/AWSAppSyncRealTimeProvider/index.d.ts +3 -4
- package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +17 -14
- package/lib/internals/InternalGraphQLAPI.js +45 -33
- package/lib/tsconfig.tsbuildinfo +890 -820
- package/lib/types/index.d.ts +3 -4
- package/lib/utils/resolveConfig.d.ts +1 -1
- package/lib/utils/resolveConfig.js +1 -1
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +3 -4
- package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +17 -14
- package/lib-esm/internals/InternalGraphQLAPI.js +44 -32
- package/lib-esm/tsconfig.tsbuildinfo +890 -820
- package/lib-esm/types/index.d.ts +3 -4
- package/lib-esm/utils/resolveConfig.d.ts +1 -1
- package/lib-esm/utils/resolveConfig.js +1 -1
- package/package.json +5 -5
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +28 -29
- package/src/internals/InternalGraphQLAPI.ts +29 -18
- package/src/types/index.ts +3 -4
- 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()`.
|
|
@@ -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.b5a42af.0+b5a42af",
|
|
4
4
|
"description": "Api-graphql category of aws-amplify",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib-esm/index.js",
|
|
@@ -47,9 +47,9 @@
|
|
|
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.b5a42af.0+b5a42af",
|
|
51
|
+
"@aws-amplify/auth": "6.0.1-console-preview.b5a42af.0+b5a42af",
|
|
52
|
+
"@aws-amplify/core": "6.0.1-console-preview.b5a42af.0+b5a42af",
|
|
53
53
|
"@aws-sdk/types": "3.387.0",
|
|
54
54
|
"graphql": "15.8.0",
|
|
55
55
|
"rxjs": "^7.8.1",
|
|
@@ -120,5 +120,5 @@
|
|
|
120
120
|
"<rootDir>/__tests__"
|
|
121
121
|
]
|
|
122
122
|
},
|
|
123
|
-
"gitHead": "
|
|
123
|
+
"gitHead": "b5a42af519fb741bb8056a814addd8804c8f60ec"
|
|
124
124
|
}
|
|
@@ -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 {
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
GraphQLOperation,
|
|
22
22
|
GraphQLOptions,
|
|
23
23
|
} from '../types';
|
|
24
|
-
import { post } from '@aws-amplify/api-rest';
|
|
24
|
+
import { post } from '@aws-amplify/api-rest/internals';
|
|
25
25
|
import { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvider';
|
|
26
26
|
|
|
27
27
|
const USER_AGENT_HEADER = 'x-amz-user-agent';
|
|
@@ -73,18 +73,19 @@ export class InternalGraphQLAPIClass {
|
|
|
73
73
|
const {
|
|
74
74
|
region: region,
|
|
75
75
|
endpoint: appSyncGraphqlEndpoint,
|
|
76
|
-
|
|
77
|
-
|
|
76
|
+
apiKey,
|
|
77
|
+
defaultAuthMode,
|
|
78
|
+
} = config.API.GraphQL;
|
|
78
79
|
|
|
79
80
|
let headers = {};
|
|
80
81
|
|
|
81
|
-
switch (
|
|
82
|
+
switch (defaultAuthMode) {
|
|
82
83
|
case 'apiKey':
|
|
83
|
-
if (!
|
|
84
|
+
if (!apiKey) {
|
|
84
85
|
throw new Error(GraphQLAuthError.NO_API_KEY);
|
|
85
86
|
}
|
|
86
87
|
headers = {
|
|
87
|
-
'X-Api-Key':
|
|
88
|
+
'X-Api-Key': apiKey,
|
|
88
89
|
};
|
|
89
90
|
break;
|
|
90
91
|
case 'iam':
|
|
@@ -93,7 +94,8 @@ export class InternalGraphQLAPIClass {
|
|
|
93
94
|
throw new Error(GraphQLAuthError.NO_CREDENTIALS);
|
|
94
95
|
}
|
|
95
96
|
break;
|
|
96
|
-
case '
|
|
97
|
+
case 'oidc':
|
|
98
|
+
case 'userPool':
|
|
97
99
|
try {
|
|
98
100
|
let token;
|
|
99
101
|
|
|
@@ -109,7 +111,7 @@ export class InternalGraphQLAPIClass {
|
|
|
109
111
|
throw new Error(GraphQLAuthError.NO_CURRENT_USER);
|
|
110
112
|
}
|
|
111
113
|
break;
|
|
112
|
-
case '
|
|
114
|
+
case 'lambda':
|
|
113
115
|
if (!additionalHeaders.Authorization) {
|
|
114
116
|
throw new Error(GraphQLAuthError.NO_AUTH_TOKEN);
|
|
115
117
|
}
|
|
@@ -117,6 +119,8 @@ export class InternalGraphQLAPIClass {
|
|
|
117
119
|
Authorization: additionalHeaders.Authorization,
|
|
118
120
|
};
|
|
119
121
|
break;
|
|
122
|
+
case 'none':
|
|
123
|
+
break;
|
|
120
124
|
default:
|
|
121
125
|
headers = {
|
|
122
126
|
Authorization: null,
|
|
@@ -198,7 +202,7 @@ export class InternalGraphQLAPIClass {
|
|
|
198
202
|
const config = Amplify.getConfig();
|
|
199
203
|
|
|
200
204
|
const { region: region, endpoint: appSyncGraphqlEndpoint } =
|
|
201
|
-
config.API.
|
|
205
|
+
config.API.GraphQL;
|
|
202
206
|
|
|
203
207
|
const customGraphqlEndpoint = null;
|
|
204
208
|
const customEndpointRegion = null;
|
|
@@ -242,12 +246,18 @@ export class InternalGraphQLAPIClass {
|
|
|
242
246
|
|
|
243
247
|
let response;
|
|
244
248
|
try {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
249
|
+
const { body: responsePayload } = await this._api.post({
|
|
250
|
+
url: new URL(endpoint),
|
|
251
|
+
options: {
|
|
252
|
+
headers,
|
|
253
|
+
body,
|
|
254
|
+
signingServiceInfo: {
|
|
255
|
+
service: 'appsync',
|
|
256
|
+
region,
|
|
257
|
+
},
|
|
258
|
+
},
|
|
250
259
|
});
|
|
260
|
+
response = await responsePayload.json();
|
|
251
261
|
} catch (err) {
|
|
252
262
|
response = {
|
|
253
263
|
data: {},
|
|
@@ -274,16 +284,17 @@ export class InternalGraphQLAPIClass {
|
|
|
274
284
|
additionalHeaders = {},
|
|
275
285
|
customUserAgentDetails?: CustomUserAgentDetails
|
|
276
286
|
): Observable<any> {
|
|
277
|
-
const {
|
|
287
|
+
const { GraphQL } = Amplify.getConfig().API ?? {};
|
|
278
288
|
if (!this.appSyncRealTime) {
|
|
279
289
|
this.appSyncRealTime = new AWSAppSyncRealTimeProvider();
|
|
280
290
|
}
|
|
281
291
|
return this.appSyncRealTime.subscribe({
|
|
282
292
|
query: print(query as DocumentNode),
|
|
283
293
|
variables,
|
|
284
|
-
appSyncGraphqlEndpoint:
|
|
285
|
-
region:
|
|
286
|
-
authenticationType:
|
|
294
|
+
appSyncGraphqlEndpoint: GraphQL?.endpoint,
|
|
295
|
+
region: GraphQL?.region,
|
|
296
|
+
authenticationType: GraphQL?.defaultAuthMode,
|
|
297
|
+
apiKey: GraphQL?.apiKey,
|
|
287
298
|
});
|
|
288
299
|
}
|
|
289
300
|
}
|
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()`.
|
|
@@ -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(
|