@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.
@@ -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/api-rest';
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?: GraphQLAuthModeKeys;
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?: GraphQLAuthModeKeys;
107
+ authMode?: APIAuthMode;
109
108
  authToken?: string;
110
109
  /**
111
110
  * @deprecated This property should not be used
@@ -4,5 +4,5 @@
4
4
  export declare const resolveConfig: () => {
5
5
  endpoint: string;
6
6
  region: string;
7
- defaultAuthMode: import("@aws-amplify/core/lib-esm/libraryUtils").GraphQLAuthMode;
7
+ defaultAuthMode: import("@aws-amplify/core/lib-esm/libraryUtils").APIAuthMode;
8
8
  };
@@ -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.AppSync) !== null && _b !== void 0 ? _b : {}, region = _c.region, defaultAuthMode = _c.defaultAuthMode, endpoint = _c.endpoint;
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);
@@ -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?: GraphQLAuthMode;
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 _awsRealTimeOPENIDHeader;
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, apiKey, result;
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
- jwt: this._awsRealTimeOPENIDHeader.bind(this),
691
- custom: this._customAuthHeader,
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.type])) return [3 /*break*/, 1];
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.type];
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
- apiKey = void 0;
701
- if (authenticationType.type === 'apiKey') {
702
- apiKey = authenticationType.apiKey;
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: 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._awsRealTimeOPENIDHeader = function (_a) {
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 () {
@@ -5,7 +5,7 @@ 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 { post } from '@aws-amplify/api-rest';
8
+ import { post } from '@aws-amplify/api-rest/internals';
9
9
  import { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvider';
10
10
  var USER_AGENT_HEADER = 'x-amz-user-agent';
11
11
  var logger = new Logger('GraphQLAPI');
@@ -38,36 +38,38 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
38
38
  if (additionalHeaders === void 0) { additionalHeaders = {}; }
39
39
  var _a;
40
40
  return __awaiter(this, void 0, void 0, function () {
41
- var config, _b, region, appSyncGraphqlEndpoint, authenticationType, headers, _c, session, token, e_1;
41
+ var config, _b, region, appSyncGraphqlEndpoint, apiKey, defaultAuthMode, headers, _c, session, token, e_1;
42
42
  return __generator(this, function (_d) {
43
43
  switch (_d.label) {
44
44
  case 0:
45
45
  config = Amplify.getConfig();
46
- _b = config.API.AppSync, region = _b.region, appSyncGraphqlEndpoint = _b.endpoint, authenticationType = _b.defaultAuthMode;
46
+ _b = config.API.GraphQL, region = _b.region, appSyncGraphqlEndpoint = _b.endpoint, apiKey = _b.apiKey, defaultAuthMode = _b.defaultAuthMode;
47
47
  headers = {};
48
- _c = authenticationType.type;
48
+ _c = defaultAuthMode;
49
49
  switch (_c) {
50
50
  case 'apiKey': return [3 /*break*/, 1];
51
51
  case 'iam': return [3 /*break*/, 2];
52
- case 'jwt': return [3 /*break*/, 4];
53
- case 'custom': return [3 /*break*/, 8];
52
+ case 'oidc': return [3 /*break*/, 4];
53
+ case 'userPool': return [3 /*break*/, 4];
54
+ case 'lambda': return [3 /*break*/, 8];
55
+ case 'none': return [3 /*break*/, 9];
54
56
  }
55
- return [3 /*break*/, 9];
57
+ return [3 /*break*/, 10];
56
58
  case 1:
57
- if (!authenticationType.apiKey) {
59
+ if (!apiKey) {
58
60
  throw new Error(GraphQLAuthError.NO_API_KEY);
59
61
  }
60
62
  headers = {
61
- 'X-Api-Key': authenticationType.apiKey,
63
+ 'X-Api-Key': apiKey,
62
64
  };
63
- return [3 /*break*/, 10];
65
+ return [3 /*break*/, 11];
64
66
  case 2: return [4 /*yield*/, fetchAuthSession()];
65
67
  case 3:
66
68
  session = _d.sent();
67
69
  if (session.credentials === undefined) {
68
70
  throw new Error(GraphQLAuthError.NO_CREDENTIALS);
69
71
  }
70
- return [3 /*break*/, 10];
72
+ return [3 /*break*/, 11];
71
73
  case 4:
72
74
  _d.trys.push([4, 6, , 7]);
73
75
  token = void 0;
@@ -84,7 +86,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
84
86
  case 6:
85
87
  e_1 = _d.sent();
86
88
  throw new Error(GraphQLAuthError.NO_CURRENT_USER);
87
- case 7: return [3 /*break*/, 10];
89
+ case 7: return [3 /*break*/, 11];
88
90
  case 8:
89
91
  if (!additionalHeaders.Authorization) {
90
92
  throw new Error(GraphQLAuthError.NO_AUTH_TOKEN);
@@ -92,13 +94,14 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
92
94
  headers = {
93
95
  Authorization: additionalHeaders.Authorization,
94
96
  };
95
- return [3 /*break*/, 10];
96
- case 9:
97
+ return [3 /*break*/, 11];
98
+ case 9: return [3 /*break*/, 11];
99
+ case 10:
97
100
  headers = {
98
101
  Authorization: null,
99
102
  };
100
- return [3 /*break*/, 10];
101
- case 10: return [2 /*return*/, headers];
103
+ return [3 /*break*/, 11];
104
+ case 11: return [2 /*return*/, headers];
102
105
  }
103
106
  });
104
107
  });
@@ -147,13 +150,13 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
147
150
  var query = _a.query, variables = _a.variables, authMode = _a.authMode;
148
151
  if (additionalHeaders === void 0) { additionalHeaders = {}; }
149
152
  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;
153
+ var config, _b, region, appSyncGraphqlEndpoint, customGraphqlEndpoint, customEndpointRegion, headers, _c, _d, _e, _f, _g, body, endpoint, error, response, responsePayload, err_1, errors;
151
154
  var _h;
152
155
  return __generator(this, function (_j) {
153
156
  switch (_j.label) {
154
157
  case 0:
155
158
  config = Amplify.getConfig();
156
- _b = config.API.AppSync, region = _b.region, appSyncGraphqlEndpoint = _b.endpoint;
159
+ _b = config.API.GraphQL, region = _b.region, appSyncGraphqlEndpoint = _b.endpoint;
157
160
  customGraphqlEndpoint = null;
158
161
  customEndpointRegion = null;
159
162
  _c = [{}];
@@ -196,24 +199,32 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
196
199
  }
197
200
  _j.label = 7;
198
201
  case 7:
199
- _j.trys.push([7, 9, , 10]);
200
- return [4 /*yield*/, this._api.post(endpoint, {
201
- headers: headers,
202
- body: body,
203
- region: region,
204
- serviceName: 'appsync',
202
+ _j.trys.push([7, 10, , 11]);
203
+ return [4 /*yield*/, this._api.post({
204
+ url: new URL(endpoint),
205
+ options: {
206
+ headers: headers,
207
+ body: body,
208
+ signingServiceInfo: {
209
+ service: 'appsync',
210
+ region: region,
211
+ },
212
+ },
205
213
  })];
206
214
  case 8:
207
- response = _j.sent();
208
- return [3 /*break*/, 10];
215
+ responsePayload = (_j.sent()).body;
216
+ return [4 /*yield*/, responsePayload.json()];
209
217
  case 9:
218
+ response = _j.sent();
219
+ return [3 /*break*/, 11];
220
+ case 10:
210
221
  err_1 = _j.sent();
211
222
  response = {
212
223
  data: {},
213
224
  errors: [new GraphQLError(err_1.message, null, null, null, null, err_1)],
214
225
  };
215
- return [3 /*break*/, 10];
216
- case 10:
226
+ return [3 /*break*/, 11];
227
+ case 11:
217
228
  errors = response.errors;
218
229
  if (errors && errors.length) {
219
230
  throw response;
@@ -227,16 +238,17 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
227
238
  var query = _a.query, variables = _a.variables, defaultAuthenticationType = _a.authMode, authToken = _a.authToken;
228
239
  if (additionalHeaders === void 0) { additionalHeaders = {}; }
229
240
  var _b;
230
- var AppSync = ((_b = Amplify.getConfig().API) !== null && _b !== void 0 ? _b : {}).AppSync;
241
+ var GraphQL = ((_b = Amplify.getConfig().API) !== null && _b !== void 0 ? _b : {}).GraphQL;
231
242
  if (!this.appSyncRealTime) {
232
243
  this.appSyncRealTime = new AWSAppSyncRealTimeProvider();
233
244
  }
234
245
  return this.appSyncRealTime.subscribe({
235
246
  query: print(query),
236
247
  variables: variables,
237
- appSyncGraphqlEndpoint: AppSync === null || AppSync === void 0 ? void 0 : AppSync.endpoint,
238
- region: AppSync === null || AppSync === void 0 ? void 0 : AppSync.region,
239
- authenticationType: AppSync === null || AppSync === void 0 ? void 0 : AppSync.defaultAuthMode,
248
+ appSyncGraphqlEndpoint: GraphQL === null || GraphQL === void 0 ? void 0 : GraphQL.endpoint,
249
+ region: GraphQL === null || GraphQL === void 0 ? void 0 : GraphQL.region,
250
+ authenticationType: GraphQL === null || GraphQL === void 0 ? void 0 : GraphQL.defaultAuthMode,
251
+ apiKey: GraphQL === null || GraphQL === void 0 ? void 0 : GraphQL.apiKey,
240
252
  });
241
253
  };
242
254
  return InternalGraphQLAPIClass;