@aws-amplify/api-graphql 4.0.1-console-preview.d807e55.0 → 4.0.1-console-preview.5f040a2.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,3 +1,4 @@
1
+ import { AmplifyClassV6 } from '@aws-amplify/core';
1
2
  import { GraphQLOptions, GraphQLResult } from './types';
2
3
  import { InternalGraphQLAPIClass } from './internals';
3
4
  import { Observable } from 'rxjs';
@@ -18,7 +19,7 @@ export declare class GraphQLAPIClass extends InternalGraphQLAPIClass {
18
19
  * @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config
19
20
  * @returns An Observable if the query is a subscription query, else a promise of the graphql result.
20
21
  */
21
- graphql<T = any>(options: GraphQLOptions, additionalHeaders?: {
22
+ graphql<T = any>(amplify: AmplifyClassV6, options: GraphQLOptions, additionalHeaders?: {
22
23
  [key: string]: string;
23
24
  }): Observable<GraphQLResult<T>> | Promise<GraphQLResult<T>>;
24
25
  /**
package/lib/GraphQLAPI.js CHANGED
@@ -28,8 +28,8 @@ var GraphQLAPIClass = /** @class */ (function (_super) {
28
28
  * @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config
29
29
  * @returns An Observable if the query is a subscription query, else a promise of the graphql result.
30
30
  */
31
- GraphQLAPIClass.prototype.graphql = function (options, additionalHeaders) {
32
- return _super.prototype.graphql.call(this, options, additionalHeaders);
31
+ GraphQLAPIClass.prototype.graphql = function (amplify, options, additionalHeaders) {
32
+ return _super.prototype.graphql.call(this, amplify, options, additionalHeaders);
33
33
  };
34
34
  /**
35
35
  * Checks to see if an error thrown is from an api request cancellation
@@ -1,5 +1,6 @@
1
1
  import { OperationTypeNode } from 'graphql';
2
2
  import { Observable } from 'rxjs';
3
+ import { AmplifyClassV6 } from '@aws-amplify/core';
3
4
  import { CustomUserAgentDetails } from '@aws-amplify/core/internals/utils';
4
5
  import { GraphQLResult, GraphQLOperation, GraphQLOptions } from '../types';
5
6
  export declare const graphqlOperation: (query: any, variables?: {}, authToken?: string | undefined) => {
@@ -16,7 +17,6 @@ export declare class InternalGraphQLAPIClass {
16
17
  */
17
18
  private _options;
18
19
  private appSyncRealTime;
19
- Cache: import("@aws-amplify/core/lib-esm/Cache/types").ICache;
20
20
  private _api;
21
21
  /**
22
22
  * Initialize GraphQL API with AWS configuration
@@ -37,7 +37,7 @@ export declare class InternalGraphQLAPIClass {
37
37
  * @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config
38
38
  * @returns An Observable if the query is a subscription query, else a promise of the graphql result.
39
39
  */
40
- graphql<T = any>({ query: paramQuery, variables, authMode, authToken }: GraphQLOptions, additionalHeaders?: {
40
+ graphql<T = any>(amplify: AmplifyClassV6, { query: paramQuery, variables, authMode, authToken }: GraphQLOptions, additionalHeaders?: {
41
41
  [key: string]: string;
42
42
  }, customUserAgentDetails?: CustomUserAgentDetails): Observable<GraphQLResult<T>> | Promise<GraphQLResult<T>>;
43
43
  private _graphql;
@@ -4,7 +4,6 @@ var tslib_1 = require("tslib");
4
4
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5
5
  // SPDX-License-Identifier: Apache-2.0
6
6
  var graphql_1 = require("graphql");
7
- var core_1 = require("@aws-amplify/core");
8
7
  var utils_1 = require("@aws-amplify/core/internals/utils");
9
8
  var types_1 = require("../types");
10
9
  var api_rest_1 = require("@aws-amplify/api-rest");
@@ -29,7 +28,6 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
29
28
  * @param {Object} options - Configuration object for API
30
29
  */
31
30
  function InternalGraphQLAPIClass(options) {
32
- this.Cache = core_1.Cache;
33
31
  this._api = { post: internals_1.post, updateRequestToBeCancellable: internals_1.updateRequestToBeCancellable };
34
32
  this._options = options;
35
33
  logger.debug('API Options', this._options);
@@ -37,7 +35,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
37
35
  InternalGraphQLAPIClass.prototype.getModuleName = function () {
38
36
  return 'InternalGraphQLAPI';
39
37
  };
40
- InternalGraphQLAPIClass.prototype._headerBasedAuth = function (authMode, additionalHeaders) {
38
+ InternalGraphQLAPIClass.prototype._headerBasedAuth = function (amplify, authMode, additionalHeaders) {
41
39
  if (additionalHeaders === void 0) { additionalHeaders = {}; }
42
40
  var _a, _b;
43
41
  return tslib_1.__awaiter(this, void 0, void 0, function () {
@@ -45,7 +43,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
45
43
  return tslib_1.__generator(this, function (_e) {
46
44
  switch (_e.label) {
47
45
  case 0:
48
- config = core_1.Amplify.getConfig();
46
+ config = amplify.getConfig();
49
47
  _c = ((_a = config.API) === null || _a === void 0 ? void 0 : _a.GraphQL) || {}, region = _c.region, appSyncGraphqlEndpoint = _c.endpoint, apiKey = _c.apiKey, defaultAuthMode = _c.defaultAuthMode;
50
48
  authenticationType = authMode || defaultAuthMode || 'iam';
51
49
  headers = {};
@@ -67,7 +65,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
67
65
  'X-Api-Key': apiKey,
68
66
  };
69
67
  return [3 /*break*/, 11];
70
- case 2: return [4 /*yield*/, core_1.fetchAuthSession()];
68
+ case 2: return [4 /*yield*/, amplify.Auth.fetchAuthSession()];
71
69
  case 3:
72
70
  session = _e.sent();
73
71
  if (session.credentials === undefined) {
@@ -77,7 +75,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
77
75
  case 4:
78
76
  _e.trys.push([4, 6, , 7]);
79
77
  token = void 0;
80
- return [4 /*yield*/, core_1.fetchAuthSession()];
78
+ return [4 /*yield*/, amplify.Auth.fetchAuthSession()];
81
79
  case 5:
82
80
  token = (_b = (_e.sent()).tokens) === null || _b === void 0 ? void 0 : _b.accessToken.toString();
83
81
  if (!token) {
@@ -127,7 +125,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
127
125
  * @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config
128
126
  * @returns An Observable if the query is a subscription query, else a promise of the graphql result.
129
127
  */
130
- InternalGraphQLAPIClass.prototype.graphql = function (_a, additionalHeaders, customUserAgentDetails) {
128
+ InternalGraphQLAPIClass.prototype.graphql = function (amplify, _a, additionalHeaders, customUserAgentDetails) {
131
129
  var paramQuery = _a.query, _b = _a.variables, variables = _b === void 0 ? {} : _b, authMode = _a.authMode, authToken = _a.authToken;
132
130
  var query = typeof paramQuery === 'string'
133
131
  ? graphql_1.parse(paramQuery)
@@ -143,16 +141,16 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
143
141
  case 'query':
144
142
  case 'mutation':
145
143
  var abortController = new AbortController();
146
- var responsePromise = this._graphql({ query: query, variables: variables, authMode: authMode }, headers, abortController, customUserAgentDetails);
144
+ var responsePromise = this._graphql(amplify, { query: query, variables: variables, authMode: authMode }, headers, abortController, customUserAgentDetails);
147
145
  this._api.updateRequestToBeCancellable(responsePromise, abortController);
148
146
  return responsePromise;
149
147
  case 'subscription':
150
- return this._graphqlSubscribe({ query: query, variables: variables, authMode: authMode }, headers, customUserAgentDetails);
148
+ return this._graphqlSubscribe(amplify, { query: query, variables: variables, authMode: authMode }, headers, customUserAgentDetails);
151
149
  default:
152
150
  throw new Error("invalid operation type: " + operationType);
153
151
  }
154
152
  };
155
- InternalGraphQLAPIClass.prototype._graphql = function (_a, additionalHeaders, abortController, customUserAgentDetails) {
153
+ InternalGraphQLAPIClass.prototype._graphql = function (amplify, _a, additionalHeaders, abortController, customUserAgentDetails) {
156
154
  var query = _a.query, variables = _a.variables, authMode = _a.authMode;
157
155
  if (additionalHeaders === void 0) { additionalHeaders = {}; }
158
156
  var _b;
@@ -162,14 +160,14 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
162
160
  return tslib_1.__generator(this, function (_k) {
163
161
  switch (_k.label) {
164
162
  case 0:
165
- config = core_1.Amplify.getConfig();
163
+ config = amplify.getConfig();
166
164
  _c = ((_b = config.API) === null || _b === void 0 ? void 0 : _b.GraphQL) || {}, region = _c.region, appSyncGraphqlEndpoint = _c.endpoint;
167
165
  customGraphqlEndpoint = null;
168
166
  customEndpointRegion = null;
169
167
  _d = [{}];
170
168
  _e = !customGraphqlEndpoint;
171
169
  if (!_e) return [3 /*break*/, 2];
172
- return [4 /*yield*/, this._headerBasedAuth(authMode, additionalHeaders)];
170
+ return [4 /*yield*/, this._headerBasedAuth(amplify, authMode, additionalHeaders)];
173
171
  case 1:
174
172
  _e = (_k.sent());
175
173
  _k.label = 2;
@@ -178,7 +176,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
178
176
  _g = customGraphqlEndpoint;
179
177
  if (!_g) return [3 /*break*/, 6];
180
178
  if (!customEndpointRegion) return [3 /*break*/, 4];
181
- return [4 /*yield*/, this._headerBasedAuth(authMode, additionalHeaders)];
179
+ return [4 /*yield*/, this._headerBasedAuth(amplify, authMode, additionalHeaders)];
182
180
  case 3:
183
181
  _h = _k.sent();
184
182
  return [3 /*break*/, 5];
@@ -266,11 +264,11 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
266
264
  InternalGraphQLAPIClass.prototype.cancel = function (request, message) {
267
265
  return internals_1.cancel(request, message);
268
266
  };
269
- InternalGraphQLAPIClass.prototype._graphqlSubscribe = function (_a, additionalHeaders, customUserAgentDetails) {
267
+ InternalGraphQLAPIClass.prototype._graphqlSubscribe = function (amplify, _a, additionalHeaders, customUserAgentDetails) {
270
268
  var query = _a.query, variables = _a.variables, authMode = _a.authMode;
271
269
  if (additionalHeaders === void 0) { additionalHeaders = {}; }
272
270
  var _b;
273
- var GraphQL = ((_b = core_1.Amplify.getConfig().API) !== null && _b !== void 0 ? _b : {}).GraphQL;
271
+ var GraphQL = ((_b = amplify.getConfig().API) !== null && _b !== void 0 ? _b : {}).GraphQL;
274
272
  if (!this.appSyncRealTime) {
275
273
  this.appSyncRealTime = new AWSAppSyncRealTimeProvider_1.AWSAppSyncRealTimeProvider();
276
274
  }
@@ -1,4 +1,4 @@
1
- import { GraphQLOptionsV6, GraphQLResponseV6 } from '../types';
1
+ import { V6Client, GraphQLOptionsV6, GraphQLResponseV6 } from '../types';
2
2
  /**
3
3
  * Invokes graphql operations against a graphql service, providing correct input and
4
4
  * output types if Amplify-generated graphql from a recent version of the CLI/codegen
@@ -83,7 +83,7 @@ import { GraphQLOptionsV6, GraphQLResponseV6 } from '../types';
83
83
  * @param options
84
84
  * @param additionalHeaders
85
85
  */
86
- export declare function graphql<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
86
+ export declare function graphql<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(this: V6Client, options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
87
87
  [key: string]: string;
88
88
  }): GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
89
89
  /**
@@ -91,11 +91,11 @@ export declare function graphql<FALLBACK_TYPES = unknown, TYPED_GQL_STRING exten
91
91
  * @param {any} request - request to cancel
92
92
  * @returns - A boolean indicating if the request was cancelled
93
93
  */
94
- export declare function cancel(promise: Promise<any>, message?: string): boolean;
94
+ export declare function cancel(this: V6Client, promise: Promise<any>, message?: string): boolean;
95
95
  /**
96
96
  * Checks to see if an error thrown is from an api request cancellation
97
97
  * @param {any} error - Any error
98
98
  * @returns - A boolean indicating if the error was from an api request cancellation
99
99
  */
100
- export declare function isCancelError(error: any): boolean;
100
+ export declare function isCancelError(this: V6Client, error: any): boolean;
101
101
  export { GraphQLOptionsV6, GraphQLResponseV6 };
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
4
  // SPDX-License-Identifier: Apache-2.0
5
5
  var GraphQLAPI_1 = require("../GraphQLAPI");
6
+ var types_1 = require("../types");
6
7
  /**
7
8
  * Invokes graphql operations against a graphql service, providing correct input and
8
9
  * output types if Amplify-generated graphql from a recent version of the CLI/codegen
@@ -93,7 +94,7 @@ function graphql(options, additionalHeaders) {
93
94
  * Neither of these can actually be validated at runtime. Hence, we don't perform
94
95
  * any validation or type-guarding here.
95
96
  */
96
- var result = GraphQLAPI_1.GraphQLAPI.graphql(options, additionalHeaders);
97
+ var result = GraphQLAPI_1.GraphQLAPI.graphql(this[types_1.__amplify], options, additionalHeaders);
97
98
  return result;
98
99
  }
99
100
  exports.graphql = graphql;