@aws-amplify/api-graphql 4.0.16 → 4.0.17-unstable.5c56101.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/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/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/types/index.d.ts +2 -1
- package/package.json +5 -5
- package/src/internals/generateClient.ts +23 -35
- 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/types/index.ts +2 -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
|
@@ -4,10 +4,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.generateClient = void 0;
|
|
5
5
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
6
6
|
// SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
const core_1 = require("@aws-amplify/core");
|
|
7
8
|
const v6_1 = require("./v6");
|
|
8
|
-
const
|
|
9
|
+
const generateEnumsProperty_1 = require("./utils/generateEnumsProperty");
|
|
10
|
+
const generateModelsProperty_1 = require("./utils/generateModelsProperty");
|
|
11
|
+
const isApiGraphQLProviderConfig_1 = require("./utils/isApiGraphQLProviderConfig");
|
|
9
12
|
const types_1 = require("../types");
|
|
10
|
-
const
|
|
13
|
+
const isConfigureEventWithResourceConfig_1 = require("./utils/isConfigureEventWithResourceConfig");
|
|
11
14
|
/**
|
|
12
15
|
* @private
|
|
13
16
|
*
|
|
@@ -26,10 +29,15 @@ function generateClient(params) {
|
|
|
26
29
|
graphql: v6_1.graphql,
|
|
27
30
|
cancel: v6_1.cancel,
|
|
28
31
|
isCancelError: v6_1.isCancelError,
|
|
29
|
-
models:
|
|
32
|
+
models: emptyProperty,
|
|
33
|
+
enums: emptyProperty,
|
|
30
34
|
};
|
|
31
|
-
const
|
|
32
|
-
if (
|
|
35
|
+
const apiGraphqlConfig = params.amplify.getConfig().API?.GraphQL;
|
|
36
|
+
if ((0, isApiGraphQLProviderConfig_1.isApiGraphQLConfig)(apiGraphqlConfig)) {
|
|
37
|
+
client.models = (0, generateModelsProperty_1.generateModelsProperty)(client, apiGraphqlConfig);
|
|
38
|
+
client.enums = (0, generateEnumsProperty_1.generateEnumsProperty)(apiGraphqlConfig);
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
33
41
|
// This happens when the `Amplify.configure()` call gets evaluated after the `generateClient()` call.
|
|
34
42
|
//
|
|
35
43
|
// Cause: when the `generateClient()` and the `Amplify.configure()` calls are located in
|
|
@@ -42,32 +50,26 @@ function generateClient(params) {
|
|
|
42
50
|
//
|
|
43
51
|
// TODO: revisit, and reverify this approach when enabling multiple clients for multi-endpoints
|
|
44
52
|
// configuration.
|
|
45
|
-
client.models = emptyModels;
|
|
46
53
|
generateModelsPropertyOnAmplifyConfigure(client);
|
|
47
54
|
}
|
|
48
|
-
else {
|
|
49
|
-
client.models = (0, generateModelsProperty_1.generateModelsProperty)(client, config.API?.GraphQL);
|
|
50
|
-
}
|
|
51
55
|
return client;
|
|
52
56
|
}
|
|
53
57
|
exports.generateClient = generateClient;
|
|
54
58
|
const generateModelsPropertyOnAmplifyConfigure = (clientRef) => {
|
|
55
59
|
core_1.Hub.listen('core', coreEvent => {
|
|
56
|
-
if (!
|
|
60
|
+
if (!(0, isConfigureEventWithResourceConfig_1.isConfigureEventWithResourceConfig)(coreEvent.payload)) {
|
|
57
61
|
return;
|
|
58
62
|
}
|
|
59
|
-
const
|
|
60
|
-
if (
|
|
61
|
-
clientRef.models = (0, generateModelsProperty_1.generateModelsProperty)(clientRef,
|
|
63
|
+
const apiGraphQLConfig = coreEvent.payload.data.API?.GraphQL;
|
|
64
|
+
if ((0, isApiGraphQLProviderConfig_1.isApiGraphQLConfig)(apiGraphQLConfig)) {
|
|
65
|
+
clientRef.models = (0, generateModelsProperty_1.generateModelsProperty)(clientRef, apiGraphQLConfig);
|
|
66
|
+
clientRef.enums = (0, generateEnumsProperty_1.generateEnumsProperty)(apiGraphQLConfig);
|
|
62
67
|
}
|
|
63
68
|
});
|
|
64
69
|
};
|
|
65
|
-
|
|
66
|
-
return payload.event === 'configure';
|
|
67
|
-
}
|
|
68
|
-
const emptyModels = new Proxy({}, {
|
|
70
|
+
const emptyProperty = new Proxy({}, {
|
|
69
71
|
get() {
|
|
70
|
-
throw new Error('
|
|
72
|
+
throw new Error('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.');
|
|
71
73
|
},
|
|
72
74
|
});
|
|
73
75
|
//# sourceMappingURL=generateClient.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateClient.js","sources":["../../../src/internals/generateClient.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.generateClient = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst v6_1 = require(\"./v6\");\nconst generateModelsProperty_1 = require(\"./generateModelsProperty\");\nconst types_1 = require(\"../types\");\nconst
|
|
1
|
+
{"version":3,"file":"generateClient.js","sources":["../../../src/internals/generateClient.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.generateClient = void 0;\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nconst core_1 = require(\"@aws-amplify/core\");\nconst v6_1 = require(\"./v6\");\nconst generateEnumsProperty_1 = require(\"./utils/generateEnumsProperty\");\nconst generateModelsProperty_1 = require(\"./utils/generateModelsProperty\");\nconst isApiGraphQLProviderConfig_1 = require(\"./utils/isApiGraphQLProviderConfig\");\nconst types_1 = require(\"../types\");\nconst isConfigureEventWithResourceConfig_1 = require(\"./utils/isConfigureEventWithResourceConfig\");\n/**\n * @private\n *\n * Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`\n * compatible context object for config and auth fetching.\n *\n * @param params\n * @returns\n */\nfunction generateClient(params) {\n const client = {\n [types_1.__amplify]: params.amplify,\n [types_1.__authMode]: params.authMode,\n [types_1.__authToken]: params.authToken,\n [types_1.__headers]: params.headers,\n graphql: v6_1.graphql,\n cancel: v6_1.cancel,\n isCancelError: v6_1.isCancelError,\n models: emptyProperty,\n enums: emptyProperty,\n };\n const apiGraphqlConfig = params.amplify.getConfig().API?.GraphQL;\n if ((0, isApiGraphQLProviderConfig_1.isApiGraphQLConfig)(apiGraphqlConfig)) {\n client.models = (0, generateModelsProperty_1.generateModelsProperty)(client, apiGraphqlConfig);\n client.enums = (0, generateEnumsProperty_1.generateEnumsProperty)(apiGraphqlConfig);\n }\n else {\n // This happens when the `Amplify.configure()` call gets evaluated after the `generateClient()` call.\n //\n // Cause: when the `generateClient()` and the `Amplify.configure()` calls are located in\n // different source files, script bundlers may randomly arrange their orders in the production\n // bundle.\n //\n // With the current implementation, the `client.models` instance created by `generateClient()`\n // will be rebuilt on every `Amplify.configure()` call that's provided with a valid GraphQL\n // provider configuration.\n //\n // TODO: revisit, and reverify this approach when enabling multiple clients for multi-endpoints\n // configuration.\n generateModelsPropertyOnAmplifyConfigure(client);\n }\n return client;\n}\nexports.generateClient = generateClient;\nconst generateModelsPropertyOnAmplifyConfigure = (clientRef) => {\n core_1.Hub.listen('core', coreEvent => {\n if (!(0, isConfigureEventWithResourceConfig_1.isConfigureEventWithResourceConfig)(coreEvent.payload)) {\n return;\n }\n const apiGraphQLConfig = coreEvent.payload.data.API?.GraphQL;\n if ((0, isApiGraphQLProviderConfig_1.isApiGraphQLConfig)(apiGraphQLConfig)) {\n clientRef.models = (0, generateModelsProperty_1.generateModelsProperty)(clientRef, apiGraphQLConfig);\n clientRef.enums = (0, generateEnumsProperty_1.generateEnumsProperty)(apiGraphQLConfig);\n }\n });\n};\nconst emptyProperty = new Proxy({}, {\n get() {\n throw new Error('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.');\n },\n});\n"],"names":[],"mapp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AAQ,MAAM,IAAI,KAAK,CAAC,iOAAiO,CAAC,CAAC;AAC3P,KAAK;AACL,CAAC,CAAC;;"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateEnumsProperty = void 0;
|
|
7
|
+
const generateEnumsProperty = (graphqlConfig) => {
|
|
8
|
+
const modelIntrospection = graphqlConfig.modelIntrospection;
|
|
9
|
+
if (!modelIntrospection) {
|
|
10
|
+
return {};
|
|
11
|
+
}
|
|
12
|
+
const enums = {};
|
|
13
|
+
for (const [_, enumData] of Object.entries(modelIntrospection.enums)) {
|
|
14
|
+
enums[enumData.name] = {
|
|
15
|
+
values: () => enumData.values,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
return enums;
|
|
19
|
+
};
|
|
20
|
+
exports.generateEnumsProperty = generateEnumsProperty;
|
|
21
|
+
//# sourceMappingURL=generateEnumsProperty.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateEnumsProperty.js","sources":["../../../../src/internals/utils/generateEnumsProperty.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.generateEnumsProperty = void 0;\nconst generateEnumsProperty = (graphqlConfig) => {\n const modelIntrospection = graphqlConfig.modelIntrospection;\n if (!modelIntrospection) {\n return {};\n }\n const enums = {};\n for (const [_, enumData] of Object.entries(modelIntrospection.enums)) {\n enums[enumData.name] = {\n values: () => enumData.values,\n };\n }\n return enums;\n};\nexports.generateEnumsProperty = generateEnumsProperty;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,qBAAqB,GAAG,KAAK,CAAC,CAAC;AACvC,MAAM,qBAAqB,GAAG,CAAC,aAAa,KAAK;AACjD,IAAI,MAAM,kBAAkB,GAAG,aAAa,CAAC,kBAAkB,CAAC;AAChE,IAAI,IAAI,CAAC,kBAAkB,EAAE;AAC7B,QAAQ,OAAO,EAAE,CAAC;AAClB,KAAK;AACL,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;AACrB,IAAI,KAAK,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE;AAC1E,QAAQ,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG;AAC/B,YAAY,MAAM,EAAE,MAAM,QAAQ,CAAC,MAAM;AACzC,SAAS,CAAC;AACV,KAAK;AACL,IAAI,OAAO,KAAK,CAAC;AACjB,CAAC,CAAC;AACF,OAAO,CAAC,qBAAqB,GAAG,qBAAqB;;"}
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.generateModelsProperty = void 0;
|
|
5
|
-
const APIClient_1 = require("
|
|
6
|
-
const list_1 = require("
|
|
7
|
-
const indexQuery_1 = require("
|
|
8
|
-
const get_1 = require("
|
|
9
|
-
const subscription_1 = require("
|
|
10
|
-
const observeQuery_1 = require("
|
|
11
|
-
const clientUtils_1 = require("
|
|
12
|
-
function generateModelsProperty(client,
|
|
5
|
+
const APIClient_1 = require("../APIClient");
|
|
6
|
+
const list_1 = require("../operations/list");
|
|
7
|
+
const indexQuery_1 = require("../operations/indexQuery");
|
|
8
|
+
const get_1 = require("../operations/get");
|
|
9
|
+
const subscription_1 = require("../operations/subscription");
|
|
10
|
+
const observeQuery_1 = require("../operations/observeQuery");
|
|
11
|
+
const clientUtils_1 = require("../clientUtils");
|
|
12
|
+
function generateModelsProperty(client, apiGraphQLConfig) {
|
|
13
13
|
const models = {};
|
|
14
|
-
const modelIntrospection =
|
|
14
|
+
const modelIntrospection = apiGraphQLConfig.modelIntrospection;
|
|
15
15
|
if (!modelIntrospection) {
|
|
16
16
|
return {};
|
|
17
17
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateModelsProperty.js","sources":["../../../../src/internals/utils/generateModelsProperty.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.generateModelsProperty = void 0;\nconst APIClient_1 = require(\"../APIClient\");\nconst list_1 = require(\"../operations/list\");\nconst indexQuery_1 = require(\"../operations/indexQuery\");\nconst get_1 = require(\"../operations/get\");\nconst subscription_1 = require(\"../operations/subscription\");\nconst observeQuery_1 = require(\"../operations/observeQuery\");\nconst clientUtils_1 = require(\"../clientUtils\");\nfunction generateModelsProperty(client, apiGraphQLConfig) {\n const models = {};\n const modelIntrospection = apiGraphQLConfig.modelIntrospection;\n if (!modelIntrospection) {\n return {};\n }\n const SUBSCRIPTION_OPS = ['ONCREATE', 'ONUPDATE', 'ONDELETE'];\n for (const model of Object.values(modelIntrospection.models)) {\n const { name } = model;\n models[name] = {};\n Object.entries(APIClient_1.graphQLOperationsInfo).forEach(([key, { operationPrefix }]) => {\n const operation = key;\n if (operation === 'LIST') {\n models[name][operationPrefix] = (0, list_1.listFactory)(client, modelIntrospection, model);\n }\n else if (SUBSCRIPTION_OPS.includes(operation)) {\n models[name][operationPrefix] = (0, subscription_1.subscriptionFactory)(client, modelIntrospection, model, operation);\n }\n else if (operation === 'OBSERVE_QUERY') {\n models[name][operationPrefix] = (0, observeQuery_1.observeQueryFactory)(models, model);\n }\n else {\n models[name][operationPrefix] = (0, get_1.getFactory)(client, modelIntrospection, model, operation);\n }\n });\n const secondaryIdxs = (0, clientUtils_1.getSecondaryIndexesFromSchemaModel)(model);\n for (const idx of secondaryIdxs) {\n models[name][idx.queryField] = (0, indexQuery_1.indexQueryFactory)(client, modelIntrospection, model, idx);\n }\n }\n return models;\n}\nexports.generateModelsProperty = generateModelsProperty;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,sBAAsB,GAAG,KAAK,CAAC,CAAC;AACxC,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAC5C,MAAM,MAAM,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;AAC7C,MAAM,YAAY,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;AACzD,MAAM,KAAK,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC3C,MAAM,cAAc,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;AAC7D,MAAM,cAAc,GAAG,OAAO,CAAC,4BAA4B,CAAC,CAAC;AAC7D,MAAM,aAAa,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAAC;AAChD,SAAS,sBAAsB,CAAC,MAAM,EAAE,gBAAgB,EAAE;AAC1D,IAAI,MAAM,MAAM,GAAG,EAAE,CAAC;AACtB,IAAI,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,kBAAkB,CAAC;AACnE,IAAI,IAAI,CAAC,kBAAkB,EAAE;AAC7B,QAAQ,OAAO,EAAE,CAAC;AAClB,KAAK;AACL,IAAI,MAAM,gBAAgB,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;AAClE,IAAI,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE;AAClE,QAAQ,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;AAC/B,QAAQ,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;AAC1B,QAAQ,MAAM,CAAC,OAA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AC,CAAC;AACvH,SAAS;AACT,KAAK;AACL,IAAI,OAAO,MAAM,CAAC;AAClB,CAAC;AACD,OAAO,CAAC,sBAAsB,GAAG,sBAAsB;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isApiGraphQLConfig = void 0;
|
|
7
|
+
function isApiGraphQLConfig(apiGraphQLConfig) {
|
|
8
|
+
return apiGraphQLConfig !== undefined;
|
|
9
|
+
}
|
|
10
|
+
exports.isApiGraphQLConfig = isApiGraphQLConfig;
|
|
11
|
+
//# sourceMappingURL=isApiGraphQLProviderConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isApiGraphQLProviderConfig.js","sources":["../../../../src/internals/utils/isApiGraphQLProviderConfig.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.isApiGraphQLConfig = void 0;\nfunction isApiGraphQLConfig(apiGraphQLConfig) {\n return apiGraphQLConfig !== undefined;\n}\nexports.isApiGraphQLConfig = isApiGraphQLConfig;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,kBAAkB,GAAG,KAAK,CAAC,CAAC;AACpC,SAAS,kBAAkB,CAAC,gBAAgB,EAAE;AAC9C,IAAI,OAAO,gBAAgB,KAAK,SAAS,CAAC;AAC1C,CAAC;AACD,OAAO,CAAC,kBAAkB,GAAG,kBAAkB;;"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.isConfigureEventWithResourceConfig = void 0;
|
|
7
|
+
function isConfigureEventWithResourceConfig(payload) {
|
|
8
|
+
return payload.event === 'configure';
|
|
9
|
+
}
|
|
10
|
+
exports.isConfigureEventWithResourceConfig = isConfigureEventWithResourceConfig;
|
|
11
|
+
//# sourceMappingURL=isConfigureEventWithResourceConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isConfigureEventWithResourceConfig.js","sources":["../../../../src/internals/utils/isConfigureEventWithResourceConfig.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.isConfigureEventWithResourceConfig = void 0;\nfunction isConfigureEventWithResourceConfig(payload) {\n return payload.event === 'configure';\n}\nexports.isConfigureEventWithResourceConfig = isConfigureEventWithResourceConfig;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,kCAAkC,GAAG,KAAK,CAAC,CAAC;AACpD,SAAS,kCAAkC,CAAC,OAAO,EAAE;AACrD,IAAI,OAAO,OAAO,CAAC,KAAK,KAAK,WAAW,CAAC;AACzC,CAAC;AACD,OAAO,CAAC,kCAAkC,GAAG,kCAAkC;;"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import { Hub } from '@aws-amplify/core';
|
|
1
2
|
import { graphql, cancel, isCancelError } from './v6.mjs';
|
|
2
|
-
import {
|
|
3
|
+
import { generateEnumsProperty } from './utils/generateEnumsProperty.mjs';
|
|
4
|
+
import { generateModelsProperty } from './utils/generateModelsProperty.mjs';
|
|
5
|
+
import { isApiGraphQLConfig } from './utils/isApiGraphQLProviderConfig.mjs';
|
|
3
6
|
import { __amplify, __authMode, __authToken, __headers } from '../types/index.mjs';
|
|
4
|
-
import {
|
|
7
|
+
import { isConfigureEventWithResourceConfig } from './utils/isConfigureEventWithResourceConfig.mjs';
|
|
5
8
|
|
|
6
9
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
7
10
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -23,10 +26,15 @@ function generateClient(params) {
|
|
|
23
26
|
graphql,
|
|
24
27
|
cancel,
|
|
25
28
|
isCancelError,
|
|
26
|
-
models:
|
|
29
|
+
models: emptyProperty,
|
|
30
|
+
enums: emptyProperty,
|
|
27
31
|
};
|
|
28
|
-
const
|
|
29
|
-
if (
|
|
32
|
+
const apiGraphqlConfig = params.amplify.getConfig().API?.GraphQL;
|
|
33
|
+
if (isApiGraphQLConfig(apiGraphqlConfig)) {
|
|
34
|
+
client.models = generateModelsProperty(client, apiGraphqlConfig);
|
|
35
|
+
client.enums = generateEnumsProperty(apiGraphqlConfig);
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
30
38
|
// This happens when the `Amplify.configure()` call gets evaluated after the `generateClient()` call.
|
|
31
39
|
//
|
|
32
40
|
// Cause: when the `generateClient()` and the `Amplify.configure()` calls are located in
|
|
@@ -39,31 +47,25 @@ function generateClient(params) {
|
|
|
39
47
|
//
|
|
40
48
|
// TODO: revisit, and reverify this approach when enabling multiple clients for multi-endpoints
|
|
41
49
|
// configuration.
|
|
42
|
-
client.models = emptyModels;
|
|
43
50
|
generateModelsPropertyOnAmplifyConfigure(client);
|
|
44
51
|
}
|
|
45
|
-
else {
|
|
46
|
-
client.models = generateModelsProperty(client, config.API?.GraphQL);
|
|
47
|
-
}
|
|
48
52
|
return client;
|
|
49
53
|
}
|
|
50
54
|
const generateModelsPropertyOnAmplifyConfigure = (clientRef) => {
|
|
51
55
|
Hub.listen('core', coreEvent => {
|
|
52
|
-
if (!
|
|
56
|
+
if (!isConfigureEventWithResourceConfig(coreEvent.payload)) {
|
|
53
57
|
return;
|
|
54
58
|
}
|
|
55
|
-
const
|
|
56
|
-
if (
|
|
57
|
-
clientRef.models = generateModelsProperty(clientRef,
|
|
59
|
+
const apiGraphQLConfig = coreEvent.payload.data.API?.GraphQL;
|
|
60
|
+
if (isApiGraphQLConfig(apiGraphQLConfig)) {
|
|
61
|
+
clientRef.models = generateModelsProperty(clientRef, apiGraphQLConfig);
|
|
62
|
+
clientRef.enums = generateEnumsProperty(apiGraphQLConfig);
|
|
58
63
|
}
|
|
59
64
|
});
|
|
60
65
|
};
|
|
61
|
-
|
|
62
|
-
return payload.event === 'configure';
|
|
63
|
-
}
|
|
64
|
-
const emptyModels = new Proxy({}, {
|
|
66
|
+
const emptyProperty = new Proxy({}, {
|
|
65
67
|
get() {
|
|
66
|
-
throw new Error('
|
|
68
|
+
throw new Error('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.');
|
|
67
69
|
},
|
|
68
70
|
});
|
|
69
71
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateClient.mjs","sources":["../../../src/internals/generateClient.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { graphql, cancel, isCancelError } from './v6';\nimport { generateModelsProperty } from './generateModelsProperty';\nimport { __amplify, __authMode, __authToken, __headers, } from '../types';\nimport {
|
|
1
|
+
{"version":3,"file":"generateClient.mjs","sources":["../../../src/internals/generateClient.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { Hub } from '@aws-amplify/core';\nimport { graphql, cancel, isCancelError } from './v6';\nimport { generateEnumsProperty } from './utils/generateEnumsProperty';\nimport { generateModelsProperty } from './utils/generateModelsProperty';\nimport { isApiGraphQLConfig } from './utils/isApiGraphQLProviderConfig';\nimport { __amplify, __authMode, __authToken, __headers, } from '../types';\nimport { isConfigureEventWithResourceConfig } from './utils/isConfigureEventWithResourceConfig';\n/**\n * @private\n *\n * Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`\n * compatible context object for config and auth fetching.\n *\n * @param params\n * @returns\n */\nexport function generateClient(params) {\n const client = {\n [__amplify]: params.amplify,\n [__authMode]: params.authMode,\n [__authToken]: params.authToken,\n [__headers]: params.headers,\n graphql,\n cancel,\n isCancelError,\n models: emptyProperty,\n enums: emptyProperty,\n };\n const apiGraphqlConfig = params.amplify.getConfig().API?.GraphQL;\n if (isApiGraphQLConfig(apiGraphqlConfig)) {\n client.models = generateModelsProperty(client, apiGraphqlConfig);\n client.enums = generateEnumsProperty(apiGraphqlConfig);\n }\n else {\n // This happens when the `Amplify.configure()` call gets evaluated after the `generateClient()` call.\n //\n // Cause: when the `generateClient()` and the `Amplify.configure()` calls are located in\n // different source files, script bundlers may randomly arrange their orders in the production\n // bundle.\n //\n // With the current implementation, the `client.models` instance created by `generateClient()`\n // will be rebuilt on every `Amplify.configure()` call that's provided with a valid GraphQL\n // provider configuration.\n //\n // TODO: revisit, and reverify this approach when enabling multiple clients for multi-endpoints\n // configuration.\n generateModelsPropertyOnAmplifyConfigure(client);\n }\n return client;\n}\nconst generateModelsPropertyOnAmplifyConfigure = (clientRef) => {\n Hub.listen('core', coreEvent => {\n if (!isConfigureEventWithResourceConfig(coreEvent.payload)) {\n return;\n }\n const apiGraphQLConfig = coreEvent.payload.data.API?.GraphQL;\n if (isApiGraphQLConfig(apiGraphQLConfig)) {\n clientRef.models = generateModelsProperty(clientRef, apiGraphQLConfig);\n clientRef.enums = generateEnumsProperty(apiGraphQLConfig);\n }\n });\n};\nconst emptyProperty = new Proxy({}, {\n get() {\n throw new Error('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.');\n },\n});\n"],"names":[],"mappings":";;;;;;;;AAAA;AACA;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,cAAc,CAAC,MAAM,EAAE;AACvC,IAAI,MAAM,MAAM,GAAG;AACnB,QAAQ,CAAC,SAAS,GAAG,MAAM,CAAC,OAAO;AACnC,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC,QAAQ;AACrC,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,SAAS;AACvC,QAAQ,CAAC,SAAS,GAAG,MAAM,CAAC,OAAO;AACnC,QAAQ,OAAO;AACf,QAAQ,MAAM;AACd,QAAQ,aAAa;AACrB,QAAQ,MAAM,EAAE,aAAa;AAC7B,QAAQ,KAAK,EAAE,aAAa;AAC5B,KAAK,CAAC;AACN,IAAI,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC;AACrE,IAAI,IAAI,kBAAkB,CAAC,gBAAgB,CAAC,EAAE;AAC9C,QAAQ,MAAM,CAAC,MAAM,GAAG,sBAAsB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AACzE,QAAQ,MAAM,CAAC,KAAK,GAAG,qBAAqB,CAAC,gBAAgB,CAAC,CAAC;AAC/D,KAAK;AACL,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ,wCAAwC,CAAC,MAAM,CAAC,CAAC;AACzD,KAAK;AACL,IAAI,OAAO,MAAM,CAAC;AAClB,CAAC;AACD,MAAM,wCAAwC,GAAG,CAAC,SAAS,KAAK;AAChE,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,IAAI;AACpC,QAAQ,IAAI,CAAC,kCAAkC,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;AACpE,YAAY,OAAO;AACnB,SAAS;AACT,QAAQ,MAAM,gBAAgB,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC;AACrE,QAAQ,IAAI,kBAAkB,CAAC,gBAAgB,CAAC,EAAE;AAClD,YAAY,SAAS,CAAC,MAAM,GAAG,sBAAsB,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;AACnF,YAAY,SAAS,CAAC,KAAK,GAAG,qBAAqB,CAAC,gBAAgB,CAAC,CAAC;AACtE,SAAS;AACT,KAAK,CAAC,CAAC;AACP,CAAC,CAAC;AACF,MAAM,aAAa,GAAG,IAAI,KAAK,CAAC,EAAE,EAAE;AACpC,IAAI,GAAG,GAAG;AACV,QAAQ,MAAM,IAAI,KAAK,CAAC,iOAAiO,CAAC,CAAC;AAC3P,KAAK;AACL,CAAC,CAAC;;;;"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { GraphQLProviderConfig } from '@aws-amplify/core/internals/utils';
|
|
2
|
+
import { EnumTypes } from '@aws-amplify/data-schema-types';
|
|
3
|
+
export declare const generateEnumsProperty: <T extends Record<any, any> = never>(graphqlConfig: GraphQLProviderConfig['GraphQL']) => EnumTypes<T>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
const generateEnumsProperty = (graphqlConfig) => {
|
|
4
|
+
const modelIntrospection = graphqlConfig.modelIntrospection;
|
|
5
|
+
if (!modelIntrospection) {
|
|
6
|
+
return {};
|
|
7
|
+
}
|
|
8
|
+
const enums = {};
|
|
9
|
+
for (const [_, enumData] of Object.entries(modelIntrospection.enums)) {
|
|
10
|
+
enums[enumData.name] = {
|
|
11
|
+
values: () => enumData.values,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
return enums;
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export { generateEnumsProperty };
|
|
18
|
+
//# sourceMappingURL=generateEnumsProperty.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateEnumsProperty.mjs","sources":["../../../../src/internals/utils/generateEnumsProperty.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport const generateEnumsProperty = (graphqlConfig) => {\n const modelIntrospection = graphqlConfig.modelIntrospection;\n if (!modelIntrospection) {\n return {};\n }\n const enums = {};\n for (const [_, enumData] of Object.entries(modelIntrospection.enums)) {\n enums[enumData.name] = {\n values: () => enumData.values,\n };\n }\n return enums;\n};\n"],"names":[],"mappings":"AAAA;AACA;AACY,MAAC,qBAAqB,GAAG,CAAC,aAAa,KAAK;AACxD,IAAI,MAAM,kBAAkB,GAAG,aAAa,CAAC,kBAAkB,CAAC;AAChE,IAAI,IAAI,CAAC,kBAAkB,EAAE;AAC7B,QAAQ,OAAO,EAAE,CAAC;AAClB,KAAK;AACL,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;AACrB,IAAI,KAAK,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,kBAAkB,CAAC,KAAK,CAAC,EAAE;AAC1E,QAAQ,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG;AAC/B,YAAY,MAAM,EAAE,MAAM,QAAQ,CAAC,MAAM;AACzC,SAAS,CAAC;AACV,KAAK;AACL,IAAI,OAAO,KAAK,CAAC;AACjB;;;;"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ModelTypes } from '@aws-amplify/data-schema-types';
|
|
2
|
+
import { V6Client } from '../../types';
|
|
3
|
+
import { GraphQLProviderConfig } from '@aws-amplify/core/internals/utils';
|
|
4
|
+
export declare function generateModelsProperty<T extends Record<any, any> = never>(client: V6Client<Record<string, any>>, apiGraphQLConfig: GraphQLProviderConfig['GraphQL']): ModelTypes<T>;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { graphQLOperationsInfo } from '
|
|
2
|
-
import { listFactory } from '
|
|
3
|
-
import { indexQueryFactory } from '
|
|
4
|
-
import { getFactory } from '
|
|
5
|
-
import { subscriptionFactory } from '
|
|
6
|
-
import { observeQueryFactory } from '
|
|
7
|
-
import { getSecondaryIndexesFromSchemaModel } from '
|
|
1
|
+
import { graphQLOperationsInfo } from '../APIClient.mjs';
|
|
2
|
+
import { listFactory } from '../operations/list.mjs';
|
|
3
|
+
import { indexQueryFactory } from '../operations/indexQuery.mjs';
|
|
4
|
+
import { getFactory } from '../operations/get.mjs';
|
|
5
|
+
import { subscriptionFactory } from '../operations/subscription.mjs';
|
|
6
|
+
import { observeQueryFactory } from '../operations/observeQuery.mjs';
|
|
7
|
+
import { getSecondaryIndexesFromSchemaModel } from '../clientUtils.mjs';
|
|
8
8
|
|
|
9
|
-
function generateModelsProperty(client,
|
|
9
|
+
function generateModelsProperty(client, apiGraphQLConfig) {
|
|
10
10
|
const models = {};
|
|
11
|
-
const modelIntrospection =
|
|
11
|
+
const modelIntrospection = apiGraphQLConfig.modelIntrospection;
|
|
12
12
|
if (!modelIntrospection) {
|
|
13
13
|
return {};
|
|
14
14
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateModelsProperty.mjs","sources":["../../../../src/internals/utils/generateModelsProperty.ts"],"sourcesContent":["import { graphQLOperationsInfo } from '../APIClient';\nimport { listFactory } from '../operations/list';\nimport { indexQueryFactory } from '../operations/indexQuery';\nimport { getFactory } from '../operations/get';\nimport { subscriptionFactory } from '../operations/subscription';\nimport { observeQueryFactory } from '../operations/observeQuery';\nimport { getSecondaryIndexesFromSchemaModel } from '../clientUtils';\nexport function generateModelsProperty(client, apiGraphQLConfig) {\n const models = {};\n const modelIntrospection = apiGraphQLConfig.modelIntrospection;\n if (!modelIntrospection) {\n return {};\n }\n const SUBSCRIPTION_OPS = ['ONCREATE', 'ONUPDATE', 'ONDELETE'];\n for (const model of Object.values(modelIntrospection.models)) {\n const { name } = model;\n models[name] = {};\n Object.entries(graphQLOperationsInfo).forEach(([key, { operationPrefix }]) => {\n const operation = key;\n if (operation === 'LIST') {\n models[name][operationPrefix] = listFactory(client, modelIntrospection, model);\n }\n else if (SUBSCRIPTION_OPS.includes(operation)) {\n models[name][operationPrefix] = subscriptionFactory(client, modelIntrospection, model, operation);\n }\n else if (operation === 'OBSERVE_QUERY') {\n models[name][operationPrefix] = observeQueryFactory(models, model);\n }\n else {\n models[name][operationPrefix] = getFactory(client, modelIntrospection, model, operation);\n }\n });\n const secondaryIdxs = getSecondaryIndexesFromSchemaModel(model);\n for (const idx of secondaryIdxs) {\n models[name][idx.queryField] = indexQueryFactory(client, modelIntrospection, model, idx);\n }\n }\n return models;\n}\n"],"names":[],"mappings":";;;;;;;;AAOO,SAAS,sBAAsB,CAAC,MAAM,EAAE,gBAAgB,EAAE;AACjE,IAAI,MAAM,MAAM,GAAG,EAAE,CAAC;AACtB,IAAI,MAAM,kBAAkB,GAAG,gBAAgB,CAAC,kBAAkB,CAAC;AACnE,IAAI,IAAI,CAAC,kBAAkB,EAAE;AAC7B,QAAQ,OAAO,EAAE,CAAC;AAClB,KAAK;AACL,IAAI,MAAM,gBAAgB,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;AAClE,IAAI,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,MAAM,CAAC,EAAE;AAClE,QAAQ,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;AAC/B,QAAQ,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC;AAC1B,QAAQ,MAAM,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,GAAG,EAAE,EAAE,eAAe,EAAE,CAAC,KAAK;AACtF,YAAY,MAAM,SAAS,GAAG,GAAG,CAAC;AAClC,YAAY,IAAI,SAAS,KAAK,MAAM,EAAE;AACtC,gBAAgB,MAAM,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,CAAC,CAAC;AAC/F,aAAa;AACb,iBAAiB,IAAI,gBAAgB,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;AAC3D,gBAAgB,MAAM,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,GAAG,mBAAmB,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;AAClH,aAAa;AACb,iBAAiB,IAAI,SAAS,KAAK,eAAe,EAAE;AACpD,gBAAgB,MAAM,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,GAAG,mBAAmB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AACnF,aAAa;AACb,iBAAiB;AACjB,gBAAgB,MAAM,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,GAAG,UAAU,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;AACzG,aAAa;AACb,SAAS,CAAC,CAAC;AACX,QAAQ,MAAM,aAAa,GAAG,kCAAkC,CAAC,KAAK,CAAC,CAAC;AACxE,QAAQ,KAAK,MAAM,GAAG,IAAI,aAAa,EAAE;AACzC,YAAY,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,iBAAiB,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;AACrG,SAAS;AACT,KAAK;AACL,IAAI,OAAO,MAAM,CAAC;AAClB;;;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
function isApiGraphQLConfig(apiGraphQLConfig) {
|
|
4
|
+
return apiGraphQLConfig !== undefined;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export { isApiGraphQLConfig };
|
|
8
|
+
//# sourceMappingURL=isApiGraphQLProviderConfig.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"isApiGraphQLProviderConfig.mjs","sources":["../../../../src/internals/utils/isApiGraphQLProviderConfig.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nexport function isApiGraphQLConfig(apiGraphQLConfig) {\n return apiGraphQLConfig !== undefined;\n}\n"],"names":[],"mappings":"AAAA;AACA;AACO,SAAS,kBAAkB,CAAC,gBAAgB,EAAE;AACrD,IAAI,OAAO,gBAAgB,KAAK,SAAS,CAAC;AAC1C;;;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { HubCapsule, ResourcesConfig } from '@aws-amplify/core';
|
|
2
|
+
export declare function isConfigureEventWithResourceConfig(payload: HubCapsule<'core', {
|
|
3
|
+
event: string;
|
|
4
|
+
data?: unknown;
|
|
5
|
+
}>['payload']): payload is {
|
|
6
|
+
event: 'configure';
|
|
7
|
+
data: ResourcesConfig;
|
|
8
|
+
};
|
|
@@ -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;;;;"}
|
|
@@ -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;
|
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.5c56101.0+5c56101",
|
|
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.5c56101.0+5c56101",
|
|
88
|
+
"@aws-amplify/core": "6.0.17-unstable.5c56101.0+5c56101",
|
|
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": "5c561018aedcff314e68b3dd385fe9bd9ff93150"
|
|
105
105
|
}
|
|
@@ -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
|
},
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
ModelIntrospectionSchema,
|
|
6
|
+
GraphQLProviderConfig,
|
|
7
|
+
} from '@aws-amplify/core/internals/utils';
|
|
8
|
+
import { EnumTypes } from '@aws-amplify/data-schema-types';
|
|
9
|
+
|
|
10
|
+
export const generateEnumsProperty = <T extends Record<any, any> = never>(
|
|
11
|
+
graphqlConfig: GraphQLProviderConfig['GraphQL'],
|
|
12
|
+
): EnumTypes<T> => {
|
|
13
|
+
const modelIntrospection: ModelIntrospectionSchema | undefined =
|
|
14
|
+
graphqlConfig.modelIntrospection;
|
|
15
|
+
|
|
16
|
+
if (!modelIntrospection) {
|
|
17
|
+
return {} as EnumTypes<never>;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const enums: {
|
|
21
|
+
[EnumName: string]: {
|
|
22
|
+
values: () => string[];
|
|
23
|
+
};
|
|
24
|
+
} = {};
|
|
25
|
+
|
|
26
|
+
for (const [_, enumData] of Object.entries(modelIntrospection.enums)) {
|
|
27
|
+
enums[enumData.name] = {
|
|
28
|
+
values: () => enumData.values,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return enums as EnumTypes<T>;
|
|
33
|
+
};
|
|
@@ -1,25 +1,27 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { ModelTypes } from '@aws-amplify/data-schema-types';
|
|
4
|
-
import { graphQLOperationsInfo, ModelOperation } from '
|
|
5
|
-
import { V6Client, __authMode, __authToken } from '
|
|
6
|
-
import { listFactory } from '
|
|
7
|
-
import { indexQueryFactory } from '
|
|
8
|
-
import { getFactory } from '
|
|
9
|
-
import { subscriptionFactory } from '
|
|
10
|
-
import { observeQueryFactory } from '
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
4
|
+
import { graphQLOperationsInfo, ModelOperation } from '../APIClient';
|
|
5
|
+
import { V6Client, __authMode, __authToken } from '../../types';
|
|
6
|
+
import { listFactory } from '../operations/list';
|
|
7
|
+
import { indexQueryFactory } from '../operations/indexQuery';
|
|
8
|
+
import { getFactory } from '../operations/get';
|
|
9
|
+
import { subscriptionFactory } from '../operations/subscription';
|
|
10
|
+
import { observeQueryFactory } from '../operations/observeQuery';
|
|
11
|
+
import {
|
|
12
|
+
ModelIntrospectionSchema,
|
|
13
|
+
GraphQLProviderConfig,
|
|
14
|
+
} from '@aws-amplify/core/internals/utils';
|
|
15
|
+
import { getSecondaryIndexesFromSchemaModel } from '../clientUtils';
|
|
14
16
|
|
|
15
17
|
export function generateModelsProperty<T extends Record<any, any> = never>(
|
|
16
18
|
client: V6Client<Record<string, any>>,
|
|
17
|
-
|
|
19
|
+
apiGraphQLConfig: GraphQLProviderConfig['GraphQL'],
|
|
18
20
|
): ModelTypes<T> {
|
|
19
21
|
const models = {} as any;
|
|
20
22
|
|
|
21
23
|
const modelIntrospection: ModelIntrospectionSchema | undefined =
|
|
22
|
-
|
|
24
|
+
apiGraphQLConfig.modelIntrospection;
|
|
23
25
|
|
|
24
26
|
if (!modelIntrospection) {
|
|
25
27
|
return {} as ModelTypes<never>;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import { GraphQLProviderConfig } from '@aws-amplify/core/internals/utils';
|
|
5
|
+
|
|
6
|
+
export function isApiGraphQLConfig(
|
|
7
|
+
apiGraphQLConfig: GraphQLProviderConfig['GraphQL'] | undefined,
|
|
8
|
+
): apiGraphQLConfig is GraphQLProviderConfig['GraphQL'] {
|
|
9
|
+
return apiGraphQLConfig !== undefined;
|
|
10
|
+
}
|
|
@@ -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 { HubCapsule, ResourcesConfig } from '@aws-amplify/core';
|
|
5
|
+
|
|
6
|
+
export function isConfigureEventWithResourceConfig(
|
|
7
|
+
payload: HubCapsule<'core', { event: string; data?: unknown }>['payload'],
|
|
8
|
+
): payload is {
|
|
9
|
+
event: 'configure';
|
|
10
|
+
data: ResourcesConfig;
|
|
11
|
+
} {
|
|
12
|
+
return payload.event === 'configure';
|
|
13
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -1,7 +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 { AmplifyClassV6, ResourcesConfig } from '@aws-amplify/core';
|
|
4
|
-
import { ModelTypes, CustomHeaders } from '@aws-amplify/data-schema-types';
|
|
4
|
+
import { ModelTypes, CustomHeaders, EnumTypes } from '@aws-amplify/data-schema-types';
|
|
5
5
|
import { Source, DocumentNode, GraphQLError } from 'graphql';
|
|
6
6
|
export { OperationTypeNode } from 'graphql';
|
|
7
7
|
import { Observable } from 'rxjs';
|
|
@@ -382,6 +382,7 @@ export type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
|
|
|
382
382
|
cancel: (promise: Promise<any>, message?: string) => boolean;
|
|
383
383
|
isCancelError: (error: any) => boolean;
|
|
384
384
|
models: ModelTypes<T>;
|
|
385
|
+
enums: EnumTypes<T>;
|
|
385
386
|
}>;
|
|
386
387
|
|
|
387
388
|
export type V6ClientSSRRequest<T extends Record<any, any> = never> =
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateModelsProperty.js","sources":["../../../src/internals/generateModelsProperty.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.generateModelsProperty = void 0;\nconst APIClient_1 = require(\"./APIClient\");\nconst list_1 = require(\"./operations/list\");\nconst indexQuery_1 = require(\"./operations/indexQuery\");\nconst get_1 = require(\"./operations/get\");\nconst subscription_1 = require(\"./operations/subscription\");\nconst observeQuery_1 = require(\"./operations/observeQuery\");\nconst clientUtils_1 = require(\"./clientUtils\");\nfunction generateModelsProperty(client, graphqlConfig) {\n const models = {};\n const modelIntrospection = graphqlConfig.modelIntrospection;\n if (!modelIntrospection) {\n return {};\n }\n const SUBSCRIPTION_OPS = ['ONCREATE', 'ONUPDATE', 'ONDELETE'];\n for (const model of Object.values(modelIntrospection.models)) {\n const { name } = model;\n models[name] = {};\n Object.entries(APIClient_1.graphQLOperationsInfo).forEach(([key, { operationPrefix }]) => {\n const operation = key;\n if (operation === 'LIST') {\n models[name][operationPrefix] = (0, list_1.listFactory)(client, modelIntrospection, model);\n }\n else if (SUBSCRIPTION_OPS.includes(operation)) {\n models[name][operationPrefix] = (0, subscription_1.subscriptionFactory)(client, modelIntrospection, model, operation);\n }\n else if (operation === 'OBSERVE_QUERY') {\n models[name][operationPrefix] = (0, observeQuery_1.observeQueryFactory)(models, model);\n }\n else {\n models[name][operationPrefix] = (0, get_1.getFactory)(client, modelIntrospection, model, operation);\n }\n });\n const secondaryIdxs = (0, clientUtils_1.getSecondaryIndexesFromSchemaModel)(model);\n for (const idx of secondaryIdxs) {\n models[name][idx.queryField] = (0, indexQuery_1.indexQueryFactory)(client, modelIntrospection, model, idx);\n }\n }\n return models;\n}\nexports.generateModelsProperty = generateModelsProperty;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,sBAAsB,GAAG,KAAK,CAAC,CAAC;AACxC,MAAM,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAC3C,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,YAAY,GAAG,OAAO,CAAC,yBAAyB,CAAC,CAAC;AACxD,MAAM,KAAK,GAAG,OA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,CAAC,mBAAmB,EAAE,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;AACtI,aAAa;AACb,iBAAiB,IAAI,SAAS,KAAK,eAAe,EAAE;AACpD,gBAAgB,MAAM,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,GAAG,IAAI,cAAc,CAAC,mBAAmB,EAAE,MAAM,EAAE,KAAK,CAAC,CAAC;AACvG,aAAa;AACb,iBAAiB;AACjB,gBAAgB,MAAM,CAAC,IAAI,CAAC,CAAC,eAAe,CAAC,GAAG,IAAI,KAAK,CAAC,UAAU,EAAE,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC;AACpH,aAAa;AACb,SAAS,CAAC,CAAC;AACX,QAAQ,MAAM,aAAa,GAAG,IAAI,aAAa,CAAC,kCAAkC,EAAE,KAAK,CAAC,CAAC;AAC3F,QAAQ,KAAK,MAAM,GAAG,IAAI,aAAa,EAAE;AACzC,YAAY,MAAM,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC,GAAG,IAAI,YAAY,CAAC,iBAAiB,EAAE,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG,CAAC,CAAC;AACvH,SAAS;AACT,KAAK;AACL,IAAI,OAAO,MAAM,CAAC;AAClB,CAAC;AACD,OAAO,CAAC,sBAAsB,GAAG,sBAAsB;;"}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { ModelTypes } from '@aws-amplify/data-schema-types';
|
|
2
|
-
import { V6Client } from '../types';
|
|
3
|
-
import { GraphQLProviderConfig } from '@aws-amplify/core';
|
|
4
|
-
export declare function generateModelsProperty<T extends Record<any, any> = never>(client: V6Client<Record<string, any>>, graphqlConfig: GraphQLProviderConfig['GraphQL']): ModelTypes<T>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateModelsProperty.mjs","sources":["../../../src/internals/generateModelsProperty.ts"],"sourcesContent":["import { graphQLOperationsInfo } from './APIClient';\nimport { listFactory } from './operations/list';\nimport { indexQueryFactory } from './operations/indexQuery';\nimport { getFactory } from './operations/get';\nimport { subscriptionFactory } from './operations/subscription';\nimport { observeQueryFactory } from './operations/observeQuery';\nimport { getSecondaryIndexesFromSchemaModel } from './clientUtils';\nexport function generateModelsProperty(client, graphqlConfig) {\n const models = {};\n const modelIntrospection = graphqlConfig.modelIntrospection;\n if (!modelIntrospection) {\n return {};\n }\n const SUBSCRIPTION_OPS = ['ONCREATE', 'ONUPDATE', 'ONDELETE'];\n for (const model of Object.values(modelIntrospection.models)) {\n const { name } = model;\n models[name] = {};\n Object.entries(graphQLOperationsInfo).forEach(([key, { operationPrefix }]) => {\n const operation = key;\n if (operation === 'LIST') {\n models[name][operationPrefix] = listFactory(client, modelIntrospection, model);\n }\n else if (SUBSCRIPTION_OPS.includes(operation)) {\n models[name][operationPrefix] = subscriptionFactory(client, modelIntrospection, model, operation);\n }\n else if (operation === 'OBSERVE_QUERY') {\n models[name][operationPrefix] = observeQueryFactory(models, model);\n }\n else {\n models[name][operationPrefix] = getFactory(client, modelIntrospection, model, operation);\n }\n });\n const secondaryIdxs = getSecondaryIndexesFromSchemaModel(model);\n for (const idx of secondaryIdxs) {\n models[name][idx.queryField] = indexQueryFactory(client, modelIntrospection, model, idx);\n }\n }\n return models;\n}\n"],"names":[],"mappings":";;;;;;;;AAOO,SAAS,sBAAsB,CAAC,MAAM,EAAE,aAAa,EAAE;AAC9D,IAAI,MAAM,MAAM,GAAG,EAAE,CAAC;AACtB,IAAI,MAAM,kBAAkB,GAAG,aAAa,CAAC,kBAAkB,CAAC;AAChE,IAAI,IAAI,CAAC,kBAAkB,EAAE;AAC7B,QAAQ,OAAO,EAAE,CAAC;AAClB,KAAK;AACL,IAAI,MAAM,gBAAgB,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;AAClE,IAAI,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,k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