@aws-amplify/api-graphql 4.0.1-console-preview.a1c533e.0 → 4.0.1-console-preview.23dc225.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.
Files changed (39) hide show
  1. package/lib/Providers/AWSAppSyncRealTimeProvider/index.d.ts +2 -2
  2. package/lib/Providers/AWSAppSyncRealTimeProvider/index.js +2 -3
  3. package/lib/internals/InternalGraphQLAPI.js +92 -65
  4. package/lib/tsconfig.tsbuildinfo +290 -197
  5. package/lib/types/index.d.ts +4 -4
  6. package/lib/utils/errors/validation.d.ts +2 -3
  7. package/lib/utils/errors/validation.js +10 -10
  8. package/lib/utils/index.d.ts +1 -1
  9. package/lib/utils/index.js +2 -2
  10. package/lib/utils/resolveConfig.d.ts +8 -4
  11. package/lib/utils/resolveConfig.js +13 -7
  12. package/lib/utils/resolveLibraryOptions.d.ts +11 -0
  13. package/lib/utils/resolveLibraryOptions.js +13 -0
  14. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +2 -2
  15. package/lib-esm/Providers/AWSAppSyncRealTimeProvider/index.js +3 -4
  16. package/lib-esm/internals/InternalGraphQLAPI.js +93 -66
  17. package/lib-esm/tsconfig.tsbuildinfo +290 -197
  18. package/lib-esm/types/index.d.ts +4 -4
  19. package/lib-esm/utils/errors/validation.d.ts +2 -3
  20. package/lib-esm/utils/errors/validation.js +10 -10
  21. package/lib-esm/utils/index.d.ts +1 -1
  22. package/lib-esm/utils/index.js +1 -1
  23. package/lib-esm/utils/resolveConfig.d.ts +8 -4
  24. package/lib-esm/utils/resolveConfig.js +13 -7
  25. package/lib-esm/utils/resolveLibraryOptions.d.ts +11 -0
  26. package/lib-esm/utils/resolveLibraryOptions.js +11 -0
  27. package/package.json +6 -7
  28. package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +7 -6
  29. package/src/internals/InternalGraphQLAPI.ts +75 -31
  30. package/src/types/index.ts +7 -4
  31. package/src/utils/errors/validation.ts +10 -10
  32. package/src/utils/index.ts +1 -1
  33. package/src/utils/resolveConfig.ts +24 -9
  34. package/src/utils/resolveLibraryOptions.ts +13 -0
  35. package/lib/utils/resolveCredentials.d.ts +0 -12
  36. package/lib/utils/resolveCredentials.js +0 -22
  37. package/lib-esm/utils/resolveCredentials.d.ts +0 -12
  38. package/lib-esm/utils/resolveCredentials.js +0 -20
  39. package/src/utils/resolveCredentials.ts +0 -14
@@ -2,7 +2,7 @@ import { AmplifyClassV6 } from '@aws-amplify/core';
2
2
  import { Source, DocumentNode, GraphQLError } from 'graphql';
3
3
  export { OperationTypeNode } from 'graphql';
4
4
  import { Observable } from 'rxjs';
5
- import { APIAuthMode, DocumentType } from '@aws-amplify/core/internals/utils';
5
+ import { GraphQLAuthMode, DocumentType } from '@aws-amplify/core/internals/utils';
6
6
  export { CONTROL_MSG, ConnectionState } from './PubSub';
7
7
  /**
8
8
  * Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
@@ -10,7 +10,7 @@ export { CONTROL_MSG, ConnectionState } from './PubSub';
10
10
  export interface GraphQLOptions {
11
11
  query: string | DocumentNode;
12
12
  variables?: Record<string, DocumentType>;
13
- authMode?: APIAuthMode;
13
+ authMode?: GraphQLAuthMode;
14
14
  authToken?: string;
15
15
  /**
16
16
  * @deprecated This property should not be used
@@ -133,7 +133,7 @@ export declare type GraphqlSubscriptionMessage<T> = {
133
133
  };
134
134
  export interface AWSAppSyncRealTimeProviderOptions {
135
135
  appSyncGraphqlEndpoint?: string;
136
- authenticationType?: APIAuthMode;
136
+ authenticationType?: GraphQLAuthMode;
137
137
  query?: string;
138
138
  variables?: Record<string, unknown>;
139
139
  apiKey?: string;
@@ -165,7 +165,7 @@ export declare type GraphQLOperation = Source | string;
165
165
  export interface GraphQLOptionsV6<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string> {
166
166
  query: TYPED_GQL_STRING | DocumentNode;
167
167
  variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
168
- authMode?: APIAuthMode;
168
+ authMode?: GraphQLAuthMode;
169
169
  authToken?: string;
170
170
  /**
171
171
  * @deprecated This property should not be used
@@ -1,8 +1,7 @@
1
1
  import { AmplifyErrorMap } from '@aws-amplify/core/internals/utils';
2
2
  export declare enum APIValidationErrorCode {
3
- NoAppId = "NoAppId",
4
- NoCredentials = "NoCredentials",
3
+ NoAuthSession = "NoAuthSession",
5
4
  NoRegion = "NoRegion",
6
- NoDefaultAuthMode = "NoDefaultAuthMode"
5
+ NoCustomEndpoint = "NoCustomEndpoint"
7
6
  }
8
7
  export declare const validationErrorMap: AmplifyErrorMap<APIValidationErrorCode>;
@@ -3,22 +3,22 @@
3
3
  var _a;
4
4
  export var APIValidationErrorCode;
5
5
  (function (APIValidationErrorCode) {
6
- APIValidationErrorCode["NoAppId"] = "NoAppId";
7
- APIValidationErrorCode["NoCredentials"] = "NoCredentials";
6
+ APIValidationErrorCode["NoAuthSession"] = "NoAuthSession";
8
7
  APIValidationErrorCode["NoRegion"] = "NoRegion";
9
- APIValidationErrorCode["NoDefaultAuthMode"] = "NoDefaultAuthMode";
8
+ APIValidationErrorCode["NoCustomEndpoint"] = "NoCustomEndpoint";
10
9
  })(APIValidationErrorCode || (APIValidationErrorCode = {}));
11
10
  export var validationErrorMap = (_a = {},
12
- _a[APIValidationErrorCode.NoAppId] = {
13
- message: 'Missing application id.',
14
- },
15
- _a[APIValidationErrorCode.NoCredentials] = {
16
- message: 'Credentials should not be empty.',
11
+ _a[APIValidationErrorCode.NoAuthSession] = {
12
+ message: 'Auth session should not be empty.',
17
13
  },
14
+ // TODO: re-enable when working in all test environments:
15
+ // [APIValidationErrorCode.NoEndpoint]: {
16
+ // message: 'Missing endpoint',
17
+ // },
18
18
  _a[APIValidationErrorCode.NoRegion] = {
19
19
  message: 'Missing region.',
20
20
  },
21
- _a[APIValidationErrorCode.NoDefaultAuthMode] = {
22
- message: 'Missing default auth mode',
21
+ _a[APIValidationErrorCode.NoCustomEndpoint] = {
22
+ message: 'Custom endpoint region is present without custom endpoint.',
23
23
  },
24
24
  _a);
@@ -1,2 +1,2 @@
1
1
  export { resolveConfig } from './resolveConfig';
2
- export { resolveCredentials } from './resolveCredentials';
2
+ export { resolveLibraryOptions } from './resolveLibraryOptions';
@@ -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 { resolveConfig } from './resolveConfig';
4
- export { resolveCredentials } from './resolveCredentials';
4
+ export { resolveLibraryOptions } from './resolveLibraryOptions';
@@ -1,8 +1,12 @@
1
+ import { AmplifyClassV6 } from '@aws-amplify/core';
1
2
  /**
2
3
  * @internal
3
4
  */
4
- export declare const resolveConfig: () => {
5
- endpoint: string;
6
- region: string;
7
- defaultAuthMode: import("@aws-amplify/core/lib-esm/libraryUtils").APIAuthMode;
5
+ export declare const resolveConfig: (amplify: AmplifyClassV6) => {
6
+ apiKey: string | undefined;
7
+ customEndpoint: string | undefined;
8
+ customEndpointRegion: string | undefined;
9
+ defaultAuthMode: "apiKey" | "oidc" | "userPool" | "iam" | "lambda" | "none" | undefined;
10
+ endpoint: string | undefined;
11
+ region: string | undefined;
8
12
  };
@@ -1,15 +1,21 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { Amplify } from '@aws-amplify/core';
4
3
  import { APIValidationErrorCode, assertValidationError } from './errors';
5
4
  /**
6
5
  * @internal
7
6
  */
8
- export var resolveConfig = function () {
7
+ export var resolveConfig = function (amplify) {
9
8
  var _a, _b;
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
- assertValidationError(!!endpoint, APIValidationErrorCode.NoAppId);
12
- assertValidationError(!!region, APIValidationErrorCode.NoRegion);
13
- assertValidationError(!!defaultAuthMode, APIValidationErrorCode.NoDefaultAuthMode);
14
- return { endpoint: endpoint, region: region, defaultAuthMode: defaultAuthMode };
9
+ var _c = (_b = (_a = amplify.getConfig().API) === null || _a === void 0 ? void 0 : _a.GraphQL) !== null && _b !== void 0 ? _b : {}, apiKey = _c.apiKey, customEndpoint = _c.customEndpoint, customEndpointRegion = _c.customEndpointRegion, defaultAuthMode = _c.defaultAuthMode, endpoint = _c.endpoint, region = _c.region;
10
+ // TODO: re-enable when working in all test environments:
11
+ // assertValidationError(!!endpoint, APIValidationErrorCode.NoEndpoint);
12
+ assertValidationError(!(!customEndpoint && customEndpointRegion), APIValidationErrorCode.NoCustomEndpoint);
13
+ return {
14
+ apiKey: apiKey,
15
+ customEndpoint: customEndpoint,
16
+ customEndpointRegion: customEndpointRegion,
17
+ defaultAuthMode: defaultAuthMode,
18
+ endpoint: endpoint,
19
+ region: region,
20
+ };
15
21
  };
@@ -0,0 +1,11 @@
1
+ import { AmplifyClassV6 } from '@aws-amplify/core';
2
+ /**
3
+ * @internal
4
+ */
5
+ export declare const resolveLibraryOptions: (amplify: AmplifyClassV6) => {
6
+ headers: ((options: {
7
+ query: string;
8
+ variables?: Record<string, import("@aws-amplify/core/lib-esm/libraryUtils").DocumentType> | undefined;
9
+ }) => Promise<Record<string, string>>) | undefined;
10
+ withCredentials: boolean | undefined;
11
+ };
@@ -0,0 +1,11 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ /**
4
+ * @internal
5
+ */
6
+ export var resolveLibraryOptions = function (amplify) {
7
+ var _a, _b, _c, _d, _e, _f;
8
+ var headers = (_c = (_b = (_a = amplify.libraryOptions) === null || _a === void 0 ? void 0 : _a.API) === null || _b === void 0 ? void 0 : _b.GraphQL) === null || _c === void 0 ? void 0 : _c.headers;
9
+ var withCredentials = (_f = (_e = (_d = amplify.libraryOptions) === null || _d === void 0 ? void 0 : _d.API) === null || _e === void 0 ? void 0 : _e.GraphQL) === null || _f === void 0 ? void 0 : _f.withCredentials;
10
+ return { headers: headers, withCredentials: withCredentials };
11
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aws-amplify/api-graphql",
3
- "version": "4.0.1-console-preview.a1c533e.0+a1c533e",
3
+ "version": "4.0.1-console-preview.23dc225.0+23dc225",
4
4
  "description": "Api-graphql category of aws-amplify",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib-esm/index.js",
@@ -47,15 +47,14 @@
47
47
  "internals"
48
48
  ],
49
49
  "dependencies": {
50
- "@aws-amplify/api-rest": "4.0.1-console-preview.a1c533e.0+a1c533e",
51
- "@aws-amplify/auth": "6.0.1-console-preview.a1c533e.0+a1c533e",
52
- "@aws-amplify/core": "6.0.1-console-preview.a1c533e.0+a1c533e",
50
+ "@aws-amplify/api-rest": "4.0.1-console-preview.23dc225.0+23dc225",
51
+ "@aws-amplify/auth": "6.0.1-console-preview.23dc225.0+23dc225",
52
+ "@aws-amplify/core": "6.0.1-console-preview.23dc225.0+23dc225",
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",
58
- "uuid": "^3.2.1"
57
+ "url": "0.11.0"
59
58
  },
60
59
  "size-limit": [
61
60
  {
@@ -122,5 +121,5 @@
122
121
  "<rootDir>/__tests__"
123
122
  ]
124
123
  },
125
- "gitHead": "a1c533eae82c5386864fb15fc101bb3cb9bd93ae"
124
+ "gitHead": "23dc22531b963319f2b421f6f7c6cf867635b20e"
126
125
  }
@@ -3,12 +3,11 @@
3
3
  import { Observable, SubscriptionLike } from 'rxjs';
4
4
  import { GraphQLError } from 'graphql';
5
5
  import * as url from 'url';
6
- import { v4 as uuid } from 'uuid';
7
6
  import { Buffer } from 'buffer';
8
7
  import { Hub, fetchAuthSession } from '@aws-amplify/core';
9
8
  import { signRequest } from '@aws-amplify/core/internals/aws-client-utils';
10
9
  import {
11
- APIAuthMode,
10
+ GraphQLAuthMode,
12
11
  CustomUserAgentDetails,
13
12
  Logger,
14
13
  NonRetryableError,
@@ -17,6 +16,8 @@ import {
17
16
  isNonRetryableError,
18
17
  jitteredExponentialRetry,
19
18
  DocumentType,
19
+ amplifyUuid,
20
+ AmplifyUrl,
20
21
  } from '@aws-amplify/core/internals/utils';
21
22
 
22
23
  import {
@@ -88,7 +89,7 @@ type ParsedMessagePayload = {
88
89
 
89
90
  export interface AWSAppSyncRealTimeProviderOptions {
90
91
  appSyncGraphqlEndpoint?: string;
91
- authenticationType?: APIAuthMode;
92
+ authenticationType?: GraphQLAuthMode;
92
93
  query?: string;
93
94
  variables?: Record<string, DocumentType>;
94
95
  apiKey?: string;
@@ -210,7 +211,7 @@ export class AWSAppSyncRealTimeProvider {
210
211
  observer.complete();
211
212
  } else {
212
213
  let subscriptionStartActive = false;
213
- const subscriptionId = uuid();
214
+ const subscriptionId = amplifyUuid();
214
215
  const startSubscription = () => {
215
216
  if (!subscriptionStartActive) {
216
217
  subscriptionStartActive = true;
@@ -884,7 +885,7 @@ export class AWSAppSyncRealTimeProvider {
884
885
  Record<string, unknown> | undefined
885
886
  > {
886
887
  const headerHandler: {
887
- [key in APIAuthMode]: (arg0: AWSAppSyncRealTimeAuthInput) => {};
888
+ [key in GraphQLAuthMode]: (arg0: AWSAppSyncRealTimeAuthInput) => {};
888
889
  } = {
889
890
  apiKey: this._awsRealTimeApiKeyHeader.bind(this),
890
891
  iam: this._awsRealTimeIAMHeader.bind(this),
@@ -968,7 +969,7 @@ export class AWSAppSyncRealTimeProvider {
968
969
  {
969
970
  headers: request.headers,
970
971
  method: request.method,
971
- url: new URL(request.url),
972
+ url: new AmplifyUrl(request.url),
972
973
  body: request.data,
973
974
  },
974
975
  {
@@ -11,10 +11,11 @@ import {
11
11
  import { Observable } from 'rxjs';
12
12
  import { AmplifyClassV6 } from '@aws-amplify/core';
13
13
  import {
14
- APIAuthMode,
14
+ GraphQLAuthMode,
15
15
  CustomUserAgentDetails,
16
16
  ConsoleLogger as Logger,
17
17
  getAmplifyUserAgent,
18
+ AmplifyUrl,
18
19
  } from '@aws-amplify/core/internals/utils';
19
20
  import {
20
21
  GraphQLAuthError,
@@ -29,6 +30,7 @@ import {
29
30
  updateRequestToBeCancellable,
30
31
  } from '@aws-amplify/api-rest/internals';
31
32
  import { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvider';
33
+ import { resolveConfig, resolveLibraryOptions } from '../utils';
32
34
 
33
35
  const USER_AGENT_HEADER = 'x-amz-user-agent';
34
36
 
@@ -54,7 +56,12 @@ export class InternalGraphQLAPIClass {
54
56
  private _options;
55
57
  private appSyncRealTime: AWSAppSyncRealTimeProvider | null;
56
58
 
57
- private _api = { post, updateRequestToBeCancellable };
59
+ private _api = {
60
+ post,
61
+ cancelREST,
62
+ isCancelErrorREST,
63
+ updateRequestToBeCancellable,
64
+ };
58
65
 
59
66
  /**
60
67
  * Initialize GraphQL API with AWS configuration
@@ -71,7 +78,7 @@ export class InternalGraphQLAPIClass {
71
78
 
72
79
  private async _headerBasedAuth(
73
80
  amplify: AmplifyClassV6,
74
- authMode: APIAuthMode,
81
+ authMode: GraphQLAuthMode,
75
82
  additionalHeaders: { [key: string]: string } = {}
76
83
  ) {
77
84
  const config = amplify.getConfig();
@@ -80,7 +87,7 @@ export class InternalGraphQLAPIClass {
80
87
  endpoint: appSyncGraphqlEndpoint,
81
88
  apiKey,
82
89
  defaultAuthMode,
83
- } = config.API?.GraphQL || {};
90
+ } = resolveConfig(amplify);
84
91
 
85
92
  const authenticationType = authMode || defaultAuthMode || 'iam';
86
93
  let headers = {};
@@ -130,9 +137,6 @@ export class InternalGraphQLAPIClass {
130
137
  case 'none':
131
138
  break;
132
139
  default:
133
- headers = {
134
- Authorization: null,
135
- };
136
140
  break;
137
141
  }
138
142
 
@@ -218,25 +222,42 @@ export class InternalGraphQLAPIClass {
218
222
  abortController: AbortController,
219
223
  customUserAgentDetails?: CustomUserAgentDetails
220
224
  ): Promise<GraphQLResult<T>> {
221
- const config = amplify.getConfig();
222
-
223
- const { region: region, endpoint: appSyncGraphqlEndpoint } =
224
- config.API?.GraphQL || {};
225
+ const {
226
+ region: region,
227
+ endpoint: appSyncGraphqlEndpoint,
228
+ customEndpoint,
229
+ customEndpointRegion,
230
+ } = resolveConfig(amplify);
225
231
 
226
- const customGraphqlEndpoint = null;
227
- const customEndpointRegion = null;
232
+ // Retrieve library options from Amplify configuration
233
+ const { headers: customHeaders, withCredentials } =
234
+ resolveLibraryOptions(amplify);
228
235
 
229
236
  // TODO: Figure what we need to do to remove `!`'s.
230
237
  const headers = {
231
- ...(!customGraphqlEndpoint &&
238
+ ...(!customEndpoint &&
232
239
  (await this._headerBasedAuth(amplify, authMode!, additionalHeaders))),
233
- ...((customGraphqlEndpoint &&
240
+ /**
241
+ * Custom endpoint headers.
242
+ * If there is both a custom endpoint and custom region present, we get the headers.
243
+ * If there is a custom endpoint but no region, we return an empty object.
244
+ * If neither are present, we return an empty object.
245
+ */
246
+ ...((customEndpoint &&
234
247
  (customEndpointRegion
235
248
  ? await this._headerBasedAuth(amplify, authMode!, additionalHeaders)
236
- : { Authorization: null })) ||
249
+ : {})) ||
237
250
  {}),
251
+ // Custom headers included in Amplify configuration options:
252
+ ...(customHeaders &&
253
+ (await customHeaders({
254
+ query: print(query as DocumentNode),
255
+ variables,
256
+ }))),
257
+ // Headers from individual calls to `graphql`:
238
258
  ...additionalHeaders,
239
- ...(!customGraphqlEndpoint && {
259
+ // User agent headers:
260
+ ...(!customEndpoint && {
240
261
  [USER_AGENT_HEADER]: getAmplifyUserAgent(customUserAgentDetails),
241
262
  }),
242
263
  };
@@ -246,7 +267,31 @@ export class InternalGraphQLAPIClass {
246
267
  variables: variables || null,
247
268
  };
248
269
 
249
- const endpoint = customGraphqlEndpoint || appSyncGraphqlEndpoint;
270
+ let signingServiceInfo;
271
+
272
+ /**
273
+ * We do not send the signing service info to the REST API under the
274
+ * following conditions (i.e. it will not sign the request):
275
+ * - there is a custom endpoint but no region
276
+ * - the auth mode is `none`, or `apiKey`
277
+ * - the auth mode is a type other than the types listed below
278
+ */
279
+ if (
280
+ (customEndpoint && !customEndpointRegion) ||
281
+ (authMode !== 'oidc' &&
282
+ authMode !== 'userPool' &&
283
+ authMode !== 'iam' &&
284
+ authMode !== 'lambda')
285
+ ) {
286
+ signingServiceInfo = null;
287
+ } else {
288
+ signingServiceInfo = {
289
+ service: !customEndpointRegion ? 'appsync' : 'execute-api',
290
+ region: !customEndpointRegion ? region : customEndpointRegion,
291
+ };
292
+ }
293
+
294
+ const endpoint = customEndpoint || appSyncGraphqlEndpoint;
250
295
 
251
296
  if (!endpoint) {
252
297
  const error = new GraphQLError('No graphql endpoint provided.');
@@ -260,14 +305,12 @@ export class InternalGraphQLAPIClass {
260
305
  let response;
261
306
  try {
262
307
  const { body: responseBody } = await this._api.post({
263
- url: new URL(endpoint),
308
+ url: new AmplifyUrl(endpoint),
264
309
  options: {
265
310
  headers,
266
311
  body,
267
- signingServiceInfo: {
268
- service: 'appsync',
269
- region,
270
- },
312
+ signingServiceInfo,
313
+ withCredentials,
271
314
  },
272
315
  abortController,
273
316
  });
@@ -279,7 +322,7 @@ export class InternalGraphQLAPIClass {
279
322
  // If the exception is because user intentionally
280
323
  // cancelled the request, do not modify the exception
281
324
  // so that clients can identify the exception correctly.
282
- if (isCancelErrorREST(err)) {
325
+ if (this._api.isCancelErrorREST(err)) {
283
326
  throw err;
284
327
  }
285
328
 
@@ -304,7 +347,7 @@ export class InternalGraphQLAPIClass {
304
347
  * @return {boolean} - A boolean indicating if the error was from an api request cancellation
305
348
  */
306
349
  isCancelError(error: any): boolean {
307
- return isCancelErrorREST(error);
350
+ return this._api.isCancelErrorREST(error);
308
351
  }
309
352
 
310
353
  /**
@@ -313,7 +356,7 @@ export class InternalGraphQLAPIClass {
313
356
  * @returns - A boolean indicating if the request was cancelled
314
357
  */
315
358
  cancel(request: Promise<any>, message?: string): boolean {
316
- return cancelREST(request, message);
359
+ return this._api.cancelREST(request, message);
317
360
  }
318
361
 
319
362
  private _graphqlSubscribe(
@@ -322,7 +365,8 @@ export class InternalGraphQLAPIClass {
322
365
  additionalHeaders = {},
323
366
  customUserAgentDetails?: CustomUserAgentDetails
324
367
  ): Observable<any> {
325
- const { GraphQL } = amplify.getConfig().API ?? {};
368
+ const config = resolveConfig(amplify);
369
+
326
370
  if (!this.appSyncRealTime) {
327
371
  this.appSyncRealTime = new AWSAppSyncRealTimeProvider();
328
372
  }
@@ -330,10 +374,10 @@ export class InternalGraphQLAPIClass {
330
374
  {
331
375
  query: print(query as DocumentNode),
332
376
  variables,
333
- appSyncGraphqlEndpoint: GraphQL?.endpoint,
334
- region: GraphQL?.region,
335
- authenticationType: authMode ?? GraphQL?.defaultAuthMode,
336
- apiKey: GraphQL?.apiKey,
377
+ appSyncGraphqlEndpoint: config?.endpoint,
378
+ region: config?.region,
379
+ authenticationType: config?.defaultAuthMode,
380
+ apiKey: config?.apiKey,
337
381
  additionalHeaders,
338
382
  },
339
383
  customUserAgentDetails
@@ -5,7 +5,10 @@ import { Source, DocumentNode, GraphQLError } from 'graphql';
5
5
  export { OperationTypeNode } from 'graphql';
6
6
  import { Observable } from 'rxjs';
7
7
 
8
- import { APIAuthMode, DocumentType } from '@aws-amplify/core/internals/utils';
8
+ import {
9
+ GraphQLAuthMode,
10
+ DocumentType,
11
+ } from '@aws-amplify/core/internals/utils';
9
12
  export { CONTROL_MSG, ConnectionState } from './PubSub';
10
13
  /**
11
14
  * Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
@@ -13,7 +16,7 @@ export { CONTROL_MSG, ConnectionState } from './PubSub';
13
16
  export interface GraphQLOptions {
14
17
  query: string | DocumentNode;
15
18
  variables?: Record<string, DocumentType>;
16
- authMode?: APIAuthMode;
19
+ authMode?: GraphQLAuthMode;
17
20
  authToken?: string;
18
21
  /**
19
22
  * @deprecated This property should not be used
@@ -159,7 +162,7 @@ export type GraphqlSubscriptionMessage<T> = {
159
162
 
160
163
  export interface AWSAppSyncRealTimeProviderOptions {
161
164
  appSyncGraphqlEndpoint?: string;
162
- authenticationType?: APIAuthMode;
165
+ authenticationType?: GraphQLAuthMode;
163
166
  query?: string;
164
167
  variables?: Record<string, unknown>;
165
168
  apiKey?: string;
@@ -198,7 +201,7 @@ export interface GraphQLOptionsV6<
198
201
  > {
199
202
  query: TYPED_GQL_STRING | DocumentNode;
200
203
  variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
201
- authMode?: APIAuthMode;
204
+ authMode?: GraphQLAuthMode;
202
205
  authToken?: string;
203
206
  /**
204
207
  * @deprecated This property should not be used
@@ -4,23 +4,23 @@
4
4
  import { AmplifyErrorMap } from '@aws-amplify/core/internals/utils';
5
5
 
6
6
  export enum APIValidationErrorCode {
7
- NoAppId = 'NoAppId',
8
- NoCredentials = 'NoCredentials',
7
+ NoAuthSession = 'NoAuthSession',
9
8
  NoRegion = 'NoRegion',
10
- NoDefaultAuthMode = 'NoDefaultAuthMode',
9
+ NoCustomEndpoint = 'NoCustomEndpoint',
11
10
  }
12
11
 
13
12
  export const validationErrorMap: AmplifyErrorMap<APIValidationErrorCode> = {
14
- [APIValidationErrorCode.NoAppId]: {
15
- message: 'Missing application id.',
16
- },
17
- [APIValidationErrorCode.NoCredentials]: {
18
- message: 'Credentials should not be empty.',
13
+ [APIValidationErrorCode.NoAuthSession]: {
14
+ message: 'Auth session should not be empty.',
19
15
  },
16
+ // TODO: re-enable when working in all test environments:
17
+ // [APIValidationErrorCode.NoEndpoint]: {
18
+ // message: 'Missing endpoint',
19
+ // },
20
20
  [APIValidationErrorCode.NoRegion]: {
21
21
  message: 'Missing region.',
22
22
  },
23
- [APIValidationErrorCode.NoDefaultAuthMode]: {
24
- message: 'Missing default auth mode',
23
+ [APIValidationErrorCode.NoCustomEndpoint]: {
24
+ message: 'Custom endpoint region is present without custom endpoint.',
25
25
  },
26
26
  };
@@ -2,4 +2,4 @@
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
4
  export { resolveConfig } from './resolveConfig';
5
- export { resolveCredentials } from './resolveCredentials';
5
+ export { resolveLibraryOptions } from './resolveLibraryOptions';
@@ -1,20 +1,35 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
 
4
- import { Amplify } from '@aws-amplify/core';
4
+ import { AmplifyClassV6 } from '@aws-amplify/core';
5
5
  import { APIValidationErrorCode, assertValidationError } from './errors';
6
6
 
7
7
  /**
8
8
  * @internal
9
9
  */
10
- export const resolveConfig = () => {
11
- const { region, defaultAuthMode, endpoint } =
12
- Amplify.getConfig().API?.GraphQL ?? {};
13
- assertValidationError(!!endpoint, APIValidationErrorCode.NoAppId);
14
- assertValidationError(!!region, APIValidationErrorCode.NoRegion);
10
+ export const resolveConfig = (amplify: AmplifyClassV6) => {
11
+ const {
12
+ apiKey,
13
+ customEndpoint,
14
+ customEndpointRegion,
15
+ defaultAuthMode,
16
+ endpoint,
17
+ region,
18
+ } = amplify.getConfig().API?.GraphQL ?? {};
19
+
20
+ // TODO: re-enable when working in all test environments:
21
+ // assertValidationError(!!endpoint, APIValidationErrorCode.NoEndpoint);
15
22
  assertValidationError(
16
- !!defaultAuthMode,
17
- APIValidationErrorCode.NoDefaultAuthMode
23
+ !(!customEndpoint && customEndpointRegion),
24
+ APIValidationErrorCode.NoCustomEndpoint
18
25
  );
19
- return { endpoint, region, defaultAuthMode };
26
+
27
+ return {
28
+ apiKey,
29
+ customEndpoint,
30
+ customEndpointRegion,
31
+ defaultAuthMode,
32
+ endpoint,
33
+ region,
34
+ };
20
35
  };
@@ -0,0 +1,13 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+
4
+ import { AmplifyClassV6 } from '@aws-amplify/core';
5
+
6
+ /**
7
+ * @internal
8
+ */
9
+ export const resolveLibraryOptions = (amplify: AmplifyClassV6) => {
10
+ const headers = amplify.libraryOptions?.API?.GraphQL?.headers;
11
+ const withCredentials = amplify.libraryOptions?.API?.GraphQL?.withCredentials;
12
+ return { headers, withCredentials };
13
+ };
@@ -1,12 +0,0 @@
1
- /**
2
- * @internal
3
- */
4
- export declare const resolveCredentials: () => Promise<{
5
- credentials: {
6
- accessKeyId: string;
7
- secretAccessKey: string;
8
- sessionToken?: string | undefined;
9
- expiration?: Date | undefined;
10
- };
11
- identityId: string | undefined;
12
- }>;
@@ -1,22 +0,0 @@
1
- "use strict";
2
- // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
- // SPDX-License-Identifier: Apache-2.0
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- var tslib_1 = require("tslib");
6
- var core_1 = require("@aws-amplify/core");
7
- var errors_1 = require("./errors");
8
- /**
9
- * @internal
10
- */
11
- exports.resolveCredentials = function () { return tslib_1.__awaiter(void 0, void 0, void 0, function () {
12
- var _a, credentials, identityId;
13
- return tslib_1.__generator(this, function (_b) {
14
- switch (_b.label) {
15
- case 0: return [4 /*yield*/, core_1.fetchAuthSession()];
16
- case 1:
17
- _a = _b.sent(), credentials = _a.credentials, identityId = _a.identityId;
18
- errors_1.assertValidationError(!!credentials, errors_1.APIValidationErrorCode.NoCredentials);
19
- return [2 /*return*/, { credentials: credentials, identityId: identityId }];
20
- }
21
- });
22
- }); };
@@ -1,12 +0,0 @@
1
- /**
2
- * @internal
3
- */
4
- export declare const resolveCredentials: () => Promise<{
5
- credentials: {
6
- accessKeyId: string;
7
- secretAccessKey: string;
8
- sessionToken?: string | undefined;
9
- expiration?: Date | undefined;
10
- };
11
- identityId: string | undefined;
12
- }>;