@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 { Source, DocumentNode, GraphQLError } from 'graphql';
2
3
  export { OperationTypeNode } from 'graphql';
3
4
  import { Observable } from 'rxjs';
@@ -271,3 +272,18 @@ export declare type GeneratedSubscription<InputType, OutputType> = string & {
271
272
  __generatedSubscriptionInput: InputType;
272
273
  __generatedSubscriptionOutput: OutputType;
273
274
  };
275
+ declare type FilteredKeys<T> = {
276
+ [P in keyof T]: T[P] extends never ? never : P;
277
+ }[keyof T];
278
+ declare type ExcludeNeverFields<O> = {
279
+ [K in FilteredKeys<O>]: O[K];
280
+ };
281
+ export declare const __amplify: unique symbol;
282
+ export declare type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
283
+ [__amplify]: AmplifyClassV6;
284
+ graphql: <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
285
+ [key: string]: string;
286
+ } | undefined) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
287
+ cancel: (promise: Promise<any>, message?: string) => boolean;
288
+ isCancelError: (error: any) => boolean;
289
+ }>;
@@ -11,3 +11,4 @@ var GraphQLAuthError;
11
11
  GraphQLAuthError["NO_FEDERATED_JWT"] = "No federated jwt";
12
12
  GraphQLAuthError["NO_AUTH_TOKEN"] = "No auth token specified";
13
13
  })(GraphQLAuthError = exports.GraphQLAuthError || (exports.GraphQLAuthError = {}));
14
+ exports.__amplify = Symbol('amplify');
@@ -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
  /**
@@ -26,8 +26,8 @@ var GraphQLAPIClass = /** @class */ (function (_super) {
26
26
  * @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config
27
27
  * @returns An Observable if the query is a subscription query, else a promise of the graphql result.
28
28
  */
29
- GraphQLAPIClass.prototype.graphql = function (options, additionalHeaders) {
30
- return _super.prototype.graphql.call(this, options, additionalHeaders);
29
+ GraphQLAPIClass.prototype.graphql = function (amplify, options, additionalHeaders) {
30
+ return _super.prototype.graphql.call(this, amplify, options, additionalHeaders);
31
31
  };
32
32
  /**
33
33
  * 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;
@@ -2,7 +2,6 @@ import { __assign, __awaiter, __generator, __read } from "tslib";
2
2
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
3
  // SPDX-License-Identifier: Apache-2.0
4
4
  import { print, parse, GraphQLError, } from 'graphql';
5
- import { Amplify, Cache, fetchAuthSession } from '@aws-amplify/core';
6
5
  import { ConsoleLogger as Logger, getAmplifyUserAgent, } from '@aws-amplify/core/internals/utils';
7
6
  import { GraphQLAuthError, } from '../types';
8
7
  import { isCancelError as isCancelErrorREST } from '@aws-amplify/api-rest';
@@ -27,7 +26,6 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
27
26
  * @param {Object} options - Configuration object for API
28
27
  */
29
28
  function InternalGraphQLAPIClass(options) {
30
- this.Cache = Cache;
31
29
  this._api = { post: post, updateRequestToBeCancellable: updateRequestToBeCancellable };
32
30
  this._options = options;
33
31
  logger.debug('API Options', this._options);
@@ -35,7 +33,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
35
33
  InternalGraphQLAPIClass.prototype.getModuleName = function () {
36
34
  return 'InternalGraphQLAPI';
37
35
  };
38
- InternalGraphQLAPIClass.prototype._headerBasedAuth = function (authMode, additionalHeaders) {
36
+ InternalGraphQLAPIClass.prototype._headerBasedAuth = function (amplify, authMode, additionalHeaders) {
39
37
  if (additionalHeaders === void 0) { additionalHeaders = {}; }
40
38
  var _a, _b;
41
39
  return __awaiter(this, void 0, void 0, function () {
@@ -43,7 +41,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
43
41
  return __generator(this, function (_e) {
44
42
  switch (_e.label) {
45
43
  case 0:
46
- config = Amplify.getConfig();
44
+ config = amplify.getConfig();
47
45
  _c = ((_a = config.API) === null || _a === void 0 ? void 0 : _a.GraphQL) || {}, region = _c.region, appSyncGraphqlEndpoint = _c.endpoint, apiKey = _c.apiKey, defaultAuthMode = _c.defaultAuthMode;
48
46
  authenticationType = authMode || defaultAuthMode || 'iam';
49
47
  headers = {};
@@ -65,7 +63,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
65
63
  'X-Api-Key': apiKey,
66
64
  };
67
65
  return [3 /*break*/, 11];
68
- case 2: return [4 /*yield*/, fetchAuthSession()];
66
+ case 2: return [4 /*yield*/, amplify.Auth.fetchAuthSession()];
69
67
  case 3:
70
68
  session = _e.sent();
71
69
  if (session.credentials === undefined) {
@@ -75,7 +73,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
75
73
  case 4:
76
74
  _e.trys.push([4, 6, , 7]);
77
75
  token = void 0;
78
- return [4 /*yield*/, fetchAuthSession()];
76
+ return [4 /*yield*/, amplify.Auth.fetchAuthSession()];
79
77
  case 5:
80
78
  token = (_b = (_e.sent()).tokens) === null || _b === void 0 ? void 0 : _b.accessToken.toString();
81
79
  if (!token) {
@@ -125,7 +123,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
125
123
  * @param [additionalHeaders] - headers to merge in after any `graphql_headers` set in the config
126
124
  * @returns An Observable if the query is a subscription query, else a promise of the graphql result.
127
125
  */
128
- InternalGraphQLAPIClass.prototype.graphql = function (_a, additionalHeaders, customUserAgentDetails) {
126
+ InternalGraphQLAPIClass.prototype.graphql = function (amplify, _a, additionalHeaders, customUserAgentDetails) {
129
127
  var paramQuery = _a.query, _b = _a.variables, variables = _b === void 0 ? {} : _b, authMode = _a.authMode, authToken = _a.authToken;
130
128
  var query = typeof paramQuery === 'string'
131
129
  ? parse(paramQuery)
@@ -141,16 +139,16 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
141
139
  case 'query':
142
140
  case 'mutation':
143
141
  var abortController = new AbortController();
144
- var responsePromise = this._graphql({ query: query, variables: variables, authMode: authMode }, headers, abortController, customUserAgentDetails);
142
+ var responsePromise = this._graphql(amplify, { query: query, variables: variables, authMode: authMode }, headers, abortController, customUserAgentDetails);
145
143
  this._api.updateRequestToBeCancellable(responsePromise, abortController);
146
144
  return responsePromise;
147
145
  case 'subscription':
148
- return this._graphqlSubscribe({ query: query, variables: variables, authMode: authMode }, headers, customUserAgentDetails);
146
+ return this._graphqlSubscribe(amplify, { query: query, variables: variables, authMode: authMode }, headers, customUserAgentDetails);
149
147
  default:
150
148
  throw new Error("invalid operation type: " + operationType);
151
149
  }
152
150
  };
153
- InternalGraphQLAPIClass.prototype._graphql = function (_a, additionalHeaders, abortController, customUserAgentDetails) {
151
+ InternalGraphQLAPIClass.prototype._graphql = function (amplify, _a, additionalHeaders, abortController, customUserAgentDetails) {
154
152
  var query = _a.query, variables = _a.variables, authMode = _a.authMode;
155
153
  if (additionalHeaders === void 0) { additionalHeaders = {}; }
156
154
  var _b;
@@ -160,14 +158,14 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
160
158
  return __generator(this, function (_k) {
161
159
  switch (_k.label) {
162
160
  case 0:
163
- config = Amplify.getConfig();
161
+ config = amplify.getConfig();
164
162
  _c = ((_b = config.API) === null || _b === void 0 ? void 0 : _b.GraphQL) || {}, region = _c.region, appSyncGraphqlEndpoint = _c.endpoint;
165
163
  customGraphqlEndpoint = null;
166
164
  customEndpointRegion = null;
167
165
  _d = [{}];
168
166
  _e = !customGraphqlEndpoint;
169
167
  if (!_e) return [3 /*break*/, 2];
170
- return [4 /*yield*/, this._headerBasedAuth(authMode, additionalHeaders)];
168
+ return [4 /*yield*/, this._headerBasedAuth(amplify, authMode, additionalHeaders)];
171
169
  case 1:
172
170
  _e = (_k.sent());
173
171
  _k.label = 2;
@@ -176,7 +174,7 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
176
174
  _g = customGraphqlEndpoint;
177
175
  if (!_g) return [3 /*break*/, 6];
178
176
  if (!customEndpointRegion) return [3 /*break*/, 4];
179
- return [4 /*yield*/, this._headerBasedAuth(authMode, additionalHeaders)];
177
+ return [4 /*yield*/, this._headerBasedAuth(amplify, authMode, additionalHeaders)];
180
178
  case 3:
181
179
  _h = _k.sent();
182
180
  return [3 /*break*/, 5];
@@ -264,11 +262,11 @@ var InternalGraphQLAPIClass = /** @class */ (function () {
264
262
  InternalGraphQLAPIClass.prototype.cancel = function (request, message) {
265
263
  return cancelREST(request, message);
266
264
  };
267
- InternalGraphQLAPIClass.prototype._graphqlSubscribe = function (_a, additionalHeaders, customUserAgentDetails) {
265
+ InternalGraphQLAPIClass.prototype._graphqlSubscribe = function (amplify, _a, additionalHeaders, customUserAgentDetails) {
268
266
  var query = _a.query, variables = _a.variables, authMode = _a.authMode;
269
267
  if (additionalHeaders === void 0) { additionalHeaders = {}; }
270
268
  var _b;
271
- var GraphQL = ((_b = Amplify.getConfig().API) !== null && _b !== void 0 ? _b : {}).GraphQL;
269
+ var GraphQL = ((_b = amplify.getConfig().API) !== null && _b !== void 0 ? _b : {}).GraphQL;
272
270
  if (!this.appSyncRealTime) {
273
271
  this.appSyncRealTime = new AWSAppSyncRealTimeProvider();
274
272
  }
@@ -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 };
@@ -1,6 +1,7 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
3
  import { GraphQLAPI } from '../GraphQLAPI';
4
+ import { __amplify, } from '../types';
4
5
  /**
5
6
  * Invokes graphql operations against a graphql service, providing correct input and
6
7
  * output types if Amplify-generated graphql from a recent version of the CLI/codegen
@@ -91,7 +92,7 @@ export function graphql(options, additionalHeaders) {
91
92
  * Neither of these can actually be validated at runtime. Hence, we don't perform
92
93
  * any validation or type-guarding here.
93
94
  */
94
- var result = GraphQLAPI.graphql(options, additionalHeaders);
95
+ var result = GraphQLAPI.graphql(this[__amplify], options, additionalHeaders);
95
96
  return result;
96
97
  }
97
98
  /**