@aws-amplify/api-graphql 4.0.16 → 4.0.17-unstable.1fdbb12.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/dist/cjs/internals/APIClient.js +0 -1
- package/dist/cjs/internals/APIClient.js.map +1 -1
- package/dist/cjs/internals/InternalGraphQLAPI.js +7 -2
- package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -1
- package/dist/cjs/internals/generateClient.js +20 -18
- package/dist/cjs/internals/generateClient.js.map +1 -1
- package/dist/cjs/internals/utils/generateEnumsProperty.js +21 -0
- package/dist/cjs/internals/utils/generateEnumsProperty.js.map +1 -0
- package/dist/cjs/internals/{generateModelsProperty.js → utils/generateModelsProperty.js} +9 -9
- package/dist/cjs/internals/utils/generateModelsProperty.js.map +1 -0
- package/dist/cjs/internals/utils/isApiGraphQLProviderConfig.js +11 -0
- package/dist/cjs/internals/utils/isApiGraphQLProviderConfig.js.map +1 -0
- package/dist/cjs/internals/utils/isConfigureEventWithResourceConfig.js +11 -0
- package/dist/cjs/internals/utils/isConfigureEventWithResourceConfig.js.map +1 -0
- package/dist/cjs/internals/v6.js +1 -1
- package/dist/cjs/internals/v6.js.map +1 -1
- package/dist/esm/internals/APIClient.mjs +0 -1
- package/dist/esm/internals/APIClient.mjs.map +1 -1
- package/dist/esm/internals/InternalGraphQLAPI.mjs +7 -2
- package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
- package/dist/esm/internals/generateClient.mjs +20 -18
- package/dist/esm/internals/generateClient.mjs.map +1 -1
- package/dist/esm/internals/utils/generateEnumsProperty.d.ts +3 -0
- package/dist/esm/internals/utils/generateEnumsProperty.mjs +18 -0
- package/dist/esm/internals/utils/generateEnumsProperty.mjs.map +1 -0
- package/dist/esm/internals/utils/generateModelsProperty.d.ts +4 -0
- package/dist/esm/internals/{generateModelsProperty.mjs → utils/generateModelsProperty.mjs} +9 -9
- package/dist/esm/internals/utils/generateModelsProperty.mjs.map +1 -0
- package/dist/esm/internals/utils/isApiGraphQLProviderConfig.d.ts +2 -0
- package/dist/esm/internals/utils/isApiGraphQLProviderConfig.mjs +8 -0
- package/dist/esm/internals/utils/isApiGraphQLProviderConfig.mjs.map +1 -0
- package/dist/esm/internals/utils/isConfigureEventWithResourceConfig.d.ts +8 -0
- package/dist/esm/internals/utils/isConfigureEventWithResourceConfig.mjs +8 -0
- package/dist/esm/internals/utils/isConfigureEventWithResourceConfig.mjs.map +1 -0
- package/dist/esm/internals/v6.mjs +1 -1
- package/dist/esm/internals/v6.mjs.map +1 -1
- package/dist/esm/types/index.d.ts +2 -1
- package/dist/esm/utils/resolveLibraryOptions.d.ts +4 -1
- package/package.json +5 -5
- package/src/GraphQLAPI.ts +2 -2
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +20 -20
- package/src/internals/APIClient.ts +6 -8
- package/src/internals/InternalGraphQLAPI.ts +25 -20
- package/src/internals/generateClient.ts +23 -35
- package/src/internals/operations/get.ts +11 -11
- package/src/internals/operations/list.ts +10 -10
- package/src/internals/operations/subscription.ts +6 -6
- package/src/internals/server/generateClientWithAmplifyInstance.ts +1 -1
- package/src/internals/utils/generateEnumsProperty.ts +33 -0
- package/src/internals/{generateModelsProperty.ts → utils/generateModelsProperty.ts} +14 -12
- package/src/internals/utils/isApiGraphQLProviderConfig.ts +10 -0
- package/src/internals/utils/isConfigureEventWithResourceConfig.ts +13 -0
- package/src/internals/v6.ts +5 -5
- package/src/server/generateClient.ts +2 -2
- package/src/types/index.ts +51 -45
- package/src/utils/ConnectionStateMonitor.ts +6 -6
- package/src/utils/errors/assertValidationError.ts +1 -1
- package/src/utils/findIndexByFields.ts +3 -3
- package/src/utils/resolveConfig.ts +2 -2
- package/src/utils/resolveOwnerFields.ts +1 -1
- package/dist/cjs/internals/generateModelsProperty.js.map +0 -1
- package/dist/esm/internals/generateModelsProperty.d.ts +0 -4
- package/dist/esm/internals/generateModelsProperty.mjs.map +0 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
function isConfigureEventWithResourceConfig(payload) {
|
|
4
|
+
return payload.event === 'configure';
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export { isConfigureEventWithResourceConfig };
|
|
8
|
+
//# sourceMappingURL=isConfigureEventWithResourceConfig.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isConfigureEventWithResourceConfig.mjs","sources":["../../../../src/internals/utils/isConfigureEventWithResourceConfig.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport function isConfigureEventWithResourceConfig(payload) {\n return payload.event === 'configure';\n}\n"],"names":[],"mappings":"AAAA;AACA;AACO,SAAS,kCAAkC,CAAC,OAAO,EAAE;AAC5D,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,WAAW,CAAC;AACzC;;;;"}
|
|
@@ -88,7 +88,7 @@ import { __authMode, __authToken, __amplify } from '../types/index.mjs';
|
|
|
88
88
|
* @param additionalHeaders
|
|
89
89
|
*/
|
|
90
90
|
function graphql(options, additionalHeaders) {
|
|
91
|
-
// inject client-level auth
|
|
91
|
+
// inject client-level auth
|
|
92
92
|
options.authMode = options.authMode || this[__authMode];
|
|
93
93
|
options.authToken = options.authToken || this[__authToken];
|
|
94
94
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v6.mjs","sources":["../../../src/internals/v6.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { GraphQLAPI } from '../GraphQLAPI';\nimport { __amplify, __authMode, __authToken, } from '../types';\n/**\n * Invokes graphql operations against a graphql service, providing correct input and\n * output types if Amplify-generated graphql from a recent version of the CLI/codegen\n * are used *or* correct typing is provided via the type argument.\n *\n * Amplify-generated \"branded\" graphql queries will look similar to this:\n *\n * ```ts\n * //\n * // |-- branding\n * // v\n * export const getModel = `...` as GeneratedQuery<\n * \tGetModelQueryVariables,\n * \tGetModelQuery\n * >;\n * ```\n *\n * If this branding is not in your generated graphql, update to a newer version of\n * CLI/codegen and regenerate your graphql using `amplify codegen`.\n *\n * ## Using Amplify-generated graphql\n *\n * ```ts\n * import * as queries from './graphql/queries';\n *\n * //\n * // |-- correctly typed graphql response containing a Widget\n * // v\n * const queryResult = await graphql({\n * \tquery: queries.getWidget,\n * \tvariables: {\n * \t\tid: \"abc\", // <-- type hinted/enforced\n * \t},\n * });\n *\n * //\n * // |-- a correctly typed Widget\n * // v\n * const fetchedWidget = queryResult.data?.getWidget!;\n * ```\n *\n * ## Custom input + result types\n *\n * To provide input types (`variables`) and result types:\n *\n * ```ts\n * type GetById_NameOnly = {\n * \tvariables: {\n * \t\tid: string\n * \t},\n * \tresult: Promise<{\n * \t\tdata: { getWidget: { name: string } }\n * \t}>\n * }\n *\n * //\n * // |-- type is GetById_NameOnly[\"result\"]\n * // v\n * const result = graphql<GetById_NameOnly>({\n * \tquery: \"...\",\n * \tvariables: { id: \"abc\" } // <-- type of GetById_NameOnly[\"variables\"]\n * });\n * ```\n *\n * ## Custom result type only\n *\n * To specify result types only, use a type that is *not* in the `{variables, result}` shape:\n *\n * ```ts\n * type MyResultType = Promise<{\n * \tdata: {\n * \t\tgetWidget: { name: string }\n * \t}\n * }>\n *\n * //\n * // |-- type is MyResultType\n * // v\n * const result = graphql<MyResultType>({query: \"...\"});\n * ```\n *\n * @param options\n * @param additionalHeaders\n */\nexport function graphql(options, additionalHeaders) {\n // inject client-level auth
|
|
1
|
+
{"version":3,"file":"v6.mjs","sources":["../../../src/internals/v6.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { GraphQLAPI } from '../GraphQLAPI';\nimport { __amplify, __authMode, __authToken, } from '../types';\n/**\n * Invokes graphql operations against a graphql service, providing correct input and\n * output types if Amplify-generated graphql from a recent version of the CLI/codegen\n * are used *or* correct typing is provided via the type argument.\n *\n * Amplify-generated \"branded\" graphql queries will look similar to this:\n *\n * ```ts\n * //\n * // |-- branding\n * // v\n * export const getModel = `...` as GeneratedQuery<\n * \tGetModelQueryVariables,\n * \tGetModelQuery\n * >;\n * ```\n *\n * If this branding is not in your generated graphql, update to a newer version of\n * CLI/codegen and regenerate your graphql using `amplify codegen`.\n *\n * ## Using Amplify-generated graphql\n *\n * ```ts\n * import * as queries from './graphql/queries';\n *\n * //\n * // |-- correctly typed graphql response containing a Widget\n * // v\n * const queryResult = await graphql({\n * \tquery: queries.getWidget,\n * \tvariables: {\n * \t\tid: \"abc\", // <-- type hinted/enforced\n * \t},\n * });\n *\n * //\n * // |-- a correctly typed Widget\n * // v\n * const fetchedWidget = queryResult.data?.getWidget!;\n * ```\n *\n * ## Custom input + result types\n *\n * To provide input types (`variables`) and result types:\n *\n * ```ts\n * type GetById_NameOnly = {\n * \tvariables: {\n * \t\tid: string\n * \t},\n * \tresult: Promise<{\n * \t\tdata: { getWidget: { name: string } }\n * \t}>\n * }\n *\n * //\n * // |-- type is GetById_NameOnly[\"result\"]\n * // v\n * const result = graphql<GetById_NameOnly>({\n * \tquery: \"...\",\n * \tvariables: { id: \"abc\" } // <-- type of GetById_NameOnly[\"variables\"]\n * });\n * ```\n *\n * ## Custom result type only\n *\n * To specify result types only, use a type that is *not* in the `{variables, result}` shape:\n *\n * ```ts\n * type MyResultType = Promise<{\n * \tdata: {\n * \t\tgetWidget: { name: string }\n * \t}\n * }>\n *\n * //\n * // |-- type is MyResultType\n * // v\n * const result = graphql<MyResultType>({query: \"...\"});\n * ```\n *\n * @param options\n * @param additionalHeaders\n */\nexport function graphql(options, additionalHeaders) {\n // inject client-level auth\n options.authMode = options.authMode || this[__authMode];\n options.authToken = options.authToken || this[__authToken];\n /**\n * The correctness of these typings depends on correct string branding or overrides.\n * Neither of these can actually be validated at runtime. Hence, we don't perform\n * any validation or type-guarding here.\n */\n const result = GraphQLAPI.graphql(this[__amplify], options, additionalHeaders);\n return result;\n}\n/**\n * Cancels an inflight request. Only applicable for graphql queries and mutations\n * @param {any} request - request to cancel\n * @returns - A boolean indicating if the request was cancelled\n */\nexport function cancel(promise, message) {\n return GraphQLAPI.cancel(promise, message);\n}\n/**\n * Checks to see if an error thrown is from an api request cancellation\n * @param {any} error - Any error\n * @returns - A boolean indicating if the error was from an api request cancellation\n */\nexport function isCancelError(error) {\n return GraphQLAPI.isCancelError(error);\n}\n"],"names":[],"mappings":";;;AAAA;AACA;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,OAAO,CAAC,OAAO,EAAE,iBAAiB,EAAE;AACpD;AACA,IAAI,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC;AAC5D,IAAI,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC;AAC/D;AACA;AACA;AACA;AACA;AACA,IAAI,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC;AACnF,IAAI,OAAO,MAAM,CAAC;AAClB,CAAC;AACD;AACA;AACA;AACA;AACA;AACO,SAAS,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE;AACzC,IAAI,OAAO,UAAU,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC/C,CAAC;AACD;AACA;AACA;AACA;AACA;AACO,SAAS,aAAa,CAAC,KAAK,EAAE;AACrC,IAAI,OAAO,UAAU,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AAC3C;;;;"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AmplifyClassV6, ResourcesConfig } from '@aws-amplify/core';
|
|
2
|
-
import { ModelTypes, CustomHeaders } from '@aws-amplify/data-schema-types';
|
|
2
|
+
import { ModelTypes, CustomHeaders, EnumTypes } from '@aws-amplify/data-schema-types';
|
|
3
3
|
import { Source, DocumentNode, GraphQLError } from 'graphql';
|
|
4
4
|
export { OperationTypeNode } from 'graphql';
|
|
5
5
|
import { Observable } from 'rxjs';
|
|
@@ -294,6 +294,7 @@ export type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
|
|
|
294
294
|
cancel: (promise: Promise<any>, message?: string) => boolean;
|
|
295
295
|
isCancelError: (error: any) => boolean;
|
|
296
296
|
models: ModelTypes<T>;
|
|
297
|
+
enums: EnumTypes<T>;
|
|
297
298
|
}>;
|
|
298
299
|
export type V6ClientSSRRequest<T extends Record<any, any> = never> = ExcludeNeverFields<{
|
|
299
300
|
[__amplify]: AmplifyClassV6;
|
|
@@ -4,8 +4,11 @@ import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
|
4
4
|
*/
|
|
5
5
|
export declare const resolveLibraryOptions: (amplify: AmplifyClassV6) => {
|
|
6
6
|
headers: ((options?: {
|
|
7
|
+
/**
|
|
8
|
+
* @internal
|
|
9
|
+
*/
|
|
7
10
|
query?: string | undefined;
|
|
8
11
|
variables?: Record<string, import("@aws-amplify/core/internals/utils").DocumentType> | undefined;
|
|
9
|
-
} | undefined) => Promise<
|
|
12
|
+
} | undefined) => Promise<Record<string, unknown> | import("@aws-amplify/core/internals/aws-client-utils").Headers>) | undefined;
|
|
10
13
|
withCredentials: boolean | undefined;
|
|
11
14
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/api-graphql",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.17-unstable.1fdbb12.0+1fdbb12",
|
|
4
4
|
"description": "Api-graphql category of aws-amplify",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.mjs",
|
|
@@ -84,9 +84,9 @@
|
|
|
84
84
|
"server"
|
|
85
85
|
],
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"@aws-amplify/api-rest": "4.0.
|
|
88
|
-
"@aws-amplify/core": "6.0.
|
|
89
|
-
"@aws-amplify/data-schema-types": "^0.7.
|
|
87
|
+
"@aws-amplify/api-rest": "4.0.17-unstable.1fdbb12.0+1fdbb12",
|
|
88
|
+
"@aws-amplify/core": "6.0.17-unstable.1fdbb12.0+1fdbb12",
|
|
89
|
+
"@aws-amplify/data-schema-types": "^0.7.2",
|
|
90
90
|
"@aws-sdk/types": "3.387.0",
|
|
91
91
|
"graphql": "15.8.0",
|
|
92
92
|
"rxjs": "^7.8.1",
|
|
@@ -101,5 +101,5 @@
|
|
|
101
101
|
"limit": "91.7 kB"
|
|
102
102
|
}
|
|
103
103
|
],
|
|
104
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "1fdbb12f85d1a363258c4ebeb5aa7c98ee619e16"
|
|
105
105
|
}
|
package/src/GraphQLAPI.ts
CHANGED
|
@@ -10,7 +10,7 @@ import { Observable } from 'rxjs';
|
|
|
10
10
|
export const graphqlOperation = (
|
|
11
11
|
query: any,
|
|
12
12
|
variables = {},
|
|
13
|
-
authToken?: string
|
|
13
|
+
authToken?: string,
|
|
14
14
|
) => ({
|
|
15
15
|
query,
|
|
16
16
|
variables,
|
|
@@ -35,7 +35,7 @@ export class GraphQLAPIClass extends InternalGraphQLAPIClass {
|
|
|
35
35
|
graphql<T = any>(
|
|
36
36
|
amplify: AmplifyClassV6 | (() => Promise<AmplifyClassV6>),
|
|
37
37
|
options: GraphQLOptions,
|
|
38
|
-
additionalHeaders?: CustomHeaders
|
|
38
|
+
additionalHeaders?: CustomHeaders,
|
|
39
39
|
): Observable<GraphQLResult<T>> | Promise<GraphQLResult<T>> {
|
|
40
40
|
return super.graphql(amplify, options, additionalHeaders, {
|
|
41
41
|
category: Category.API,
|
|
@@ -158,7 +158,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
158
158
|
) {
|
|
159
159
|
this.reconnectionMonitor.record(ReconnectEvent.HALT_RECONNECT);
|
|
160
160
|
}
|
|
161
|
-
}
|
|
161
|
+
},
|
|
162
162
|
);
|
|
163
163
|
}
|
|
164
164
|
|
|
@@ -191,7 +191,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
191
191
|
|
|
192
192
|
subscribe(
|
|
193
193
|
options?: AWSAppSyncRealTimeProviderOptions,
|
|
194
|
-
customUserAgentDetails?: CustomUserAgentDetails
|
|
194
|
+
customUserAgentDetails?: CustomUserAgentDetails,
|
|
195
195
|
): Observable<Record<string, unknown>> {
|
|
196
196
|
const {
|
|
197
197
|
appSyncGraphqlEndpoint,
|
|
@@ -211,7 +211,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
211
211
|
errors: [
|
|
212
212
|
{
|
|
213
213
|
...new GraphQLError(
|
|
214
|
-
`Subscribe only available for AWS AppSync endpoint
|
|
214
|
+
`Subscribe only available for AWS AppSync endpoint`,
|
|
215
215
|
),
|
|
216
216
|
},
|
|
217
217
|
],
|
|
@@ -242,7 +242,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
242
242
|
customUserAgentDetails,
|
|
243
243
|
}).catch<any>(err => {
|
|
244
244
|
logger.debug(
|
|
245
|
-
`${CONTROL_MSG.REALTIME_SUBSCRIPTION_INIT_ERROR}: ${err}
|
|
245
|
+
`${CONTROL_MSG.REALTIME_SUBSCRIPTION_INIT_ERROR}: ${err}`,
|
|
246
246
|
);
|
|
247
247
|
|
|
248
248
|
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
|
|
@@ -428,13 +428,13 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
428
428
|
private _logStartSubscriptionError(
|
|
429
429
|
subscriptionId: string,
|
|
430
430
|
observer: PubSubContentObserver,
|
|
431
|
-
err: { message?: string }
|
|
431
|
+
err: { message?: string },
|
|
432
432
|
) {
|
|
433
433
|
logger.debug({ err });
|
|
434
434
|
const message = String(err.message ?? '');
|
|
435
435
|
// Resolving to give the state observer time to propogate the update
|
|
436
436
|
Promise.resolve(
|
|
437
|
-
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED)
|
|
437
|
+
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED),
|
|
438
438
|
);
|
|
439
439
|
|
|
440
440
|
// Capture the error only when the network didn't cause disruption
|
|
@@ -447,7 +447,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
447
447
|
errors: [
|
|
448
448
|
{
|
|
449
449
|
...new GraphQLError(
|
|
450
|
-
`${CONTROL_MSG.CONNECTION_FAILED}: ${message}
|
|
450
|
+
`${CONTROL_MSG.CONNECTION_FAILED}: ${message}`,
|
|
451
451
|
),
|
|
452
452
|
},
|
|
453
453
|
],
|
|
@@ -558,7 +558,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
558
558
|
return;
|
|
559
559
|
}
|
|
560
560
|
logger.debug(
|
|
561
|
-
`subscription message from AWS AppSync RealTime: ${message.data}
|
|
561
|
+
`subscription message from AWS AppSync RealTime: ${message.data}`,
|
|
562
562
|
);
|
|
563
563
|
const {
|
|
564
564
|
id = '',
|
|
@@ -587,7 +587,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
587
587
|
|
|
588
588
|
if (type === MESSAGE_TYPES.GQL_START_ACK) {
|
|
589
589
|
logger.debug(
|
|
590
|
-
`subscription ready for ${JSON.stringify({ query, variables })}
|
|
590
|
+
`subscription ready for ${JSON.stringify({ query, variables })}`,
|
|
591
591
|
);
|
|
592
592
|
if (typeof subscriptionReadyCallback === 'function') {
|
|
593
593
|
subscriptionReadyCallback();
|
|
@@ -611,7 +611,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
611
611
|
});
|
|
612
612
|
}
|
|
613
613
|
this.connectionStateMonitor.record(
|
|
614
|
-
CONNECTION_CHANGE.CONNECTION_ESTABLISHED
|
|
614
|
+
CONNECTION_CHANGE.CONNECTION_ESTABLISHED,
|
|
615
615
|
);
|
|
616
616
|
|
|
617
617
|
return;
|
|
@@ -623,7 +623,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
623
623
|
clearTimeout(this.keepAliveAlertTimeoutId);
|
|
624
624
|
this.keepAliveTimeoutId = setTimeout(
|
|
625
625
|
() => this._errorDisconnect(CONTROL_MSG.TIMEOUT_DISCONNECT),
|
|
626
|
-
this.keepAliveTimeout
|
|
626
|
+
this.keepAliveTimeout,
|
|
627
627
|
);
|
|
628
628
|
this.keepAliveAlertTimeoutId = setTimeout(() => {
|
|
629
629
|
this.connectionStateMonitor.record(CONNECTION_CHANGE.KEEP_ALIVE_MISSED);
|
|
@@ -646,14 +646,14 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
646
646
|
});
|
|
647
647
|
|
|
648
648
|
logger.debug(
|
|
649
|
-
`${CONTROL_MSG.CONNECTION_FAILED}: ${JSON.stringify(payload)}
|
|
649
|
+
`${CONTROL_MSG.CONNECTION_FAILED}: ${JSON.stringify(payload)}`,
|
|
650
650
|
);
|
|
651
651
|
|
|
652
652
|
observer.error({
|
|
653
653
|
errors: [
|
|
654
654
|
{
|
|
655
655
|
...new GraphQLError(
|
|
656
|
-
`${CONTROL_MSG.CONNECTION_FAILED}: ${JSON.stringify(payload)}
|
|
656
|
+
`${CONTROL_MSG.CONNECTION_FAILED}: ${JSON.stringify(payload)}`,
|
|
657
657
|
),
|
|
658
658
|
},
|
|
659
659
|
],
|
|
@@ -697,7 +697,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
697
697
|
this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
|
|
698
698
|
logger.debug(
|
|
699
699
|
'timeoutStartSubscription',
|
|
700
|
-
JSON.stringify({ query, variables })
|
|
700
|
+
JSON.stringify({ query, variables }),
|
|
701
701
|
);
|
|
702
702
|
}
|
|
703
703
|
}
|
|
@@ -785,7 +785,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
785
785
|
await jitteredExponentialRetry(
|
|
786
786
|
this._initializeHandshake.bind(this),
|
|
787
787
|
[awsRealTimeUrl],
|
|
788
|
-
MAX_DELAY_MS
|
|
788
|
+
MAX_DELAY_MS,
|
|
789
789
|
);
|
|
790
790
|
}
|
|
791
791
|
|
|
@@ -827,7 +827,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
827
827
|
return;
|
|
828
828
|
}
|
|
829
829
|
logger.debug(
|
|
830
|
-
`subscription message from AWS AppSyncRealTime: ${message.data}
|
|
830
|
+
`subscription message from AWS AppSyncRealTime: ${message.data} `,
|
|
831
831
|
);
|
|
832
832
|
const data = JSON.parse(message.data) as ParsedMessagePayload;
|
|
833
833
|
const {
|
|
@@ -874,12 +874,12 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
874
874
|
const checkAckOk = (ackOk: boolean) => {
|
|
875
875
|
if (!ackOk) {
|
|
876
876
|
this.connectionStateMonitor.record(
|
|
877
|
-
CONNECTION_CHANGE.CONNECTION_FAILED
|
|
877
|
+
CONNECTION_CHANGE.CONNECTION_FAILED,
|
|
878
878
|
);
|
|
879
879
|
rej(
|
|
880
880
|
new Error(
|
|
881
|
-
`Connection timeout: ack from AWSAppSyncRealTime was not received after ${CONNECTION_INIT_TIMEOUT} ms
|
|
882
|
-
)
|
|
881
|
+
`Connection timeout: ack from AWSAppSyncRealTime was not received after ${CONNECTION_INIT_TIMEOUT} ms`,
|
|
882
|
+
),
|
|
883
883
|
);
|
|
884
884
|
}
|
|
885
885
|
};
|
|
@@ -1010,7 +1010,7 @@ export class AWSAppSyncRealTimeProvider {
|
|
|
1010
1010
|
credentials: creds!,
|
|
1011
1011
|
signingRegion: endpointInfo.region!,
|
|
1012
1012
|
signingService: endpointInfo.service,
|
|
1013
|
-
}
|
|
1013
|
+
},
|
|
1014
1014
|
);
|
|
1015
1015
|
return signed_params.headers;
|
|
1016
1016
|
}
|
|
@@ -579,8 +579,6 @@ export function generateGraphQLDocument(
|
|
|
579
579
|
);
|
|
580
580
|
}
|
|
581
581
|
|
|
582
|
-
console.log('indexQueryArgs', indexQueryArgs!);
|
|
583
|
-
|
|
584
582
|
let graphQLOperationType: 'mutation' | 'query' | 'subscription' | undefined;
|
|
585
583
|
let graphQLSelectionSet: string | undefined;
|
|
586
584
|
let graphQLArguments: Record<string, any> | undefined;
|
|
@@ -613,10 +611,10 @@ export function generateGraphQLDocument(
|
|
|
613
611
|
return acc;
|
|
614
612
|
},
|
|
615
613
|
{},
|
|
616
|
-
|
|
614
|
+
)
|
|
617
615
|
: {
|
|
618
616
|
[primaryKeyFieldName]: `${fields[primaryKeyFieldName].type}!`,
|
|
619
|
-
|
|
617
|
+
});
|
|
620
618
|
graphQLSelectionSet ?? (graphQLSelectionSet = selectionSetFields);
|
|
621
619
|
case 'LIST':
|
|
622
620
|
graphQLArguments ??
|
|
@@ -660,13 +658,13 @@ export function generateGraphQLDocument(
|
|
|
660
658
|
graphQLArguments
|
|
661
659
|
? `(${Object.entries(graphQLArguments).map(
|
|
662
660
|
([fieldName, type]) => `\$${fieldName}: ${type}`,
|
|
663
|
-
|
|
661
|
+
)})`
|
|
664
662
|
: ''
|
|
665
663
|
} { ${graphQLFieldName}${
|
|
666
664
|
graphQLArguments
|
|
667
665
|
? `(${Object.keys(graphQLArguments).map(
|
|
668
666
|
fieldName => `${fieldName}: \$${fieldName}`,
|
|
669
|
-
|
|
667
|
+
)})`
|
|
670
668
|
: ''
|
|
671
669
|
} { ${graphQLSelectionSet} } }`;
|
|
672
670
|
|
|
@@ -716,7 +714,7 @@ export function buildGraphQLVariables(
|
|
|
716
714
|
|
|
717
715
|
return !isReadOnly;
|
|
718
716
|
}),
|
|
719
|
-
|
|
717
|
+
)
|
|
720
718
|
: {},
|
|
721
719
|
};
|
|
722
720
|
break;
|
|
@@ -732,7 +730,7 @@ export function buildGraphQLVariables(
|
|
|
732
730
|
return acc;
|
|
733
731
|
},
|
|
734
732
|
{},
|
|
735
|
-
|
|
733
|
+
)
|
|
736
734
|
: { [primaryKeyFieldName]: arg[primaryKeyFieldName] };
|
|
737
735
|
}
|
|
738
736
|
|
|
@@ -40,7 +40,7 @@ const logger = new ConsoleLogger('GraphQLAPI');
|
|
|
40
40
|
const isAmplifyInstance = (
|
|
41
41
|
amplify:
|
|
42
42
|
| AmplifyClassV6
|
|
43
|
-
| ((fn: (amplify: any) => Promise<any>) => Promise<AmplifyClassV6>)
|
|
43
|
+
| ((fn: (amplify: any) => Promise<any>) => Promise<AmplifyClassV6>),
|
|
44
44
|
): amplify is AmplifyClassV6 => {
|
|
45
45
|
return typeof amplify !== 'function';
|
|
46
46
|
};
|
|
@@ -68,7 +68,7 @@ export class InternalGraphQLAPIClass {
|
|
|
68
68
|
private async _headerBasedAuth(
|
|
69
69
|
amplify: AmplifyClassV6,
|
|
70
70
|
authMode: GraphQLAuthMode,
|
|
71
|
-
additionalHeaders: Record<string, string> = {}
|
|
71
|
+
additionalHeaders: Record<string, string> = {},
|
|
72
72
|
) {
|
|
73
73
|
const {
|
|
74
74
|
region: region,
|
|
@@ -159,7 +159,7 @@ export class InternalGraphQLAPIClass {
|
|
|
159
159
|
| ((fn: (amplify: any) => Promise<any>) => Promise<AmplifyClassV6>),
|
|
160
160
|
{ query: paramQuery, variables = {}, authMode, authToken }: GraphQLOptions,
|
|
161
161
|
additionalHeaders?: CustomHeaders,
|
|
162
|
-
customUserAgentDetails?: CustomUserAgentDetails
|
|
162
|
+
customUserAgentDetails?: CustomUserAgentDetails,
|
|
163
163
|
): Observable<GraphQLResult<T>> | Promise<GraphQLResult<T>> {
|
|
164
164
|
const query =
|
|
165
165
|
typeof paramQuery === 'string'
|
|
@@ -167,7 +167,7 @@ export class InternalGraphQLAPIClass {
|
|
|
167
167
|
: parse(print(paramQuery));
|
|
168
168
|
|
|
169
169
|
const [operationDef = {}] = query.definitions.filter(
|
|
170
|
-
def => def.kind === 'OperationDefinition'
|
|
170
|
+
def => def.kind === 'OperationDefinition',
|
|
171
171
|
);
|
|
172
172
|
const { operation: operationType } =
|
|
173
173
|
operationDef as OperationDefinitionNode;
|
|
@@ -188,19 +188,24 @@ export class InternalGraphQLAPIClass {
|
|
|
188
188
|
headers,
|
|
189
189
|
abortController,
|
|
190
190
|
customUserAgentDetails,
|
|
191
|
-
authToken
|
|
191
|
+
authToken,
|
|
192
192
|
);
|
|
193
193
|
} else {
|
|
194
|
-
|
|
195
|
-
|
|
194
|
+
// NOTE: this wrapper function must be await-able so the Amplify server context manager can
|
|
195
|
+
// destroy the context only after it completes
|
|
196
|
+
const wrapper = async (amplifyInstance: AmplifyClassV6) => {
|
|
197
|
+
const result = await this._graphql<T>(
|
|
196
198
|
amplifyInstance,
|
|
197
199
|
{ query, variables, authMode },
|
|
198
200
|
headers,
|
|
199
201
|
abortController,
|
|
200
202
|
customUserAgentDetails,
|
|
201
|
-
authToken
|
|
203
|
+
authToken,
|
|
202
204
|
);
|
|
203
205
|
|
|
206
|
+
return result;
|
|
207
|
+
};
|
|
208
|
+
|
|
204
209
|
responsePromise = amplify(wrapper) as unknown as Promise<
|
|
205
210
|
GraphQLResult<T>
|
|
206
211
|
>;
|
|
@@ -208,7 +213,7 @@ export class InternalGraphQLAPIClass {
|
|
|
208
213
|
|
|
209
214
|
this._api.updateRequestToBeCancellable(
|
|
210
215
|
responsePromise,
|
|
211
|
-
abortController
|
|
216
|
+
abortController,
|
|
212
217
|
);
|
|
213
218
|
return responsePromise;
|
|
214
219
|
case 'subscription':
|
|
@@ -217,7 +222,7 @@ export class InternalGraphQLAPIClass {
|
|
|
217
222
|
{ query, variables, authMode },
|
|
218
223
|
headers,
|
|
219
224
|
customUserAgentDetails,
|
|
220
|
-
authToken
|
|
225
|
+
authToken,
|
|
221
226
|
);
|
|
222
227
|
default:
|
|
223
228
|
throw new Error(`invalid operation type: ${operationType}`);
|
|
@@ -230,7 +235,7 @@ export class InternalGraphQLAPIClass {
|
|
|
230
235
|
additionalHeaders: CustomHeaders = {},
|
|
231
236
|
abortController: AbortController,
|
|
232
237
|
customUserAgentDetails?: CustomUserAgentDetails,
|
|
233
|
-
authToken?: string
|
|
238
|
+
authToken?: string,
|
|
234
239
|
): Promise<GraphQLResult<T>> {
|
|
235
240
|
const {
|
|
236
241
|
region: region,
|
|
@@ -263,7 +268,7 @@ export class InternalGraphQLAPIClass {
|
|
|
263
268
|
const requestOptions: RequestOptions = {
|
|
264
269
|
method: 'POST',
|
|
265
270
|
url: new AmplifyUrl(
|
|
266
|
-
customEndpoint || appSyncGraphqlEndpoint || ''
|
|
271
|
+
customEndpoint || appSyncGraphqlEndpoint || '',
|
|
267
272
|
).toString(),
|
|
268
273
|
queryString: print(query as DocumentNode),
|
|
269
274
|
};
|
|
@@ -287,7 +292,7 @@ export class InternalGraphQLAPIClass {
|
|
|
287
292
|
(await this._headerBasedAuth(
|
|
288
293
|
amplify,
|
|
289
294
|
authMode!,
|
|
290
|
-
additionalCustomHeaders
|
|
295
|
+
additionalCustomHeaders,
|
|
291
296
|
))),
|
|
292
297
|
/**
|
|
293
298
|
* Custom endpoint headers.
|
|
@@ -300,8 +305,8 @@ export class InternalGraphQLAPIClass {
|
|
|
300
305
|
? await this._headerBasedAuth(
|
|
301
306
|
amplify,
|
|
302
307
|
authMode!,
|
|
303
|
-
additionalCustomHeaders
|
|
304
|
-
|
|
308
|
+
additionalCustomHeaders,
|
|
309
|
+
)
|
|
305
310
|
: {})) ||
|
|
306
311
|
{}),
|
|
307
312
|
// Custom headers included in Amplify configuration options:
|
|
@@ -361,7 +366,7 @@ export class InternalGraphQLAPIClass {
|
|
|
361
366
|
let response: any;
|
|
362
367
|
|
|
363
368
|
try {
|
|
364
|
-
const { body: responseBody } = await this._api.post({
|
|
369
|
+
const { body: responseBody } = await this._api.post(amplify, {
|
|
365
370
|
url: new AmplifyUrl(endpoint),
|
|
366
371
|
options: {
|
|
367
372
|
headers,
|
|
@@ -392,7 +397,7 @@ export class InternalGraphQLAPIClass {
|
|
|
392
397
|
null,
|
|
393
398
|
null,
|
|
394
399
|
null,
|
|
395
|
-
err as any
|
|
400
|
+
err as any,
|
|
396
401
|
),
|
|
397
402
|
],
|
|
398
403
|
};
|
|
@@ -430,7 +435,7 @@ export class InternalGraphQLAPIClass {
|
|
|
430
435
|
{ query, variables, authMode }: GraphQLOptions,
|
|
431
436
|
additionalHeaders: CustomHeaders = {},
|
|
432
437
|
customUserAgentDetails?: CustomUserAgentDetails,
|
|
433
|
-
authToken?: string
|
|
438
|
+
authToken?: string,
|
|
434
439
|
): Observable<any> {
|
|
435
440
|
const config = resolveConfig(amplify);
|
|
436
441
|
|
|
@@ -457,7 +462,7 @@ export class InternalGraphQLAPIClass {
|
|
|
457
462
|
authToken,
|
|
458
463
|
libraryConfigHeaders,
|
|
459
464
|
},
|
|
460
|
-
customUserAgentDetails
|
|
465
|
+
customUserAgentDetails,
|
|
461
466
|
)
|
|
462
467
|
.pipe(
|
|
463
468
|
catchError(e => {
|
|
@@ -465,7 +470,7 @@ export class InternalGraphQLAPIClass {
|
|
|
465
470
|
throw repackageUnauthError(e);
|
|
466
471
|
}
|
|
467
472
|
throw e;
|
|
468
|
-
})
|
|
473
|
+
}),
|
|
469
474
|
);
|
|
470
475
|
}
|
|
471
476
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { Hub } from '@aws-amplify/core';
|
|
4
|
+
import { EnumTypes, ModelTypes } from '@aws-amplify/data-schema-types';
|
|
3
5
|
import { graphql, cancel, isCancelError } from './v6';
|
|
4
|
-
import {
|
|
6
|
+
import { generateEnumsProperty } from './utils/generateEnumsProperty';
|
|
7
|
+
import { generateModelsProperty } from './utils/generateModelsProperty';
|
|
8
|
+
import { isApiGraphQLConfig } from './utils/isApiGraphQLProviderConfig';
|
|
5
9
|
import {
|
|
6
10
|
V6Client,
|
|
7
11
|
__amplify,
|
|
@@ -10,8 +14,7 @@ import {
|
|
|
10
14
|
__headers,
|
|
11
15
|
} from '../types';
|
|
12
16
|
import { ClientGenerationParams } from './types';
|
|
13
|
-
import {
|
|
14
|
-
import { Hub, HubCapsule, ResourcesConfig } from '@aws-amplify/core';
|
|
17
|
+
import { isConfigureEventWithResourceConfig } from './utils/isConfigureEventWithResourceConfig';
|
|
15
18
|
|
|
16
19
|
/**
|
|
17
20
|
* @private
|
|
@@ -23,7 +26,7 @@ import { Hub, HubCapsule, ResourcesConfig } from '@aws-amplify/core';
|
|
|
23
26
|
* @returns
|
|
24
27
|
*/
|
|
25
28
|
export function generateClient<T extends Record<any, any> = never>(
|
|
26
|
-
params: ClientGenerationParams
|
|
29
|
+
params: ClientGenerationParams,
|
|
27
30
|
): V6Client<T> {
|
|
28
31
|
const client = {
|
|
29
32
|
[__amplify]: params.amplify,
|
|
@@ -33,12 +36,16 @@ export function generateClient<T extends Record<any, any> = never>(
|
|
|
33
36
|
graphql,
|
|
34
37
|
cancel,
|
|
35
38
|
isCancelError,
|
|
36
|
-
models:
|
|
39
|
+
models: emptyProperty as ModelTypes<never>,
|
|
40
|
+
enums: emptyProperty as EnumTypes<never>,
|
|
37
41
|
} as any;
|
|
38
42
|
|
|
39
|
-
const
|
|
43
|
+
const apiGraphqlConfig = params.amplify.getConfig().API?.GraphQL;
|
|
40
44
|
|
|
41
|
-
if (
|
|
45
|
+
if (isApiGraphQLConfig(apiGraphqlConfig)) {
|
|
46
|
+
client.models = generateModelsProperty<T>(client, apiGraphqlConfig);
|
|
47
|
+
client.enums = generateEnumsProperty<T>(apiGraphqlConfig);
|
|
48
|
+
} else {
|
|
42
49
|
// This happens when the `Amplify.configure()` call gets evaluated after the `generateClient()` call.
|
|
43
50
|
//
|
|
44
51
|
// Cause: when the `generateClient()` and the `Amplify.configure()` calls are located in
|
|
@@ -51,52 +58,33 @@ export function generateClient<T extends Record<any, any> = never>(
|
|
|
51
58
|
//
|
|
52
59
|
// TODO: revisit, and reverify this approach when enabling multiple clients for multi-endpoints
|
|
53
60
|
// configuration.
|
|
54
|
-
client
|
|
55
|
-
generateModelsPropertyOnAmplifyConfigure<T>(client);
|
|
56
|
-
} else {
|
|
57
|
-
client.models = generateModelsProperty<T>(
|
|
58
|
-
client,
|
|
59
|
-
config.API?.GraphQL,
|
|
60
|
-
);
|
|
61
|
+
generateModelsPropertyOnAmplifyConfigure(client);
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
return client as V6Client<T>;
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
const generateModelsPropertyOnAmplifyConfigure =
|
|
67
|
-
T extends Record<any, any> = never,
|
|
68
|
-
>(clientRef: any) => {
|
|
67
|
+
const generateModelsPropertyOnAmplifyConfigure = (clientRef: any) => {
|
|
69
68
|
Hub.listen('core', coreEvent => {
|
|
70
|
-
if (!
|
|
69
|
+
if (!isConfigureEventWithResourceConfig(coreEvent.payload)) {
|
|
71
70
|
return;
|
|
72
71
|
}
|
|
73
72
|
|
|
74
|
-
const
|
|
73
|
+
const apiGraphQLConfig = coreEvent.payload.data.API?.GraphQL;
|
|
75
74
|
|
|
76
|
-
if (
|
|
77
|
-
clientRef.models = generateModelsProperty
|
|
78
|
-
|
|
79
|
-
resourceConfig.API?.GraphQL,
|
|
80
|
-
);
|
|
75
|
+
if (isApiGraphQLConfig(apiGraphQLConfig)) {
|
|
76
|
+
clientRef.models = generateModelsProperty(clientRef, apiGraphQLConfig);
|
|
77
|
+
clientRef.enums = generateEnumsProperty(apiGraphQLConfig);
|
|
81
78
|
}
|
|
82
79
|
});
|
|
83
80
|
};
|
|
84
81
|
|
|
85
|
-
|
|
86
|
-
payload: HubCapsule<'core', { event: string; data?: unknown }>['payload'],
|
|
87
|
-
): payload is {
|
|
88
|
-
event: 'configure';
|
|
89
|
-
data: ResourcesConfig;
|
|
90
|
-
} {
|
|
91
|
-
return payload.event === 'configure';
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
const emptyModels = new Proxy(
|
|
82
|
+
const emptyProperty = new Proxy(
|
|
95
83
|
{},
|
|
96
84
|
{
|
|
97
85
|
get() {
|
|
98
86
|
throw new Error(
|
|
99
|
-
'
|
|
87
|
+
'Client could not be generated. This is likely due to `Amplify.configure()` not being called prior to `generateClient()` or because the configuration passed to `Amplify.configure()` is missing GraphQL provider configuration.',
|
|
100
88
|
);
|
|
101
89
|
},
|
|
102
90
|
},
|