@aws-amplify/api-graphql 4.0.22-unstable.1aafa48.0 → 4.0.22-unstable.2b71e29.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 +3 -0
- package/dist/cjs/internals/generateClient.js.map +1 -1
- package/dist/cjs/internals/generateCustomOperationsProperty.js +6 -1
- package/dist/cjs/internals/generateCustomOperationsProperty.js.map +1 -1
- package/dist/cjs/internals/operations/custom.js +88 -5
- package/dist/cjs/internals/operations/custom.js.map +1 -1
- package/dist/esm/internals/generateClient.mjs +4 -1
- package/dist/esm/internals/generateClient.mjs.map +1 -1
- package/dist/esm/internals/generateCustomOperationsProperty.d.ts +2 -1
- package/dist/esm/internals/generateCustomOperationsProperty.mjs +5 -1
- package/dist/esm/internals/generateCustomOperationsProperty.mjs.map +1 -1
- package/dist/esm/internals/operations/custom.d.ts +5 -2
- package/dist/esm/internals/operations/custom.mjs +88 -5
- package/dist/esm/internals/operations/custom.mjs.map +1 -1
- package/dist/esm/internals/server/generateModelsProperty.d.ts +2 -1
- package/dist/esm/internals/utils/clientProperties/generateModelsProperty.d.ts +1 -1
- package/dist/esm/types/index.d.ts +2 -1
- package/package.json +6 -6
- package/src/internals/APIClient.ts +24 -31
- package/src/internals/generateClient.ts +11 -0
- package/src/internals/generateCustomOperationsProperty.ts +25 -3
- package/src/internals/operations/custom.ts +143 -19
- package/src/internals/server/generateModelsProperty.ts +5 -2
- package/src/internals/utils/clientProperties/generateModelsProperty.ts +1 -1
- package/src/types/index.ts +2 -0
|
@@ -34,6 +34,7 @@ function generateClient(params) {
|
|
|
34
34
|
enums: emptyProperty,
|
|
35
35
|
queries: emptyProperty,
|
|
36
36
|
mutations: emptyProperty,
|
|
37
|
+
subscriptions: emptyProperty,
|
|
37
38
|
};
|
|
38
39
|
const apiGraphqlConfig = params.amplify.getConfig().API?.GraphQL;
|
|
39
40
|
if ((0, isApiGraphQLProviderConfig_1.isApiGraphQLConfig)(apiGraphqlConfig)) {
|
|
@@ -41,6 +42,7 @@ function generateClient(params) {
|
|
|
41
42
|
client.enums = (0, generateEnumsProperty_1.generateEnumsProperty)(apiGraphqlConfig);
|
|
42
43
|
client.queries = (0, generateCustomOperationsProperty_1.generateCustomQueriesProperty)(client, apiGraphqlConfig);
|
|
43
44
|
client.mutations = (0, generateCustomOperationsProperty_1.generateCustomMutationsProperty)(client, apiGraphqlConfig);
|
|
45
|
+
client.subscriptions = (0, generateCustomOperationsProperty_1.generateCustomSubscriptionsProperty)(client, apiGraphqlConfig);
|
|
44
46
|
}
|
|
45
47
|
else {
|
|
46
48
|
// This happens when the `Amplify.configure()` call gets evaluated after the `generateClient()` call.
|
|
@@ -71,6 +73,7 @@ const generateModelsPropertyOnAmplifyConfigure = (clientRef) => {
|
|
|
71
73
|
clientRef.enums = (0, generateEnumsProperty_1.generateEnumsProperty)(apiGraphQLConfig);
|
|
72
74
|
clientRef.queries = (0, generateCustomOperationsProperty_1.generateCustomQueriesProperty)(clientRef, apiGraphQLConfig);
|
|
73
75
|
clientRef.mutations = (0, generateCustomOperationsProperty_1.generateCustomMutationsProperty)(clientRef, apiGraphQLConfig);
|
|
76
|
+
clientRef.subscriptions = (0, generateCustomOperationsProperty_1.generateCustomSubscriptionsProperty)(clientRef, apiGraphQLConfig);
|
|
74
77
|
}
|
|
75
78
|
});
|
|
76
79
|
};
|
|
@@ -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 core_1 = require(\"@aws-amplify/core\");\nconst types_1 = require(\"../types\");\nconst v6_1 = require(\"./v6\");\nconst generateEnumsProperty_1 = require(\"./utils/clientProperties/generateEnumsProperty\");\nconst generateModelsProperty_1 = require(\"./utils/clientProperties/generateModelsProperty\");\nconst isApiGraphQLProviderConfig_1 = require(\"./utils/runtimeTypeGuards/isApiGraphQLProviderConfig\");\nconst generateCustomOperationsProperty_1 = require(\"./generateCustomOperationsProperty\");\nconst isConfigureEventWithResourceConfig_1 = require(\"./utils/runtimeTypeGuards/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 queries: emptyProperty,\n mutations: 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 client.queries = (0, generateCustomOperationsProperty_1.generateCustomQueriesProperty)(client, apiGraphqlConfig);\n client.mutations = (0, generateCustomOperationsProperty_1.generateCustomMutationsProperty)(client, 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 clientRef.queries = (0, generateCustomOperationsProperty_1.generateCustomQueriesProperty)(clientRef, apiGraphQLConfig);\n clientRef.mutations = (0, generateCustomOperationsProperty_1.generateCustomMutationsProperty)(clientRef, 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":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,cAAc,GAAG,KAAK,CAAC,CAAC;AAChC;AACA;AACA,MAAM,MAAM,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACpC,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC7B,MAAM,uBAAuB,GAAG,OAAO,CAAC,gDAAgD,CAAC,CAAC;AAC1F,MAAM,wBAAwB,GAAG,OAAO,CAAC,iDAAiD,CAAC,CAAC;AAC5F,MAAM,4BAA4B,GAAG,OAAO,CAAC,sDAAsD,CAAC,CAAC;AACrG,MAAM,kCAAkC,GAAG,OAAO,CAAC,oCAAoC,CAAC,CAAC;AACzF,MAAM,oCAAoC,GAAG,OAA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C3P,KAAK;AACL,CAAC,CAAC;;"}
|
|
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 types_1 = require(\"../types\");\nconst v6_1 = require(\"./v6\");\nconst generateEnumsProperty_1 = require(\"./utils/clientProperties/generateEnumsProperty\");\nconst generateModelsProperty_1 = require(\"./utils/clientProperties/generateModelsProperty\");\nconst isApiGraphQLProviderConfig_1 = require(\"./utils/runtimeTypeGuards/isApiGraphQLProviderConfig\");\nconst generateCustomOperationsProperty_1 = require(\"./generateCustomOperationsProperty\");\nconst isConfigureEventWithResourceConfig_1 = require(\"./utils/runtimeTypeGuards/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 queries: emptyProperty,\n mutations: emptyProperty,\n subscriptions: 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 client.queries = (0, generateCustomOperationsProperty_1.generateCustomQueriesProperty)(client, apiGraphqlConfig);\n client.mutations = (0, generateCustomOperationsProperty_1.generateCustomMutationsProperty)(client, apiGraphqlConfig);\n client.subscriptions = (0, generateCustomOperationsProperty_1.generateCustomSubscriptionsProperty)(client, 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 clientRef.queries = (0, generateCustomOperationsProperty_1.generateCustomQueriesProperty)(clientRef, apiGraphQLConfig);\n clientRef.mutations = (0, generateCustomOperationsProperty_1.generateCustomMutationsProperty)(clientRef, apiGraphQLConfig);\n clientRef.subscriptions = (0, generateCustomOperationsProperty_1.generateCustomSubscriptionsProperty)(clientRef, 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":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE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AO,CAAC;AACrE,QAAQ,IAAI,IAAI,4BAA4B,CAAC,kBAAkB,EAAE,gBAAgB,CAAC,EAAE;AACpF,YAAY,SAAS,CAAC,MAAM,GAAG,IAAI,wBAAwB,CAAC,sBAAsB,EAAE,SAAS,EAAE,gBAAgB,CAAC,CAAC;AACjH,YAAY,SAAS,CAAC,KAAK,GAAG,IAAI,uBAAuB,CAAC,qBAAqB,EAAE,gBAAgB,CAAC,CAAC;AACnG,YAAY,SAAS,CAAC,OAAO,GAAG,IAAI,kCAAkC,CAAC,6BAA6B,EAAE,SAAS,EAAE,gBAAgB,CAAC,CAAC;AACnI,YAAY,SAAS,CAAC,SAAS,GAAG,IAAI,kCAAkC,CAAC,+BAA+B,EAAE,SAAS,EAAE,gBAAgB,CAAC,CAAC;AACvI,YAAY,SAAS,CAAC,aAAa,GAAG,IAAI,kCAAkC,CAAC,mCAAmC,EAAE,SAAS,EAAE,gBAAgB,CAAC,CAAC;AAC/I,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;;"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.generateCustomQueriesProperty = exports.generateCustomMutationsProperty = exports.generateCustomOperationsProperty = void 0;
|
|
4
|
+
exports.generateCustomSubscriptionsProperty = exports.generateCustomQueriesProperty = exports.generateCustomMutationsProperty = exports.generateCustomOperationsProperty = void 0;
|
|
5
5
|
const types_1 = require("../types");
|
|
6
6
|
const custom_1 = require("./operations/custom");
|
|
7
7
|
const operationTypeMap = {
|
|
8
8
|
queries: 'query',
|
|
9
9
|
mutations: 'mutation',
|
|
10
|
+
subscriptions: 'subscription',
|
|
10
11
|
};
|
|
11
12
|
function generateCustomOperationsProperty(client, config, operationsType) {
|
|
12
13
|
// some bundlers end up with `Amplify.configure` being called *after* generate client.
|
|
@@ -42,4 +43,8 @@ function generateCustomQueriesProperty(client, config) {
|
|
|
42
43
|
return generateCustomOperationsProperty(client, config, 'queries');
|
|
43
44
|
}
|
|
44
45
|
exports.generateCustomQueriesProperty = generateCustomQueriesProperty;
|
|
46
|
+
function generateCustomSubscriptionsProperty(client, config) {
|
|
47
|
+
return generateCustomOperationsProperty(client, config, 'subscriptions');
|
|
48
|
+
}
|
|
49
|
+
exports.generateCustomSubscriptionsProperty = generateCustomSubscriptionsProperty;
|
|
45
50
|
//# sourceMappingURL=generateCustomOperationsProperty.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateCustomOperationsProperty.js","sources":["../../../src/internals/generateCustomOperationsProperty.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.generateCustomQueriesProperty = exports.generateCustomMutationsProperty = exports.generateCustomOperationsProperty = void 0;\nconst types_1 = require(\"../types\");\nconst custom_1 = require(\"./operations/custom\");\nconst operationTypeMap = {\n queries: 'query',\n mutations: 'mutation',\n};\nfunction generateCustomOperationsProperty(client, config, operationsType) {\n // some bundlers end up with `Amplify.configure` being called *after* generate client.\n // if that occurs, we need to *not error* while we wait. handling for late configuration\n // occurs in `generateClient()`. we do not need to subscribe to Hub events here.\n if (!config) {\n return {};\n }\n const modelIntrospection = config.modelIntrospection;\n // model intro schema might be absent if there's not actually a configured GraphQL API\n if (!modelIntrospection) {\n return {};\n }\n // custom operations will be absent from model intro schema if no custom ops\n // are present on the source schema.\n const operations = modelIntrospection[operationsType];\n if (!operations) {\n return {};\n }\n const ops = {};\n const useContext = client[types_1.__amplify] === null;\n for (const operation of Object.values(operations)) {\n ops[operation.name] = (0, custom_1.customOpFactory)(client, modelIntrospection, operationTypeMap[operationsType], operation, useContext);\n }\n return ops;\n}\nexports.generateCustomOperationsProperty = generateCustomOperationsProperty;\nfunction generateCustomMutationsProperty(client, config) {\n return generateCustomOperationsProperty(client, config, 'mutations');\n}\nexports.generateCustomMutationsProperty = generateCustomMutationsProperty;\nfunction generateCustomQueriesProperty(client, config) {\n return generateCustomOperationsProperty(client, config, 'queries');\n}\nexports.generateCustomQueriesProperty = generateCustomQueriesProperty;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,6BAA6B,GAAG,OAAO,CAAC,+BAA+B,GAAG,OAAO,CAAC,gCAAgC,GAAG,KAAK,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"generateCustomOperationsProperty.js","sources":["../../../src/internals/generateCustomOperationsProperty.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.generateCustomSubscriptionsProperty = exports.generateCustomQueriesProperty = exports.generateCustomMutationsProperty = exports.generateCustomOperationsProperty = void 0;\nconst types_1 = require(\"../types\");\nconst custom_1 = require(\"./operations/custom\");\nconst operationTypeMap = {\n queries: 'query',\n mutations: 'mutation',\n subscriptions: 'subscription',\n};\nfunction generateCustomOperationsProperty(client, config, operationsType) {\n // some bundlers end up with `Amplify.configure` being called *after* generate client.\n // if that occurs, we need to *not error* while we wait. handling for late configuration\n // occurs in `generateClient()`. we do not need to subscribe to Hub events here.\n if (!config) {\n return {};\n }\n const modelIntrospection = config.modelIntrospection;\n // model intro schema might be absent if there's not actually a configured GraphQL API\n if (!modelIntrospection) {\n return {};\n }\n // custom operations will be absent from model intro schema if no custom ops\n // are present on the source schema.\n const operations = modelIntrospection[operationsType];\n if (!operations) {\n return {};\n }\n const ops = {};\n const useContext = client[types_1.__amplify] === null;\n for (const operation of Object.values(operations)) {\n ops[operation.name] = (0, custom_1.customOpFactory)(client, modelIntrospection, operationTypeMap[operationsType], operation, useContext);\n }\n return ops;\n}\nexports.generateCustomOperationsProperty = generateCustomOperationsProperty;\nfunction generateCustomMutationsProperty(client, config) {\n return generateCustomOperationsProperty(client, config, 'mutations');\n}\nexports.generateCustomMutationsProperty = generateCustomMutationsProperty;\nfunction generateCustomQueriesProperty(client, config) {\n return generateCustomOperationsProperty(client, config, 'queries');\n}\nexports.generateCustomQueriesProperty = generateCustomQueriesProperty;\nfunction generateCustomSubscriptionsProperty(client, config) {\n return generateCustomOperationsProperty(client, config, 'subscriptions');\n}\nexports.generateCustomSubscriptionsProperty = generateCustomSubscriptionsProperty;\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,mCAAmC,GAAG,OAAO,CAAC,6BAA6B,GAAG,OAAO,CAAC,+BAA+B,GAAG,OAAO,CAAC,gCAAgC,GAAG,KAAK,CAAC,CAAC;AAClL,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACpC,MAAM,QAAQ,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAChD,MAAM,gBAAgB,GAAG;AACzB,IAAI,OAAO,EAAE,OAAO;AACpB,IAAI,SAAS,EAAE,UAAU;AACzB,IAAI,aAAa,EAAE,cAAc;AACjC,CAAC,CAAC;AACF,SAAS,gCAAgC,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE;AAC1E;AACA;AACA;AACA,IAAI,IAAI,CAAC,MAAM,EAAE;AACjB,QAAQ,OAAO,EAAE,CAAC;AAClB,KAAK;AACL,IAAI,MAAM,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,CAAC;AACzD;AACA,IAAI,IAAI,CAAC,kBAAkB,EAAE;AAC7B,QAAQ,OAAO,EAAE,CAAC;AAClB,KAAK;AACL;AACA;AACA,IAAI,MAAM,UAAU,GAAG,kBAAkB,CAAC,cAAc,CAAC,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5
|
+
const rxjs_1 = require("rxjs");
|
|
5
6
|
const APIClient_1 = require("../APIClient");
|
|
7
|
+
/**
|
|
8
|
+
* Type guard for checking whether a Custom Operation argument is a contextSpec object
|
|
9
|
+
*/
|
|
10
|
+
const argIsContextSpec = (arg) => {
|
|
11
|
+
return typeof arg?.token?.value === 'symbol';
|
|
12
|
+
};
|
|
6
13
|
/**
|
|
7
14
|
* Builds an operation function, embedded with all client and context data, that
|
|
8
15
|
* can be attached to a client as a custom query or mutation.
|
|
@@ -60,13 +67,38 @@ const APIClient_1 = require("../APIClient");
|
|
|
60
67
|
* @returns The operation function to attach to query, mutations, etc.
|
|
61
68
|
*/
|
|
62
69
|
function customOpFactory(client, modelIntrospection, operationType, operation, useContext) {
|
|
63
|
-
|
|
70
|
+
// .arguments() are defined for the custom operation in the schema builder
|
|
71
|
+
// and are present in the model introspection schema
|
|
72
|
+
const argsDefined = operation.arguments !== undefined;
|
|
73
|
+
const op = (...args) => {
|
|
74
|
+
// options is always the last argument
|
|
75
|
+
const options = args[args.length - 1];
|
|
76
|
+
let contextSpec;
|
|
77
|
+
let arg;
|
|
78
|
+
if (useContext) {
|
|
79
|
+
if (argIsContextSpec(args[0])) {
|
|
80
|
+
contextSpec = args[0];
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
throw new Error(`Invalid first argument passed to ${operation.name}. Expected contextSpec`);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
if (argsDefined) {
|
|
87
|
+
if (useContext) {
|
|
88
|
+
arg = args[1];
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
arg = args[0];
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (operationType === 'subscription') {
|
|
95
|
+
return _opSubscription(
|
|
96
|
+
// subscriptions are only enabled on the clientside
|
|
97
|
+
client, modelIntrospection, operation, arg, options);
|
|
98
|
+
}
|
|
64
99
|
return _op(client, modelIntrospection, operationType, operation, arg, options, contextSpec);
|
|
65
100
|
};
|
|
66
|
-
|
|
67
|
-
return _op(client, modelIntrospection, operationType, operation, arg, options);
|
|
68
|
-
};
|
|
69
|
-
return useContext ? opWithContext : op;
|
|
101
|
+
return op;
|
|
70
102
|
}
|
|
71
103
|
exports.customOpFactory = customOpFactory;
|
|
72
104
|
/**
|
|
@@ -106,6 +138,9 @@ function hasStringField(o, field) {
|
|
|
106
138
|
* @returns "outer" arguments string
|
|
107
139
|
*/
|
|
108
140
|
function outerArguments(operation) {
|
|
141
|
+
if (operation.arguments === undefined) {
|
|
142
|
+
return '';
|
|
143
|
+
}
|
|
109
144
|
const args = Object.entries(operation.arguments)
|
|
110
145
|
.map(([k, v]) => {
|
|
111
146
|
const baseType = v.type + (v.isRequired ? '!' : '');
|
|
@@ -137,6 +172,9 @@ function outerArguments(operation) {
|
|
|
137
172
|
* @returns "outer" arguments string
|
|
138
173
|
*/
|
|
139
174
|
function innerArguments(operation) {
|
|
175
|
+
if (operation.arguments === undefined) {
|
|
176
|
+
return '';
|
|
177
|
+
}
|
|
140
178
|
const args = Object.keys(operation.arguments)
|
|
141
179
|
.map(k => `${k}: $${k}`)
|
|
142
180
|
.join(', ');
|
|
@@ -191,6 +229,9 @@ function operationSelectionSet(modelIntrospection, operation) {
|
|
|
191
229
|
*/
|
|
192
230
|
function operationVariables(operation, args = {}) {
|
|
193
231
|
const variables = {};
|
|
232
|
+
if (operation.arguments === undefined) {
|
|
233
|
+
return variables;
|
|
234
|
+
}
|
|
194
235
|
for (const argDef of Object.values(operation.arguments)) {
|
|
195
236
|
if (typeof args[argDef.name] !== 'undefined') {
|
|
196
237
|
variables[argDef.name] = args[argDef.name];
|
|
@@ -270,4 +311,46 @@ async function _op(client, modelIntrospection, operationType, operation, args, o
|
|
|
270
311
|
}
|
|
271
312
|
}
|
|
272
313
|
}
|
|
314
|
+
/**
|
|
315
|
+
* Executes an operation from the given model intro schema against a client, returning
|
|
316
|
+
* a fully instantiated model when relevant.
|
|
317
|
+
*
|
|
318
|
+
* @param client The client to operate `graphql()` calls through.
|
|
319
|
+
* @param modelIntrospection The model intro schema to construct requests from.
|
|
320
|
+
* @param operation The specific operation name, args, return type details.
|
|
321
|
+
* @param args The arguments to provide to the operation as variables.
|
|
322
|
+
* @param options Request options like headers, etc.
|
|
323
|
+
* @returns Result from the graphql request, model-instantiated when relevant.
|
|
324
|
+
*/
|
|
325
|
+
function _opSubscription(client, modelIntrospection, operation, args, options) {
|
|
326
|
+
const operationType = 'subscription';
|
|
327
|
+
const { name: operationName } = operation;
|
|
328
|
+
const auth = (0, APIClient_1.authModeParams)(client, options);
|
|
329
|
+
const headers = (0, APIClient_1.getCustomHeaders)(client, options?.headers);
|
|
330
|
+
const outerArgsString = outerArguments(operation);
|
|
331
|
+
const innerArgsString = innerArguments(operation);
|
|
332
|
+
const selectionSet = operationSelectionSet(modelIntrospection, operation);
|
|
333
|
+
const returnTypeModelName = hasStringField(operation.type, 'model')
|
|
334
|
+
? operation.type.model
|
|
335
|
+
: undefined;
|
|
336
|
+
const query = `
|
|
337
|
+
${operationType.toLocaleLowerCase()}${outerArgsString} {
|
|
338
|
+
${operationName}${innerArgsString} ${selectionSet}
|
|
339
|
+
}
|
|
340
|
+
`;
|
|
341
|
+
const variables = operationVariables(operation, args);
|
|
342
|
+
const observable = client.graphql({
|
|
343
|
+
...auth,
|
|
344
|
+
query,
|
|
345
|
+
variables,
|
|
346
|
+
}, headers);
|
|
347
|
+
return observable.pipe((0, rxjs_1.map)(value => {
|
|
348
|
+
const [key] = Object.keys(value.data);
|
|
349
|
+
const data = value.data[key];
|
|
350
|
+
const [initialized] = returnTypeModelName
|
|
351
|
+
? (0, APIClient_1.initializeModel)(client, returnTypeModelName, [data], modelIntrospection, auth.authMode, auth.authToken)
|
|
352
|
+
: [data];
|
|
353
|
+
return initialized;
|
|
354
|
+
}));
|
|
355
|
+
}
|
|
273
356
|
//# sourceMappingURL=custom.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom.js","sources":["../../../../src/internals/operations/custom.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.customOpFactory = void 0;\nconst APIClient_1 = require(\"../APIClient\");\n/**\n * Builds an operation function, embedded with all client and context data, that\n * can be attached to a client as a custom query or mutation.\n *\n * If we have this source schema:\n *\n * ```typescript\n * a.schema({\n * echo: a.query()\n * .arguments({input: a.string().required()})\n * .returns(a.string())\n * })\n * ```\n *\n * Our model intro schema will contain an entry like this:\n *\n * ```ts\n * {\n * queries: {\n * echo: {\n * name: \"echo\",\n * isArray: false,\n * type: 'String',\n * isRequired: false,\n * arguments: {\n * input: {\n * name: 'input',\n * isArray: false,\n * type: String,\n * isRequired: true\n * }\n * }\n * }\n * }\n * }\n * ```\n *\n * The `echo` object is used to build the `echo' method that goes here:\n *\n * ```typescript\n * const client = generateClent()\n * const { data } = await client.queries.echo({input: 'a string'});\n * // ^\n * // |\n * // +-- This one right here.\n * //\n * ```\n *\n *\n * @param client The client to run graphql queries through.\n * @param modelIntrospection The model introspection schema the op comes from.\n * @param operationType The broad category of graphql operation.\n * @param operation The operation definition from the introspection schema.\n * @param useContext Whether the function needs to accept an SSR context.\n * @returns The operation function to attach to query, mutations, etc.\n */\nfunction customOpFactory(client, modelIntrospection, operationType, operation, useContext) {\n const opWithContext = async (contextSpec, arg, options) => {\n return _op(client, modelIntrospection, operationType, operation, arg, options, contextSpec);\n };\n const op = async (arg, options) => {\n return _op(client, modelIntrospection, operationType, operation, arg, options);\n };\n return useContext ? opWithContext : op;\n}\nexports.customOpFactory = customOpFactory;\n/**\n * Runtime test and type guard to check whether `o[field]` is a `String`.\n *\n * ```typescript\n * if (hasStringField(o, 'prop')) {\n * const s = o.prop;\n * // ^? const s: string\n * }\n * ```\n *\n * @param o Object to inspect\n * @param field Field to look for\n * @returns Boolean: `true` if the `o[field]` is a `string`\n */\nfunction hasStringField(o, field) {\n return typeof o[field] === 'string';\n}\n/**\n * Generates \"outer\" arguments string for a custom operation. For example,\n * in this operation:\n *\n * ```graphql\n * query MyQuery(InputString: String!) {\n * echoString(InputString: $InputString)\n * }\n * ```\n *\n * This function returns the top/outer level arguments as a string:\n *\n * ```json\n * \"InputString: String!\"\n * ```\n *\n * @param operation Operation object from model introspection schema.\n * @returns \"outer\" arguments string\n */\nfunction outerArguments(operation) {\n const args = Object.entries(operation.arguments)\n .map(([k, v]) => {\n const baseType = v.type + (v.isRequired ? '!' : '');\n const finalType = v.isArray\n ? `[${baseType}]${v.isArrayNullable ? '' : '!'}`\n : baseType;\n return `$${k}: ${finalType}`;\n })\n .join(', ');\n return args.length > 0 ? `(${args})` : '';\n}\n/**\n * Generates \"inner\" arguments string for a custom operation. For example,\n * in this operation:\n *\n * ```graphql\n * query MyQuery(InputString: String!) {\n * echoString(InputString: $InputString)\n * }\n * ```\n *\n * This function returns the inner arguments as a string:\n *\n * ```json\n * \"InputString: $InputString\"\n * ```\n *\n * @param operation Operation object from model introspection schema.\n * @returns \"outer\" arguments string\n */\nfunction innerArguments(operation) {\n const args = Object.keys(operation.arguments)\n .map(k => `${k}: $${k}`)\n .join(', ');\n return args.length > 0 ? `(${args})` : '';\n}\n/**\n * Generates the selection set string for a custom operation. This is slightly\n * different than the selection set generation for models. If the custom op returns\n * a primitive or enum types, it doen't require a selection set at all.\n *\n * E.g., the graphql might look like this:\n *\n * ```graphql\n * query MyQuery {\n * echoString(inputString: \"whatever\")\n * }\n * # ^\n * # |\n * # +-- no selection set\n * ```\n *\n * Non-primitive return type selection set generation will be similar to other\n * model operations.\n *\n * @param modelIntrospection The full code-generated introspection schema.\n * @param operation The operation object from the schema.\n * @returns The selection set as a string.\n */\nfunction operationSelectionSet(modelIntrospection, operation) {\n if (hasStringField(operation, 'type') ||\n hasStringField(operation.type, 'enum')) {\n return '';\n }\n else if (hasStringField(operation.type, 'nonModel')) {\n const nonModel = modelIntrospection.nonModels[operation.type.nonModel];\n return `{${(0, APIClient_1.selectionSetIRToString)((0, APIClient_1.defaultSelectionSetForNonModelWithIR)(nonModel, modelIntrospection))}}`;\n }\n else if (hasStringField(operation.type, 'model')) {\n return `{${(0, APIClient_1.generateSelectionSet)(modelIntrospection, operation.type.model)}}`;\n }\n else {\n return '';\n }\n}\n/**\n * Maps an arguments objec to graphql variables, removing superfluous args and\n * screaming loudly when required args are missing.\n *\n * @param operation The operation to construct graphql request variables for.\n * @param args The arguments to map variables from.\n * @returns The graphql variables object.\n */\nfunction operationVariables(operation, args = {}) {\n const variables = {};\n for (const argDef of Object.values(operation.arguments)) {\n if (typeof args[argDef.name] !== 'undefined') {\n variables[argDef.name] = args[argDef.name];\n }\n else if (argDef.isRequired) {\n // At this point, the variable is both required and missing: We don't need\n // to continue. The operation is expected to fail.\n throw new Error(`${operation.name} requires arguments '${argDef.name}'`);\n }\n }\n return variables;\n}\n/**\n * Executes an operation from the given model intro schema against a client, returning\n * a fully instantiated model when relevant.\n *\n * @param client The client to operate `graphql()` calls through.\n * @param modelIntrospection The model intro schema to construct requests from.\n * @param operationType The high level graphql operation type.\n * @param operation The specific operation name, args, return type details.\n * @param args The arguments to provide to the operation as variables.\n * @param options Request options like headers, etc.\n * @param context SSR context if relevant.\n * @returns Result from the graphql request, model-instantiated when relevant.\n */\nasync function _op(client, modelIntrospection, operationType, operation, args, options, context) {\n const { name: operationName } = operation;\n const auth = (0, APIClient_1.authModeParams)(client, options);\n const headers = (0, APIClient_1.getCustomHeaders)(client, options?.headers);\n const outerArgsString = outerArguments(operation);\n const innerArgsString = innerArguments(operation);\n const selectionSet = operationSelectionSet(modelIntrospection, operation);\n const returnTypeModelName = hasStringField(operation.type, 'model')\n ? operation.type.model\n : undefined;\n const query = `\n\t\t${operationType.toLocaleLowerCase()}${outerArgsString} {\n\t\t\t${operationName}${innerArgsString} ${selectionSet}\n\t\t}\n\t`;\n const variables = operationVariables(operation, args);\n try {\n const { data, extensions } = context\n ? (await client.graphql(context, {\n ...auth,\n query,\n variables,\n }, headers))\n : (await client.graphql({\n ...auth,\n query,\n variables,\n }, headers));\n // flatten response\n if (data) {\n const [key] = Object.keys(data);\n const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];\n // TODO: custom selection set. current selection set is default selection set only\n // custom selection set requires data-schema-type + runtime updates above.\n const [initialized] = returnTypeModelName\n ? (0, APIClient_1.initializeModel)(client, returnTypeModelName, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context)\n : [flattenedResult];\n return { data: initialized, extensions };\n }\n else {\n return { data: null, extensions };\n }\n }\n catch (error) {\n if (error.errors) {\n // graphql errors pass through\n return error;\n }\n else {\n // non-graphql errors re re-thrown\n throw error;\n }\n }\n}\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,eAAe,GAAG,KAAK,CAAC,CAAC;AACjC,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAC5C;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,SAAS,eAAe,CAAC,MAAM,EAAE,kBAAkB,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE;AAC3F,IAAI,MAAM,aAAa,GAAG,OAAO,WAAW,EAAE,GAAG,EAAE,OAAO,KAAK;AAC/D,QAAQ,OAAO,GAAG,CAAC,MAAM,EAAE,kBAAkB,EAAE,aAAa,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;AACpG,KAAK,CAAC;AACN,IAAI,MAAM,EAAE,GAAG,OAAO,GAAG,EAAE,OAAO,KAAK;AACvC,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CAAC,CAAC;AAC5C,YAAY,MAAM,eAAe,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;AAC7E;AACA;AACA,YAAY,MAAM,CAAC,WAAW,CAAC,GAAG,mBAAmB;AACrD,kBAAkB,CAAC,CAAC,EAAE,WAAW,CAAC,eAAe,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC,eAAe,CAAC,EAAE,kBAAkB,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC;AAChK,kBAAkB,CAAC,eAAe,CAAC,CAAC;AACpC,YAAY,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC;AACrD,SAAS;AACT,aAAa;AACb,YAAY,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;AAC9C,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,IAAI,KAAK,CAAC,MAAM,EAAE;AAC1B;AACA,YAAY,OAAO,KAAK,CAAC;AACzB,SAAS;AACT,aAAa;AACb;AACA,YAAY,MAAM,KAAK,CAAC;AACxB,SAAS;AACT,KAAK;AACL;;"}
|
|
1
|
+
{"version":3,"file":"custom.js","sources":["../../../../src/internals/operations/custom.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.customOpFactory = void 0;\nconst rxjs_1 = require(\"rxjs\");\nconst APIClient_1 = require(\"../APIClient\");\n/**\n * Type guard for checking whether a Custom Operation argument is a contextSpec object\n */\nconst argIsContextSpec = (arg) => {\n return typeof arg?.token?.value === 'symbol';\n};\n/**\n * Builds an operation function, embedded with all client and context data, that\n * can be attached to a client as a custom query or mutation.\n *\n * If we have this source schema:\n *\n * ```typescript\n * a.schema({\n * echo: a.query()\n * .arguments({input: a.string().required()})\n * .returns(a.string())\n * })\n * ```\n *\n * Our model intro schema will contain an entry like this:\n *\n * ```ts\n * {\n * queries: {\n * echo: {\n * name: \"echo\",\n * isArray: false,\n * type: 'String',\n * isRequired: false,\n * arguments: {\n * input: {\n * name: 'input',\n * isArray: false,\n * type: String,\n * isRequired: true\n * }\n * }\n * }\n * }\n * }\n * ```\n *\n * The `echo` object is used to build the `echo' method that goes here:\n *\n * ```typescript\n * const client = generateClent()\n * const { data } = await client.queries.echo({input: 'a string'});\n * // ^\n * // |\n * // +-- This one right here.\n * //\n * ```\n *\n *\n * @param client The client to run graphql queries through.\n * @param modelIntrospection The model introspection schema the op comes from.\n * @param operationType The broad category of graphql operation.\n * @param operation The operation definition from the introspection schema.\n * @param useContext Whether the function needs to accept an SSR context.\n * @returns The operation function to attach to query, mutations, etc.\n */\nfunction customOpFactory(client, modelIntrospection, operationType, operation, useContext) {\n // .arguments() are defined for the custom operation in the schema builder\n // and are present in the model introspection schema\n const argsDefined = operation.arguments !== undefined;\n const op = (...args) => {\n // options is always the last argument\n const options = args[args.length - 1];\n let contextSpec;\n let arg;\n if (useContext) {\n if (argIsContextSpec(args[0])) {\n contextSpec = args[0];\n }\n else {\n throw new Error(`Invalid first argument passed to ${operation.name}. Expected contextSpec`);\n }\n }\n if (argsDefined) {\n if (useContext) {\n arg = args[1];\n }\n else {\n arg = args[0];\n }\n }\n if (operationType === 'subscription') {\n return _opSubscription(\n // subscriptions are only enabled on the clientside\n client, modelIntrospection, operation, arg, options);\n }\n return _op(client, modelIntrospection, operationType, operation, arg, options, contextSpec);\n };\n return op;\n}\nexports.customOpFactory = customOpFactory;\n/**\n * Runtime test and type guard to check whether `o[field]` is a `String`.\n *\n * ```typescript\n * if (hasStringField(o, 'prop')) {\n * const s = o.prop;\n * // ^? const s: string\n * }\n * ```\n *\n * @param o Object to inspect\n * @param field Field to look for\n * @returns Boolean: `true` if the `o[field]` is a `string`\n */\nfunction hasStringField(o, field) {\n return typeof o[field] === 'string';\n}\n/**\n * Generates \"outer\" arguments string for a custom operation. For example,\n * in this operation:\n *\n * ```graphql\n * query MyQuery(InputString: String!) {\n * echoString(InputString: $InputString)\n * }\n * ```\n *\n * This function returns the top/outer level arguments as a string:\n *\n * ```json\n * \"InputString: String!\"\n * ```\n *\n * @param operation Operation object from model introspection schema.\n * @returns \"outer\" arguments string\n */\nfunction outerArguments(operation) {\n if (operation.arguments === undefined) {\n return '';\n }\n const args = Object.entries(operation.arguments)\n .map(([k, v]) => {\n const baseType = v.type + (v.isRequired ? '!' : '');\n const finalType = v.isArray\n ? `[${baseType}]${v.isArrayNullable ? '' : '!'}`\n : baseType;\n return `$${k}: ${finalType}`;\n })\n .join(', ');\n return args.length > 0 ? `(${args})` : '';\n}\n/**\n * Generates \"inner\" arguments string for a custom operation. For example,\n * in this operation:\n *\n * ```graphql\n * query MyQuery(InputString: String!) {\n * echoString(InputString: $InputString)\n * }\n * ```\n *\n * This function returns the inner arguments as a string:\n *\n * ```json\n * \"InputString: $InputString\"\n * ```\n *\n * @param operation Operation object from model introspection schema.\n * @returns \"outer\" arguments string\n */\nfunction innerArguments(operation) {\n if (operation.arguments === undefined) {\n return '';\n }\n const args = Object.keys(operation.arguments)\n .map(k => `${k}: $${k}`)\n .join(', ');\n return args.length > 0 ? `(${args})` : '';\n}\n/**\n * Generates the selection set string for a custom operation. This is slightly\n * different than the selection set generation for models. If the custom op returns\n * a primitive or enum types, it doen't require a selection set at all.\n *\n * E.g., the graphql might look like this:\n *\n * ```graphql\n * query MyQuery {\n * echoString(inputString: \"whatever\")\n * }\n * # ^\n * # |\n * # +-- no selection set\n * ```\n *\n * Non-primitive return type selection set generation will be similar to other\n * model operations.\n *\n * @param modelIntrospection The full code-generated introspection schema.\n * @param operation The operation object from the schema.\n * @returns The selection set as a string.\n */\nfunction operationSelectionSet(modelIntrospection, operation) {\n if (hasStringField(operation, 'type') ||\n hasStringField(operation.type, 'enum')) {\n return '';\n }\n else if (hasStringField(operation.type, 'nonModel')) {\n const nonModel = modelIntrospection.nonModels[operation.type.nonModel];\n return `{${(0, APIClient_1.selectionSetIRToString)((0, APIClient_1.defaultSelectionSetForNonModelWithIR)(nonModel, modelIntrospection))}}`;\n }\n else if (hasStringField(operation.type, 'model')) {\n return `{${(0, APIClient_1.generateSelectionSet)(modelIntrospection, operation.type.model)}}`;\n }\n else {\n return '';\n }\n}\n/**\n * Maps an arguments objec to graphql variables, removing superfluous args and\n * screaming loudly when required args are missing.\n *\n * @param operation The operation to construct graphql request variables for.\n * @param args The arguments to map variables from.\n * @returns The graphql variables object.\n */\nfunction operationVariables(operation, args = {}) {\n const variables = {};\n if (operation.arguments === undefined) {\n return variables;\n }\n for (const argDef of Object.values(operation.arguments)) {\n if (typeof args[argDef.name] !== 'undefined') {\n variables[argDef.name] = args[argDef.name];\n }\n else if (argDef.isRequired) {\n // At this point, the variable is both required and missing: We don't need\n // to continue. The operation is expected to fail.\n throw new Error(`${operation.name} requires arguments '${argDef.name}'`);\n }\n }\n return variables;\n}\n/**\n * Executes an operation from the given model intro schema against a client, returning\n * a fully instantiated model when relevant.\n *\n * @param client The client to operate `graphql()` calls through.\n * @param modelIntrospection The model intro schema to construct requests from.\n * @param operationType The high level graphql operation type.\n * @param operation The specific operation name, args, return type details.\n * @param args The arguments to provide to the operation as variables.\n * @param options Request options like headers, etc.\n * @param context SSR context if relevant.\n * @returns Result from the graphql request, model-instantiated when relevant.\n */\nasync function _op(client, modelIntrospection, operationType, operation, args, options, context) {\n const { name: operationName } = operation;\n const auth = (0, APIClient_1.authModeParams)(client, options);\n const headers = (0, APIClient_1.getCustomHeaders)(client, options?.headers);\n const outerArgsString = outerArguments(operation);\n const innerArgsString = innerArguments(operation);\n const selectionSet = operationSelectionSet(modelIntrospection, operation);\n const returnTypeModelName = hasStringField(operation.type, 'model')\n ? operation.type.model\n : undefined;\n const query = `\n\t\t${operationType.toLocaleLowerCase()}${outerArgsString} {\n\t\t\t${operationName}${innerArgsString} ${selectionSet}\n\t\t}\n\t`;\n const variables = operationVariables(operation, args);\n try {\n const { data, extensions } = context\n ? (await client.graphql(context, {\n ...auth,\n query,\n variables,\n }, headers))\n : (await client.graphql({\n ...auth,\n query,\n variables,\n }, headers));\n // flatten response\n if (data) {\n const [key] = Object.keys(data);\n const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];\n // TODO: custom selection set. current selection set is default selection set only\n // custom selection set requires data-schema-type + runtime updates above.\n const [initialized] = returnTypeModelName\n ? (0, APIClient_1.initializeModel)(client, returnTypeModelName, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context)\n : [flattenedResult];\n return { data: initialized, extensions };\n }\n else {\n return { data: null, extensions };\n }\n }\n catch (error) {\n if (error.errors) {\n // graphql errors pass through\n return error;\n }\n else {\n // non-graphql errors re re-thrown\n throw error;\n }\n }\n}\n/**\n * Executes an operation from the given model intro schema against a client, returning\n * a fully instantiated model when relevant.\n *\n * @param client The client to operate `graphql()` calls through.\n * @param modelIntrospection The model intro schema to construct requests from.\n * @param operation The specific operation name, args, return type details.\n * @param args The arguments to provide to the operation as variables.\n * @param options Request options like headers, etc.\n * @returns Result from the graphql request, model-instantiated when relevant.\n */\nfunction _opSubscription(client, modelIntrospection, operation, args, options) {\n const operationType = 'subscription';\n const { name: operationName } = operation;\n const auth = (0, APIClient_1.authModeParams)(client, options);\n const headers = (0, APIClient_1.getCustomHeaders)(client, options?.headers);\n const outerArgsString = outerArguments(operation);\n const innerArgsString = innerArguments(operation);\n const selectionSet = operationSelectionSet(modelIntrospection, operation);\n const returnTypeModelName = hasStringField(operation.type, 'model')\n ? operation.type.model\n : undefined;\n const query = `\n\t\t${operationType.toLocaleLowerCase()}${outerArgsString} {\n\t\t\t${operationName}${innerArgsString} ${selectionSet}\n\t\t}\n\t`;\n const variables = operationVariables(operation, args);\n const observable = client.graphql({\n ...auth,\n query,\n variables,\n }, headers);\n return observable.pipe((0, rxjs_1.map)(value => {\n const [key] = Object.keys(value.data);\n const data = value.data[key];\n const [initialized] = returnTypeModelName\n ? (0, APIClient_1.initializeModel)(client, returnTypeModelName, [data], modelIntrospection, auth.authMode, auth.authToken)\n : [data];\n return initialized;\n }));\n}\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,eAAe,GAAG,KAAK,CAAC,CAAC;AACjC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC/B,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAC5C;AACA;AACA;AACA,MAAM,gBAAgB,GAAG,CAAC,GAAG,KAAK;AAClC,IAAI,OAAO,OAAO,GAAG,EAAE,KAAK,EAAE,KAAK,KAAK,QAAQ,CAAC;AACjD,CAAC,CAAC;AACF;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,SAAS,eAAe,CAAC,MAAM,EAAE,kBAAkB,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE;AAC3F;AACA;AACA,IAAI,MAAM,WAAW,GAAG,SAAS,CAAC,SAAS,KAAK,SAAS,CAAC;AAC1D,IAAI,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,KAAK;AAC5B;AACA,QAAQ,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC9C,QAAQ,IAAI,WAAW,CAAC;AACxB,QAAQ,IAAI,GAAG,CAAC;AAChB,QAAQ,IAAI,UAAU,EAAE;AACxB,YAAY,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;AAC3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AC;AACpB,IAAI,MAAM,KAAK,GAAG,CAAC;AACnB,EAAE,EAAE,aAAa,CAAC,iBAAiB,EAAE,CAAC,EAAE,eAAe,CAAC;AACxD,GAAG,EAAE,aAAa,CAAC,EAAE,eAAe,CAAC,CAAC,EAAE,YAAY,CAAC;AACrD;AACA,CAAC,CAAC,CAAC;AACH,IAAI,MAAM,SAAS,GAAG,kBAAkB,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AAC1D,IAAI,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC;AACtC,QAAQ,GAAG,IAAI;AACf,QAAQ,KAAK;AACb,QAAQ,SAAS;AACjB,KAAK,EAAE,OAAO,CAAC,CAAC;AAChB,IAAI,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE,KAAK,IAAI;AACpD,QAAQ,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC9C,QAAQ,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACrC,QAAQ,MAAM,CAAC,WAAW,CAAC,GAAG,mBAAmB;AACjD,cAAc,IAAI,WAAW,CAAC,eAAe,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC,IAAI,CAAC,EAAE,kBAAkB,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC;AACtI,cAAc,CAAC,IAAI,CAAC,CAAC;AACrB,QAAQ,OAAO,WAAW,CAAC;AAC3B,KAAK,CAAC,CAAC,CAAC;AACR;;"}
|
|
@@ -4,7 +4,7 @@ import { graphql, cancel, isCancelError } from './v6.mjs';
|
|
|
4
4
|
import { generateEnumsProperty } from './utils/clientProperties/generateEnumsProperty.mjs';
|
|
5
5
|
import { generateModelsProperty } from './utils/clientProperties/generateModelsProperty.mjs';
|
|
6
6
|
import { isApiGraphQLConfig } from './utils/runtimeTypeGuards/isApiGraphQLProviderConfig.mjs';
|
|
7
|
-
import { generateCustomQueriesProperty, generateCustomMutationsProperty } from './generateCustomOperationsProperty.mjs';
|
|
7
|
+
import { generateCustomQueriesProperty, generateCustomMutationsProperty, generateCustomSubscriptionsProperty } from './generateCustomOperationsProperty.mjs';
|
|
8
8
|
import { isConfigureEventWithResourceConfig } from './utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.mjs';
|
|
9
9
|
|
|
10
10
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
@@ -31,6 +31,7 @@ function generateClient(params) {
|
|
|
31
31
|
enums: emptyProperty,
|
|
32
32
|
queries: emptyProperty,
|
|
33
33
|
mutations: emptyProperty,
|
|
34
|
+
subscriptions: emptyProperty,
|
|
34
35
|
};
|
|
35
36
|
const apiGraphqlConfig = params.amplify.getConfig().API?.GraphQL;
|
|
36
37
|
if (isApiGraphQLConfig(apiGraphqlConfig)) {
|
|
@@ -38,6 +39,7 @@ function generateClient(params) {
|
|
|
38
39
|
client.enums = generateEnumsProperty(apiGraphqlConfig);
|
|
39
40
|
client.queries = generateCustomQueriesProperty(client, apiGraphqlConfig);
|
|
40
41
|
client.mutations = generateCustomMutationsProperty(client, apiGraphqlConfig);
|
|
42
|
+
client.subscriptions = generateCustomSubscriptionsProperty(client, apiGraphqlConfig);
|
|
41
43
|
}
|
|
42
44
|
else {
|
|
43
45
|
// This happens when the `Amplify.configure()` call gets evaluated after the `generateClient()` call.
|
|
@@ -67,6 +69,7 @@ const generateModelsPropertyOnAmplifyConfigure = (clientRef) => {
|
|
|
67
69
|
clientRef.enums = generateEnumsProperty(apiGraphQLConfig);
|
|
68
70
|
clientRef.queries = generateCustomQueriesProperty(clientRef, apiGraphQLConfig);
|
|
69
71
|
clientRef.mutations = generateCustomMutationsProperty(clientRef, apiGraphQLConfig);
|
|
72
|
+
clientRef.subscriptions = generateCustomSubscriptionsProperty(clientRef, apiGraphQLConfig);
|
|
70
73
|
}
|
|
71
74
|
});
|
|
72
75
|
};
|
|
@@ -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 { Hub } from '@aws-amplify/core';\nimport { __amplify, __authMode, __authToken, __headers, } from '../types';\nimport { cancel, graphql, isCancelError } from './v6';\nimport { generateEnumsProperty } from './utils/clientProperties/generateEnumsProperty';\nimport { generateModelsProperty } from './utils/clientProperties/generateModelsProperty';\nimport { isApiGraphQLConfig } from './utils/runtimeTypeGuards/isApiGraphQLProviderConfig';\nimport { generateCustomMutationsProperty, generateCustomQueriesProperty, } from './generateCustomOperationsProperty';\nimport { isConfigureEventWithResourceConfig } from './utils/runtimeTypeGuards/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 queries: emptyProperty,\n mutations: 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 client.queries = generateCustomQueriesProperty(client, apiGraphqlConfig);\n client.mutations = generateCustomMutationsProperty(client, 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 clientRef.queries = generateCustomQueriesProperty(clientRef, apiGraphQLConfig);\n clientRef.mutations = generateCustomMutationsProperty(clientRef, 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;AASA;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,QAAQ,OAAO,EAAE,aAAa;AAC9B,QAAQ,SAAS,EAAE,aAAa;AAChC,KAAK,CAAC;AACN,IAAI,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC,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,gBAAgB,CAAC,CAAC;AAC/F,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;;;;"}
|
|
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 { __amplify, __authMode, __authToken, __headers, } from '../types';\nimport { cancel, graphql, isCancelError } from './v6';\nimport { generateEnumsProperty } from './utils/clientProperties/generateEnumsProperty';\nimport { generateModelsProperty } from './utils/clientProperties/generateModelsProperty';\nimport { isApiGraphQLConfig } from './utils/runtimeTypeGuards/isApiGraphQLProviderConfig';\nimport { generateCustomMutationsProperty, generateCustomQueriesProperty, generateCustomSubscriptionsProperty, } from './generateCustomOperationsProperty';\nimport { isConfigureEventWithResourceConfig } from './utils/runtimeTypeGuards/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 queries: emptyProperty,\n mutations: emptyProperty,\n subscriptions: 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 client.queries = generateCustomQueriesProperty(client, apiGraphqlConfig);\n client.mutations = generateCustomMutationsProperty(client, apiGraphqlConfig);\n client.subscriptions = generateCustomSubscriptionsProperty(client, 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 clientRef.queries = generateCustomQueriesProperty(clientRef, apiGraphQLConfig);\n clientRef.mutations = generateCustomMutationsProperty(clientRef, apiGraphQLConfig);\n clientRef.subscriptions = generateCustomSubscriptionsProperty(clientRef, 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;AASA;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,W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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,YAAY,SAAS,CAAC,OAAO,GAAG,6BAA6B,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;AAC3F,YAAY,SAAS,CAAC,SAAS,GAAG,+BAA+B,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;AAC/F,YAAY,SAAS,CAAC,aAAa,GAAG,mCAAmC,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;AACvG,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;;;;"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { CustomMutations, CustomQueries } from '@aws-amplify/data-schema-types';
|
|
2
2
|
import { GraphQLProviderConfig } from '@aws-amplify/core/internals/utils';
|
|
3
3
|
import { V6Client } from '../types';
|
|
4
|
-
type OpTypes = 'queries' | 'mutations';
|
|
4
|
+
type OpTypes = 'queries' | 'mutations' | 'subscriptions';
|
|
5
5
|
export declare function generateCustomOperationsProperty<T extends Record<any, any>, OpType extends OpTypes>(client: V6Client<Record<string, any>>, config: GraphQLProviderConfig['GraphQL'], operationsType: OpType): OpType extends 'queries' ? CustomQueries<T> : CustomMutations<T>;
|
|
6
6
|
export declare function generateCustomMutationsProperty<T extends Record<any, any>>(client: V6Client<Record<string, any>>, config: GraphQLProviderConfig['GraphQL']): CustomMutations<T>;
|
|
7
7
|
export declare function generateCustomQueriesProperty<T extends Record<any, any>>(client: V6Client<Record<string, any>>, config: GraphQLProviderConfig['GraphQL']): CustomQueries<T>;
|
|
8
|
+
export declare function generateCustomSubscriptionsProperty<T extends Record<any, any>>(client: V6Client<Record<string, any>>, config: GraphQLProviderConfig['GraphQL']): CustomMutations<T>;
|
|
8
9
|
export {};
|
|
@@ -4,6 +4,7 @@ import { customOpFactory } from './operations/custom.mjs';
|
|
|
4
4
|
const operationTypeMap = {
|
|
5
5
|
queries: 'query',
|
|
6
6
|
mutations: 'mutation',
|
|
7
|
+
subscriptions: 'subscription',
|
|
7
8
|
};
|
|
8
9
|
function generateCustomOperationsProperty(client, config, operationsType) {
|
|
9
10
|
// some bundlers end up with `Amplify.configure` being called *after* generate client.
|
|
@@ -36,6 +37,9 @@ function generateCustomMutationsProperty(client, config) {
|
|
|
36
37
|
function generateCustomQueriesProperty(client, config) {
|
|
37
38
|
return generateCustomOperationsProperty(client, config, 'queries');
|
|
38
39
|
}
|
|
40
|
+
function generateCustomSubscriptionsProperty(client, config) {
|
|
41
|
+
return generateCustomOperationsProperty(client, config, 'subscriptions');
|
|
42
|
+
}
|
|
39
43
|
|
|
40
|
-
export { generateCustomMutationsProperty, generateCustomOperationsProperty, generateCustomQueriesProperty };
|
|
44
|
+
export { generateCustomMutationsProperty, generateCustomOperationsProperty, generateCustomQueriesProperty, generateCustomSubscriptionsProperty };
|
|
41
45
|
//# sourceMappingURL=generateCustomOperationsProperty.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateCustomOperationsProperty.mjs","sources":["../../../src/internals/generateCustomOperationsProperty.ts"],"sourcesContent":["import { __amplify } from '../types';\nimport { customOpFactory } from './operations/custom';\nconst operationTypeMap = {\n queries: 'query',\n mutations: 'mutation',\n};\nexport function generateCustomOperationsProperty(client, config, operationsType) {\n // some bundlers end up with `Amplify.configure` being called *after* generate client.\n // if that occurs, we need to *not error* while we wait. handling for late configuration\n // occurs in `generateClient()`. we do not need to subscribe to Hub events here.\n if (!config) {\n return {};\n }\n const modelIntrospection = config.modelIntrospection;\n // model intro schema might be absent if there's not actually a configured GraphQL API\n if (!modelIntrospection) {\n return {};\n }\n // custom operations will be absent from model intro schema if no custom ops\n // are present on the source schema.\n const operations = modelIntrospection[operationsType];\n if (!operations) {\n return {};\n }\n const ops = {};\n const useContext = client[__amplify] === null;\n for (const operation of Object.values(operations)) {\n ops[operation.name] = customOpFactory(client, modelIntrospection, operationTypeMap[operationsType], operation, useContext);\n }\n return ops;\n}\nexport function generateCustomMutationsProperty(client, config) {\n return generateCustomOperationsProperty(client, config, 'mutations');\n}\nexport function generateCustomQueriesProperty(client, config) {\n return generateCustomOperationsProperty(client, config, 'queries');\n}\n"],"names":[],"mappings":";;;AAEA,MAAM,gBAAgB,GAAG;AACzB,IAAI,OAAO,EAAE,OAAO;AACpB,IAAI,SAAS,EAAE,UAAU;AACzB,CAAC,CAAC;AACK,SAAS,gCAAgC,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE;AACjF;AACA;AACA;AACA,IAAI,IAAI,CAAC,MAAM,EAAE;AACjB,QAAQ,OAAO,EAAE,CAAC;AAClB,KAAK;AACL,IAAI,MAAM,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,CAAC;AACzD;AACA,IAAI,IAAI,CAAC,kBAAkB,EAAE;AAC7B,QAAQ,OAAO,EAAE,CAAC;AAClB,KAAK;AACL;AACA;AACA,IAAI,MAAM,UAAU,GAAG,kBAAkB,CAAC,cAAc,CAAC,CAAC;AAC1D,IAAI,IAAI,CAAC,UAAU,EAAE;AACrB,QAAQ,OAAO,EAAE,CAAC;AAClB,KAAK;AACL,IAAI,MAAM,GAAG,GAAG,EAAE,CAAC;AACnB,IAAI,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC;AAClD,IAAI,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;AACvD,QAAQ,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC,MAAM,EAAE,kBAAkB,EAAE,gBAAgB,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AACnI,KAAK;AACL,IAAI,OAAO,GAAG,CAAC;AACf,CAAC;AACM,SAAS,+BAA+B,CAAC,MAAM,EAAE,MAAM,EAAE;AAChE,IAAI,OAAO,gCAAgC,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;AACzE,CAAC;AACM,SAAS,6BAA6B,CAAC,MAAM,EAAE,MAAM,EAAE;AAC9D,IAAI,OAAO,gCAAgC,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;AACvE;;;;"}
|
|
1
|
+
{"version":3,"file":"generateCustomOperationsProperty.mjs","sources":["../../../src/internals/generateCustomOperationsProperty.ts"],"sourcesContent":["import { __amplify } from '../types';\nimport { customOpFactory } from './operations/custom';\nconst operationTypeMap = {\n queries: 'query',\n mutations: 'mutation',\n subscriptions: 'subscription',\n};\nexport function generateCustomOperationsProperty(client, config, operationsType) {\n // some bundlers end up with `Amplify.configure` being called *after* generate client.\n // if that occurs, we need to *not error* while we wait. handling for late configuration\n // occurs in `generateClient()`. we do not need to subscribe to Hub events here.\n if (!config) {\n return {};\n }\n const modelIntrospection = config.modelIntrospection;\n // model intro schema might be absent if there's not actually a configured GraphQL API\n if (!modelIntrospection) {\n return {};\n }\n // custom operations will be absent from model intro schema if no custom ops\n // are present on the source schema.\n const operations = modelIntrospection[operationsType];\n if (!operations) {\n return {};\n }\n const ops = {};\n const useContext = client[__amplify] === null;\n for (const operation of Object.values(operations)) {\n ops[operation.name] = customOpFactory(client, modelIntrospection, operationTypeMap[operationsType], operation, useContext);\n }\n return ops;\n}\nexport function generateCustomMutationsProperty(client, config) {\n return generateCustomOperationsProperty(client, config, 'mutations');\n}\nexport function generateCustomQueriesProperty(client, config) {\n return generateCustomOperationsProperty(client, config, 'queries');\n}\nexport function generateCustomSubscriptionsProperty(client, config) {\n return generateCustomOperationsProperty(client, config, 'subscriptions');\n}\n"],"names":[],"mappings":";;;AAEA,MAAM,gBAAgB,GAAG;AACzB,IAAI,OAAO,EAAE,OAAO;AACpB,IAAI,SAAS,EAAE,UAAU;AACzB,IAAI,aAAa,EAAE,cAAc;AACjC,CAAC,CAAC;AACK,SAAS,gCAAgC,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE;AACjF;AACA;AACA;AACA,IAAI,IAAI,CAAC,MAAM,EAAE;AACjB,QAAQ,OAAO,EAAE,CAAC;AAClB,KAAK;AACL,IAAI,MAAM,kBAAkB,GAAG,MAAM,CAAC,kBAAkB,CAAC;AACzD;AACA,IAAI,IAAI,CAAC,kBAAkB,EAAE;AAC7B,QAAQ,OAAO,EAAE,CAAC;AAClB,KAAK;AACL;AACA;AACA,IAAI,MAAM,UAAU,GAAG,kBAAkB,CAAC,cAAc,CAAC,CAAC;AAC1D,IAAI,IAAI,CAAC,UAAU,EAAE;AACrB,QAAQ,OAAO,EAAE,CAAC;AAClB,KAAK;AACL,IAAI,MAAM,GAAG,GAAG,EAAE,CAAC;AACnB,IAAI,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC;AAClD,IAAI,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;AACvD,QAAQ,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC,MAAM,EAAE,kBAAkB,EAAE,gBAAgB,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AACnI,KAAK;AACL,IAAI,OAAO,GAAG,CAAC;AACf,CAAC;AACM,SAAS,+BAA+B,CAAC,MAAM,EAAE,MAAM,EAAE;AAChE,IAAI,OAAO,gCAAgC,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;AACzE,CAAC;AACM,SAAS,6BAA6B,CAAC,MAAM,EAAE,MAAM,EAAE;AAC9D,IAAI,OAAO,gCAAgC,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;AACvE,CAAC;AACM,SAAS,mCAAmC,CAAC,MAAM,EAAE,MAAM,EAAE;AACpE,IAAI,OAAO,gCAAgC,CAAC,MAAM,EAAE,MAAM,EAAE,eAAe,CAAC,CAAC;AAC7E;;;;"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
|
|
2
2
|
import { CustomOperation, ModelIntrospectionSchema } from '@aws-amplify/core/internals/utils';
|
|
3
|
-
import { AuthModeParams, ClientWithModels,
|
|
3
|
+
import { AuthModeParams, ClientWithModels, ListArgs, QueryArgs } from '../../types';
|
|
4
|
+
type CustomOperationOptions = AuthModeParams & ListArgs;
|
|
5
|
+
type OpArgs = [AmplifyServer.ContextSpec, QueryArgs, CustomOperationOptions] | [AmplifyServer.ContextSpec, CustomOperationOptions] | [QueryArgs, CustomOperationOptions] | [CustomOperationOptions];
|
|
4
6
|
/**
|
|
5
7
|
* Builds an operation function, embedded with all client and context data, that
|
|
6
8
|
* can be attached to a client as a custom query or mutation.
|
|
@@ -57,4 +59,5 @@ import { AuthModeParams, ClientWithModels, GraphQLOptionsV6, ListArgs, QueryArgs
|
|
|
57
59
|
* @param useContext Whether the function needs to accept an SSR context.
|
|
58
60
|
* @returns The operation function to attach to query, mutations, etc.
|
|
59
61
|
*/
|
|
60
|
-
export declare function customOpFactory(client: ClientWithModels, modelIntrospection: ModelIntrospectionSchema, operationType: 'query' | 'mutation', operation: CustomOperation, useContext: boolean): (
|
|
62
|
+
export declare function customOpFactory(client: ClientWithModels, modelIntrospection: ModelIntrospectionSchema, operationType: 'query' | 'mutation' | 'subscription', operation: CustomOperation, useContext: boolean): (...args: OpArgs) => Promise<any> | import("rxjs").Observable<any>;
|
|
63
|
+
export {};
|
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
import { map } from 'rxjs';
|
|
1
2
|
import { authModeParams, getCustomHeaders, flattenItems, initializeModel, selectionSetIRToString, defaultSelectionSetForNonModelWithIR, generateSelectionSet } from '../APIClient.mjs';
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Type guard for checking whether a Custom Operation argument is a contextSpec object
|
|
6
|
+
*/
|
|
7
|
+
const argIsContextSpec = (arg) => {
|
|
8
|
+
return typeof arg?.token?.value === 'symbol';
|
|
9
|
+
};
|
|
3
10
|
/**
|
|
4
11
|
* Builds an operation function, embedded with all client and context data, that
|
|
5
12
|
* can be attached to a client as a custom query or mutation.
|
|
@@ -57,13 +64,38 @@ import { authModeParams, getCustomHeaders, flattenItems, initializeModel, select
|
|
|
57
64
|
* @returns The operation function to attach to query, mutations, etc.
|
|
58
65
|
*/
|
|
59
66
|
function customOpFactory(client, modelIntrospection, operationType, operation, useContext) {
|
|
60
|
-
|
|
67
|
+
// .arguments() are defined for the custom operation in the schema builder
|
|
68
|
+
// and are present in the model introspection schema
|
|
69
|
+
const argsDefined = operation.arguments !== undefined;
|
|
70
|
+
const op = (...args) => {
|
|
71
|
+
// options is always the last argument
|
|
72
|
+
const options = args[args.length - 1];
|
|
73
|
+
let contextSpec;
|
|
74
|
+
let arg;
|
|
75
|
+
if (useContext) {
|
|
76
|
+
if (argIsContextSpec(args[0])) {
|
|
77
|
+
contextSpec = args[0];
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
throw new Error(`Invalid first argument passed to ${operation.name}. Expected contextSpec`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (argsDefined) {
|
|
84
|
+
if (useContext) {
|
|
85
|
+
arg = args[1];
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
arg = args[0];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (operationType === 'subscription') {
|
|
92
|
+
return _opSubscription(
|
|
93
|
+
// subscriptions are only enabled on the clientside
|
|
94
|
+
client, modelIntrospection, operation, arg, options);
|
|
95
|
+
}
|
|
61
96
|
return _op(client, modelIntrospection, operationType, operation, arg, options, contextSpec);
|
|
62
97
|
};
|
|
63
|
-
|
|
64
|
-
return _op(client, modelIntrospection, operationType, operation, arg, options);
|
|
65
|
-
};
|
|
66
|
-
return useContext ? opWithContext : op;
|
|
98
|
+
return op;
|
|
67
99
|
}
|
|
68
100
|
/**
|
|
69
101
|
* Runtime test and type guard to check whether `o[field]` is a `String`.
|
|
@@ -102,6 +134,9 @@ function hasStringField(o, field) {
|
|
|
102
134
|
* @returns "outer" arguments string
|
|
103
135
|
*/
|
|
104
136
|
function outerArguments(operation) {
|
|
137
|
+
if (operation.arguments === undefined) {
|
|
138
|
+
return '';
|
|
139
|
+
}
|
|
105
140
|
const args = Object.entries(operation.arguments)
|
|
106
141
|
.map(([k, v]) => {
|
|
107
142
|
const baseType = v.type + (v.isRequired ? '!' : '');
|
|
@@ -133,6 +168,9 @@ function outerArguments(operation) {
|
|
|
133
168
|
* @returns "outer" arguments string
|
|
134
169
|
*/
|
|
135
170
|
function innerArguments(operation) {
|
|
171
|
+
if (operation.arguments === undefined) {
|
|
172
|
+
return '';
|
|
173
|
+
}
|
|
136
174
|
const args = Object.keys(operation.arguments)
|
|
137
175
|
.map(k => `${k}: $${k}`)
|
|
138
176
|
.join(', ');
|
|
@@ -187,6 +225,9 @@ function operationSelectionSet(modelIntrospection, operation) {
|
|
|
187
225
|
*/
|
|
188
226
|
function operationVariables(operation, args = {}) {
|
|
189
227
|
const variables = {};
|
|
228
|
+
if (operation.arguments === undefined) {
|
|
229
|
+
return variables;
|
|
230
|
+
}
|
|
190
231
|
for (const argDef of Object.values(operation.arguments)) {
|
|
191
232
|
if (typeof args[argDef.name] !== 'undefined') {
|
|
192
233
|
variables[argDef.name] = args[argDef.name];
|
|
@@ -266,6 +307,48 @@ async function _op(client, modelIntrospection, operationType, operation, args, o
|
|
|
266
307
|
}
|
|
267
308
|
}
|
|
268
309
|
}
|
|
310
|
+
/**
|
|
311
|
+
* Executes an operation from the given model intro schema against a client, returning
|
|
312
|
+
* a fully instantiated model when relevant.
|
|
313
|
+
*
|
|
314
|
+
* @param client The client to operate `graphql()` calls through.
|
|
315
|
+
* @param modelIntrospection The model intro schema to construct requests from.
|
|
316
|
+
* @param operation The specific operation name, args, return type details.
|
|
317
|
+
* @param args The arguments to provide to the operation as variables.
|
|
318
|
+
* @param options Request options like headers, etc.
|
|
319
|
+
* @returns Result from the graphql request, model-instantiated when relevant.
|
|
320
|
+
*/
|
|
321
|
+
function _opSubscription(client, modelIntrospection, operation, args, options) {
|
|
322
|
+
const operationType = 'subscription';
|
|
323
|
+
const { name: operationName } = operation;
|
|
324
|
+
const auth = authModeParams(client, options);
|
|
325
|
+
const headers = getCustomHeaders(client, options?.headers);
|
|
326
|
+
const outerArgsString = outerArguments(operation);
|
|
327
|
+
const innerArgsString = innerArguments(operation);
|
|
328
|
+
const selectionSet = operationSelectionSet(modelIntrospection, operation);
|
|
329
|
+
const returnTypeModelName = hasStringField(operation.type, 'model')
|
|
330
|
+
? operation.type.model
|
|
331
|
+
: undefined;
|
|
332
|
+
const query = `
|
|
333
|
+
${operationType.toLocaleLowerCase()}${outerArgsString} {
|
|
334
|
+
${operationName}${innerArgsString} ${selectionSet}
|
|
335
|
+
}
|
|
336
|
+
`;
|
|
337
|
+
const variables = operationVariables(operation, args);
|
|
338
|
+
const observable = client.graphql({
|
|
339
|
+
...auth,
|
|
340
|
+
query,
|
|
341
|
+
variables,
|
|
342
|
+
}, headers);
|
|
343
|
+
return observable.pipe(map(value => {
|
|
344
|
+
const [key] = Object.keys(value.data);
|
|
345
|
+
const data = value.data[key];
|
|
346
|
+
const [initialized] = returnTypeModelName
|
|
347
|
+
? initializeModel(client, returnTypeModelName, [data], modelIntrospection, auth.authMode, auth.authToken)
|
|
348
|
+
: [data];
|
|
349
|
+
return initialized;
|
|
350
|
+
}));
|
|
351
|
+
}
|
|
269
352
|
|
|
270
353
|
export { customOpFactory };
|
|
271
354
|
//# sourceMappingURL=custom.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom.mjs","sources":["../../../../src/internals/operations/custom.ts"],"sourcesContent":["import { authModeParams, defaultSelectionSetForNonModelWithIR, flattenItems, generateSelectionSet, getCustomHeaders, initializeModel, selectionSetIRToString, } from '../APIClient';\n/**\n * Builds an operation function, embedded with all client and context data, that\n * can be attached to a client as a custom query or mutation.\n *\n * If we have this source schema:\n *\n * ```typescript\n * a.schema({\n * echo: a.query()\n * .arguments({input: a.string().required()})\n * .returns(a.string())\n * })\n * ```\n *\n * Our model intro schema will contain an entry like this:\n *\n * ```ts\n * {\n * queries: {\n * echo: {\n * name: \"echo\",\n * isArray: false,\n * type: 'String',\n * isRequired: false,\n * arguments: {\n * input: {\n * name: 'input',\n * isArray: false,\n * type: String,\n * isRequired: true\n * }\n * }\n * }\n * }\n * }\n * ```\n *\n * The `echo` object is used to build the `echo' method that goes here:\n *\n * ```typescript\n * const client = generateClent()\n * const { data } = await client.queries.echo({input: 'a string'});\n * // ^\n * // |\n * // +-- This one right here.\n * //\n * ```\n *\n *\n * @param client The client to run graphql queries through.\n * @param modelIntrospection The model introspection schema the op comes from.\n * @param operationType The broad category of graphql operation.\n * @param operation The operation definition from the introspection schema.\n * @param useContext Whether the function needs to accept an SSR context.\n * @returns The operation function to attach to query, mutations, etc.\n */\nexport function customOpFactory(client, modelIntrospection, operationType, operation, useContext) {\n const opWithContext = async (contextSpec, arg, options) => {\n return _op(client, modelIntrospection, operationType, operation, arg, options, contextSpec);\n };\n const op = async (arg, options) => {\n return _op(client, modelIntrospection, operationType, operation, arg, options);\n };\n return useContext ? opWithContext : op;\n}\n/**\n * Runtime test and type guard to check whether `o[field]` is a `String`.\n *\n * ```typescript\n * if (hasStringField(o, 'prop')) {\n * const s = o.prop;\n * // ^? const s: string\n * }\n * ```\n *\n * @param o Object to inspect\n * @param field Field to look for\n * @returns Boolean: `true` if the `o[field]` is a `string`\n */\nfunction hasStringField(o, field) {\n return typeof o[field] === 'string';\n}\n/**\n * Generates \"outer\" arguments string for a custom operation. For example,\n * in this operation:\n *\n * ```graphql\n * query MyQuery(InputString: String!) {\n * echoString(InputString: $InputString)\n * }\n * ```\n *\n * This function returns the top/outer level arguments as a string:\n *\n * ```json\n * \"InputString: String!\"\n * ```\n *\n * @param operation Operation object from model introspection schema.\n * @returns \"outer\" arguments string\n */\nfunction outerArguments(operation) {\n const args = Object.entries(operation.arguments)\n .map(([k, v]) => {\n const baseType = v.type + (v.isRequired ? '!' : '');\n const finalType = v.isArray\n ? `[${baseType}]${v.isArrayNullable ? '' : '!'}`\n : baseType;\n return `$${k}: ${finalType}`;\n })\n .join(', ');\n return args.length > 0 ? `(${args})` : '';\n}\n/**\n * Generates \"inner\" arguments string for a custom operation. For example,\n * in this operation:\n *\n * ```graphql\n * query MyQuery(InputString: String!) {\n * echoString(InputString: $InputString)\n * }\n * ```\n *\n * This function returns the inner arguments as a string:\n *\n * ```json\n * \"InputString: $InputString\"\n * ```\n *\n * @param operation Operation object from model introspection schema.\n * @returns \"outer\" arguments string\n */\nfunction innerArguments(operation) {\n const args = Object.keys(operation.arguments)\n .map(k => `${k}: $${k}`)\n .join(', ');\n return args.length > 0 ? `(${args})` : '';\n}\n/**\n * Generates the selection set string for a custom operation. This is slightly\n * different than the selection set generation for models. If the custom op returns\n * a primitive or enum types, it doen't require a selection set at all.\n *\n * E.g., the graphql might look like this:\n *\n * ```graphql\n * query MyQuery {\n * echoString(inputString: \"whatever\")\n * }\n * # ^\n * # |\n * # +-- no selection set\n * ```\n *\n * Non-primitive return type selection set generation will be similar to other\n * model operations.\n *\n * @param modelIntrospection The full code-generated introspection schema.\n * @param operation The operation object from the schema.\n * @returns The selection set as a string.\n */\nfunction operationSelectionSet(modelIntrospection, operation) {\n if (hasStringField(operation, 'type') ||\n hasStringField(operation.type, 'enum')) {\n return '';\n }\n else if (hasStringField(operation.type, 'nonModel')) {\n const nonModel = modelIntrospection.nonModels[operation.type.nonModel];\n return `{${selectionSetIRToString(defaultSelectionSetForNonModelWithIR(nonModel, modelIntrospection))}}`;\n }\n else if (hasStringField(operation.type, 'model')) {\n return `{${generateSelectionSet(modelIntrospection, operation.type.model)}}`;\n }\n else {\n return '';\n }\n}\n/**\n * Maps an arguments objec to graphql variables, removing superfluous args and\n * screaming loudly when required args are missing.\n *\n * @param operation The operation to construct graphql request variables for.\n * @param args The arguments to map variables from.\n * @returns The graphql variables object.\n */\nfunction operationVariables(operation, args = {}) {\n const variables = {};\n for (const argDef of Object.values(operation.arguments)) {\n if (typeof args[argDef.name] !== 'undefined') {\n variables[argDef.name] = args[argDef.name];\n }\n else if (argDef.isRequired) {\n // At this point, the variable is both required and missing: We don't need\n // to continue. The operation is expected to fail.\n throw new Error(`${operation.name} requires arguments '${argDef.name}'`);\n }\n }\n return variables;\n}\n/**\n * Executes an operation from the given model intro schema against a client, returning\n * a fully instantiated model when relevant.\n *\n * @param client The client to operate `graphql()` calls through.\n * @param modelIntrospection The model intro schema to construct requests from.\n * @param operationType The high level graphql operation type.\n * @param operation The specific operation name, args, return type details.\n * @param args The arguments to provide to the operation as variables.\n * @param options Request options like headers, etc.\n * @param context SSR context if relevant.\n * @returns Result from the graphql request, model-instantiated when relevant.\n */\nasync function _op(client, modelIntrospection, operationType, operation, args, options, context) {\n const { name: operationName } = operation;\n const auth = authModeParams(client, options);\n const headers = getCustomHeaders(client, options?.headers);\n const outerArgsString = outerArguments(operation);\n const innerArgsString = innerArguments(operation);\n const selectionSet = operationSelectionSet(modelIntrospection, operation);\n const returnTypeModelName = hasStringField(operation.type, 'model')\n ? operation.type.model\n : undefined;\n const query = `\n\t\t${operationType.toLocaleLowerCase()}${outerArgsString} {\n\t\t\t${operationName}${innerArgsString} ${selectionSet}\n\t\t}\n\t`;\n const variables = operationVariables(operation, args);\n try {\n const { data, extensions } = context\n ? (await client.graphql(context, {\n ...auth,\n query,\n variables,\n }, headers))\n : (await client.graphql({\n ...auth,\n query,\n variables,\n }, headers));\n // flatten response\n if (data) {\n const [key] = Object.keys(data);\n const flattenedResult = flattenItems(data)[key];\n // TODO: custom selection set. current selection set is default selection set only\n // custom selection set requires data-schema-type + runtime updates above.\n const [initialized] = returnTypeModelName\n ? initializeModel(client, returnTypeModelName, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context)\n : [flattenedResult];\n return { data: initialized, extensions };\n }\n else {\n return { data: null, extensions };\n }\n }\n catch (error) {\n if (error.errors) {\n // graphql errors pass through\n return error;\n }\n else {\n // non-graphql errors re re-thrown\n throw error;\n }\n }\n}\n"],"names":[],"mappings":";;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,eAAe,CAAC,MAAM,EAAE,kBAAkB,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE;AAClG,IAAI,MAAM,aAAa,GAAG,OAAO,WAAW,EAAE,GAAG,EAAE,OAAO,KAAK;AAC/D,QAAQ,OAAO,GAAG,CAAC,MAAM,EAAE,kBAAkB,EAAE,aAAa,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;AACpG,KAAK,CAAC;AACN,IAAI,MAAM,EAAE,GAAG,OAAO,GAAG,EAAE,OAAO,KAAK;AACvC,QAAQ,OAAO,GAAG,CAAC,MAAM,EAAE,kBAAkB,EAAE,aAAa,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,CAAC,CAAC;AACvF,KAAK,CAAC;AACN,IAAI,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,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC;AAC/I,kBAAkB,CAAC,eAAe,CAAC,CAAC;AACpC,YAAY,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC;AACrD,SAAS;AACT,aAAa;AACb,YAAY,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;AAC9C,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,IAAI,KAAK,CAAC,MAAM,EAAE;AAC1B;AACA,YAAY,OAAO,KAAK,CAAC;AACzB,SAAS;AACT,aAAa;AACb;AACA,YAAY,MAAM,KAAK,CAAC;AACxB,SAAS;AACT,KAAK;AACL;;;;"}
|
|
1
|
+
{"version":3,"file":"custom.mjs","sources":["../../../../src/internals/operations/custom.ts"],"sourcesContent":["import { map } from 'rxjs';\nimport { authModeParams, defaultSelectionSetForNonModelWithIR, flattenItems, generateSelectionSet, getCustomHeaders, initializeModel, selectionSetIRToString, } from '../APIClient';\n/**\n * Type guard for checking whether a Custom Operation argument is a contextSpec object\n */\nconst argIsContextSpec = (arg) => {\n return typeof arg?.token?.value === 'symbol';\n};\n/**\n * Builds an operation function, embedded with all client and context data, that\n * can be attached to a client as a custom query or mutation.\n *\n * If we have this source schema:\n *\n * ```typescript\n * a.schema({\n * echo: a.query()\n * .arguments({input: a.string().required()})\n * .returns(a.string())\n * })\n * ```\n *\n * Our model intro schema will contain an entry like this:\n *\n * ```ts\n * {\n * queries: {\n * echo: {\n * name: \"echo\",\n * isArray: false,\n * type: 'String',\n * isRequired: false,\n * arguments: {\n * input: {\n * name: 'input',\n * isArray: false,\n * type: String,\n * isRequired: true\n * }\n * }\n * }\n * }\n * }\n * ```\n *\n * The `echo` object is used to build the `echo' method that goes here:\n *\n * ```typescript\n * const client = generateClent()\n * const { data } = await client.queries.echo({input: 'a string'});\n * // ^\n * // |\n * // +-- This one right here.\n * //\n * ```\n *\n *\n * @param client The client to run graphql queries through.\n * @param modelIntrospection The model introspection schema the op comes from.\n * @param operationType The broad category of graphql operation.\n * @param operation The operation definition from the introspection schema.\n * @param useContext Whether the function needs to accept an SSR context.\n * @returns The operation function to attach to query, mutations, etc.\n */\nexport function customOpFactory(client, modelIntrospection, operationType, operation, useContext) {\n // .arguments() are defined for the custom operation in the schema builder\n // and are present in the model introspection schema\n const argsDefined = operation.arguments !== undefined;\n const op = (...args) => {\n // options is always the last argument\n const options = args[args.length - 1];\n let contextSpec;\n let arg;\n if (useContext) {\n if (argIsContextSpec(args[0])) {\n contextSpec = args[0];\n }\n else {\n throw new Error(`Invalid first argument passed to ${operation.name}. Expected contextSpec`);\n }\n }\n if (argsDefined) {\n if (useContext) {\n arg = args[1];\n }\n else {\n arg = args[0];\n }\n }\n if (operationType === 'subscription') {\n return _opSubscription(\n // subscriptions are only enabled on the clientside\n client, modelIntrospection, operation, arg, options);\n }\n return _op(client, modelIntrospection, operationType, operation, arg, options, contextSpec);\n };\n return op;\n}\n/**\n * Runtime test and type guard to check whether `o[field]` is a `String`.\n *\n * ```typescript\n * if (hasStringField(o, 'prop')) {\n * const s = o.prop;\n * // ^? const s: string\n * }\n * ```\n *\n * @param o Object to inspect\n * @param field Field to look for\n * @returns Boolean: `true` if the `o[field]` is a `string`\n */\nfunction hasStringField(o, field) {\n return typeof o[field] === 'string';\n}\n/**\n * Generates \"outer\" arguments string for a custom operation. For example,\n * in this operation:\n *\n * ```graphql\n * query MyQuery(InputString: String!) {\n * echoString(InputString: $InputString)\n * }\n * ```\n *\n * This function returns the top/outer level arguments as a string:\n *\n * ```json\n * \"InputString: String!\"\n * ```\n *\n * @param operation Operation object from model introspection schema.\n * @returns \"outer\" arguments string\n */\nfunction outerArguments(operation) {\n if (operation.arguments === undefined) {\n return '';\n }\n const args = Object.entries(operation.arguments)\n .map(([k, v]) => {\n const baseType = v.type + (v.isRequired ? '!' : '');\n const finalType = v.isArray\n ? `[${baseType}]${v.isArrayNullable ? '' : '!'}`\n : baseType;\n return `$${k}: ${finalType}`;\n })\n .join(', ');\n return args.length > 0 ? `(${args})` : '';\n}\n/**\n * Generates \"inner\" arguments string for a custom operation. For example,\n * in this operation:\n *\n * ```graphql\n * query MyQuery(InputString: String!) {\n * echoString(InputString: $InputString)\n * }\n * ```\n *\n * This function returns the inner arguments as a string:\n *\n * ```json\n * \"InputString: $InputString\"\n * ```\n *\n * @param operation Operation object from model introspection schema.\n * @returns \"outer\" arguments string\n */\nfunction innerArguments(operation) {\n if (operation.arguments === undefined) {\n return '';\n }\n const args = Object.keys(operation.arguments)\n .map(k => `${k}: $${k}`)\n .join(', ');\n return args.length > 0 ? `(${args})` : '';\n}\n/**\n * Generates the selection set string for a custom operation. This is slightly\n * different than the selection set generation for models. If the custom op returns\n * a primitive or enum types, it doen't require a selection set at all.\n *\n * E.g., the graphql might look like this:\n *\n * ```graphql\n * query MyQuery {\n * echoString(inputString: \"whatever\")\n * }\n * # ^\n * # |\n * # +-- no selection set\n * ```\n *\n * Non-primitive return type selection set generation will be similar to other\n * model operations.\n *\n * @param modelIntrospection The full code-generated introspection schema.\n * @param operation The operation object from the schema.\n * @returns The selection set as a string.\n */\nfunction operationSelectionSet(modelIntrospection, operation) {\n if (hasStringField(operation, 'type') ||\n hasStringField(operation.type, 'enum')) {\n return '';\n }\n else if (hasStringField(operation.type, 'nonModel')) {\n const nonModel = modelIntrospection.nonModels[operation.type.nonModel];\n return `{${selectionSetIRToString(defaultSelectionSetForNonModelWithIR(nonModel, modelIntrospection))}}`;\n }\n else if (hasStringField(operation.type, 'model')) {\n return `{${generateSelectionSet(modelIntrospection, operation.type.model)}}`;\n }\n else {\n return '';\n }\n}\n/**\n * Maps an arguments objec to graphql variables, removing superfluous args and\n * screaming loudly when required args are missing.\n *\n * @param operation The operation to construct graphql request variables for.\n * @param args The arguments to map variables from.\n * @returns The graphql variables object.\n */\nfunction operationVariables(operation, args = {}) {\n const variables = {};\n if (operation.arguments === undefined) {\n return variables;\n }\n for (const argDef of Object.values(operation.arguments)) {\n if (typeof args[argDef.name] !== 'undefined') {\n variables[argDef.name] = args[argDef.name];\n }\n else if (argDef.isRequired) {\n // At this point, the variable is both required and missing: We don't need\n // to continue. The operation is expected to fail.\n throw new Error(`${operation.name} requires arguments '${argDef.name}'`);\n }\n }\n return variables;\n}\n/**\n * Executes an operation from the given model intro schema against a client, returning\n * a fully instantiated model when relevant.\n *\n * @param client The client to operate `graphql()` calls through.\n * @param modelIntrospection The model intro schema to construct requests from.\n * @param operationType The high level graphql operation type.\n * @param operation The specific operation name, args, return type details.\n * @param args The arguments to provide to the operation as variables.\n * @param options Request options like headers, etc.\n * @param context SSR context if relevant.\n * @returns Result from the graphql request, model-instantiated when relevant.\n */\nasync function _op(client, modelIntrospection, operationType, operation, args, options, context) {\n const { name: operationName } = operation;\n const auth = authModeParams(client, options);\n const headers = getCustomHeaders(client, options?.headers);\n const outerArgsString = outerArguments(operation);\n const innerArgsString = innerArguments(operation);\n const selectionSet = operationSelectionSet(modelIntrospection, operation);\n const returnTypeModelName = hasStringField(operation.type, 'model')\n ? operation.type.model\n : undefined;\n const query = `\n\t\t${operationType.toLocaleLowerCase()}${outerArgsString} {\n\t\t\t${operationName}${innerArgsString} ${selectionSet}\n\t\t}\n\t`;\n const variables = operationVariables(operation, args);\n try {\n const { data, extensions } = context\n ? (await client.graphql(context, {\n ...auth,\n query,\n variables,\n }, headers))\n : (await client.graphql({\n ...auth,\n query,\n variables,\n }, headers));\n // flatten response\n if (data) {\n const [key] = Object.keys(data);\n const flattenedResult = flattenItems(data)[key];\n // TODO: custom selection set. current selection set is default selection set only\n // custom selection set requires data-schema-type + runtime updates above.\n const [initialized] = returnTypeModelName\n ? initializeModel(client, returnTypeModelName, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context)\n : [flattenedResult];\n return { data: initialized, extensions };\n }\n else {\n return { data: null, extensions };\n }\n }\n catch (error) {\n if (error.errors) {\n // graphql errors pass through\n return error;\n }\n else {\n // non-graphql errors re re-thrown\n throw error;\n }\n }\n}\n/**\n * Executes an operation from the given model intro schema against a client, returning\n * a fully instantiated model when relevant.\n *\n * @param client The client to operate `graphql()` calls through.\n * @param modelIntrospection The model intro schema to construct requests from.\n * @param operation The specific operation name, args, return type details.\n * @param args The arguments to provide to the operation as variables.\n * @param options Request options like headers, etc.\n * @returns Result from the graphql request, model-instantiated when relevant.\n */\nfunction _opSubscription(client, modelIntrospection, operation, args, options) {\n const operationType = 'subscription';\n const { name: operationName } = operation;\n const auth = authModeParams(client, options);\n const headers = getCustomHeaders(client, options?.headers);\n const outerArgsString = outerArguments(operation);\n const innerArgsString = innerArguments(operation);\n const selectionSet = operationSelectionSet(modelIntrospection, operation);\n const returnTypeModelName = hasStringField(operation.type, 'model')\n ? operation.type.model\n : undefined;\n const query = `\n\t\t${operationType.toLocaleLowerCase()}${outerArgsString} {\n\t\t\t${operationName}${innerArgsString} ${selectionSet}\n\t\t}\n\t`;\n const variables = operationVariables(operation, args);\n const observable = client.graphql({\n ...auth,\n query,\n variables,\n }, headers);\n return observable.pipe(map(value => {\n const [key] = Object.keys(value.data);\n const data = value.data[key];\n const [initialized] = returnTypeModelName\n ? initializeModel(client, returnTypeModelName, [data], modelIntrospection, auth.authMode, auth.authToken)\n : [data];\n return initialized;\n }));\n}\n"],"names":[],"mappings":";;;AAEA;AACA;AACA;AACA,MAAM,gBAAgB,GAAG,CAAC,GAAG,KAAK;AAClC,IAAI,OAAO,OAAO,GAAG,EAAE,KAAK,EAAE,KAAK,KAAK,QAAQ,CAAC;AACjD,CAAC,CAAC;AACF;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;AAC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
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import { ModelTypes } from '@aws-amplify/data-schema-types';
|
|
1
2
|
import { ServerClientGenerationParams, V6ClientSSRCookies, V6ClientSSRRequest } from '../../types/';
|
|
2
|
-
export declare function generateModelsProperty<
|
|
3
|
+
export declare function generateModelsProperty<T extends Record<any, any> = never, ClientType extends V6ClientSSRRequest<Record<string, any>> | V6ClientSSRCookies<Record<string, any>> = V6ClientSSRCookies<Record<string, any>>>(client: ClientType, params: ServerClientGenerationParams): ModelTypes<T> | ModelTypes<never>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ModelTypes } from '@aws-amplify/data-schema-types';
|
|
2
2
|
import { GraphQLProviderConfig } from '@aws-amplify/core/internals/utils';
|
|
3
3
|
import { V6Client } from '../../../types';
|
|
4
|
-
export declare function generateModelsProperty<T extends Record<any, any> = never>(client: V6Client<Record<string, any>>, apiGraphQLConfig: GraphQLProviderConfig['GraphQL']): ModelTypes<T>;
|
|
4
|
+
export declare function generateModelsProperty<T extends Record<any, any> = never>(client: V6Client<Record<string, any>>, apiGraphQLConfig: GraphQLProviderConfig['GraphQL']): ModelTypes<T> | ModelTypes<never>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AmplifyClassV6, ResourcesConfig } from '@aws-amplify/core';
|
|
2
|
-
import { CustomHeaders, CustomMutations, CustomQueries, EnumTypes, ModelTypes } from '@aws-amplify/data-schema-types';
|
|
2
|
+
import { CustomHeaders, CustomMutations, CustomQueries, CustomSubscriptions, EnumTypes, ModelTypes } from '@aws-amplify/data-schema-types';
|
|
3
3
|
import { DocumentNode, GraphQLError, Source } from 'graphql';
|
|
4
4
|
import { Observable } from 'rxjs';
|
|
5
5
|
import { DocumentType, GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
|
|
@@ -295,6 +295,7 @@ export type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
|
|
|
295
295
|
enums: EnumTypes<T>;
|
|
296
296
|
queries: CustomQueries<T>;
|
|
297
297
|
mutations: CustomMutations<T>;
|
|
298
|
+
subscriptions: CustomSubscriptions<T>;
|
|
298
299
|
}>;
|
|
299
300
|
export type V6ClientSSRRequest<T extends Record<any, any> = never> = ExcludeNeverFields<{
|
|
300
301
|
[__amplify]: AmplifyClassV6;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/api-graphql",
|
|
3
|
-
"version": "4.0.22-unstable.
|
|
3
|
+
"version": "4.0.22-unstable.2b71e29.0+2b71e29",
|
|
4
4
|
"description": "Api-graphql category of aws-amplify",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.mjs",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
},
|
|
73
73
|
"homepage": "https://aws-amplify.github.io/",
|
|
74
74
|
"devDependencies": {
|
|
75
|
-
"@aws-amplify/data-schema": "^0.
|
|
75
|
+
"@aws-amplify/data-schema": "^0.14.1",
|
|
76
76
|
"@rollup/plugin-typescript": "11.1.5",
|
|
77
77
|
"rollup": "^4.9.6",
|
|
78
78
|
"typescript": "5.0.2"
|
|
@@ -85,9 +85,9 @@
|
|
|
85
85
|
"server"
|
|
86
86
|
],
|
|
87
87
|
"dependencies": {
|
|
88
|
-
"@aws-amplify/api-rest": "4.0.22-unstable.
|
|
89
|
-
"@aws-amplify/core": "6.0.22-unstable.
|
|
90
|
-
"@aws-amplify/data-schema-types": "^0.7.
|
|
88
|
+
"@aws-amplify/api-rest": "4.0.22-unstable.2b71e29.0+2b71e29",
|
|
89
|
+
"@aws-amplify/core": "6.0.22-unstable.2b71e29.0+2b71e29",
|
|
90
|
+
"@aws-amplify/data-schema-types": "^0.7.11",
|
|
91
91
|
"@aws-sdk/types": "3.387.0",
|
|
92
92
|
"graphql": "15.8.0",
|
|
93
93
|
"rxjs": "^7.8.1",
|
|
@@ -102,5 +102,5 @@
|
|
|
102
102
|
"limit": "91.7 kB"
|
|
103
103
|
}
|
|
104
104
|
],
|
|
105
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "2b71e29d50204f037b1dae2007291c54d1ec8c19"
|
|
106
106
|
}
|
|
@@ -19,7 +19,6 @@ import {
|
|
|
19
19
|
ListArgs,
|
|
20
20
|
QueryArgs,
|
|
21
21
|
V6Client,
|
|
22
|
-
V6ClientSSRRequest,
|
|
23
22
|
__authMode,
|
|
24
23
|
__authToken,
|
|
25
24
|
__headers,
|
|
@@ -138,9 +137,7 @@ export function initializeModel(
|
|
|
138
137
|
options?: LazyLoadOptions,
|
|
139
138
|
) => {
|
|
140
139
|
if (record[targetNames[0]]) {
|
|
141
|
-
return (
|
|
142
|
-
client as V6ClientSSRRequest<Record<string, any>>
|
|
143
|
-
).models[relatedModelName].get(
|
|
140
|
+
return (client as any).models[relatedModelName].get(
|
|
144
141
|
contextSpec,
|
|
145
142
|
{
|
|
146
143
|
[relatedModelPKFieldName]: record[targetNames[0]],
|
|
@@ -160,9 +157,7 @@ export function initializeModel(
|
|
|
160
157
|
options?: LazyLoadOptions,
|
|
161
158
|
) => {
|
|
162
159
|
if (record[targetNames[0]]) {
|
|
163
|
-
return (client as
|
|
164
|
-
relatedModelName
|
|
165
|
-
].get(
|
|
160
|
+
return (client as any).models[relatedModelName].get(
|
|
166
161
|
{
|
|
167
162
|
[relatedModelPKFieldName]: record[targetNames[0]],
|
|
168
163
|
...sortKeyValues,
|
|
@@ -213,15 +208,16 @@ export function initializeModel(
|
|
|
213
208
|
options?: LazyLoadOptions,
|
|
214
209
|
) => {
|
|
215
210
|
if (record[parentPk]) {
|
|
216
|
-
return (
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
211
|
+
return (client as any).models[relatedModelName].list(
|
|
212
|
+
contextSpec,
|
|
213
|
+
{
|
|
214
|
+
filter: { and: hasManyFilter },
|
|
215
|
+
limit: options?.limit,
|
|
216
|
+
nextToken: options?.nextToken,
|
|
217
|
+
authMode: options?.authMode || authMode,
|
|
218
|
+
authToken: options?.authToken || authToken,
|
|
219
|
+
},
|
|
220
|
+
);
|
|
225
221
|
}
|
|
226
222
|
|
|
227
223
|
return [];
|
|
@@ -231,9 +227,7 @@ export function initializeModel(
|
|
|
231
227
|
options?: LazyLoadOptions,
|
|
232
228
|
) => {
|
|
233
229
|
if (record[parentPk]) {
|
|
234
|
-
return (client as
|
|
235
|
-
relatedModelName
|
|
236
|
-
].list({
|
|
230
|
+
return (client as any).models[relatedModelName].list({
|
|
237
231
|
filter: { and: hasManyFilter },
|
|
238
232
|
limit: options?.limit,
|
|
239
233
|
nextToken: options?.nextToken,
|
|
@@ -265,15 +259,16 @@ export function initializeModel(
|
|
|
265
259
|
options?: LazyLoadOptions,
|
|
266
260
|
) => {
|
|
267
261
|
if (record[parentPk]) {
|
|
268
|
-
return (
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
262
|
+
return (client as any).models[relatedModelName].list(
|
|
263
|
+
contextSpec,
|
|
264
|
+
{
|
|
265
|
+
filter: { and: hasManyFilter },
|
|
266
|
+
limit: options?.limit,
|
|
267
|
+
nextToken: options?.nextToken,
|
|
268
|
+
authMode: options?.authMode || authMode,
|
|
269
|
+
authToken: options?.authToken || authToken,
|
|
270
|
+
},
|
|
271
|
+
);
|
|
277
272
|
}
|
|
278
273
|
|
|
279
274
|
return [];
|
|
@@ -283,9 +278,7 @@ export function initializeModel(
|
|
|
283
278
|
options?: LazyLoadOptions,
|
|
284
279
|
) => {
|
|
285
280
|
if (record[parentPk]) {
|
|
286
|
-
return (client as
|
|
287
|
-
relatedModelName
|
|
288
|
-
].list({
|
|
281
|
+
return (client as any).models[relatedModelName].list({
|
|
289
282
|
filter: { and: hasManyFilter },
|
|
290
283
|
limit: options?.limit,
|
|
291
284
|
nextToken: options?.nextToken,
|
|
@@ -4,6 +4,7 @@ import { Hub } from '@aws-amplify/core';
|
|
|
4
4
|
import {
|
|
5
5
|
CustomMutations,
|
|
6
6
|
CustomQueries,
|
|
7
|
+
CustomSubscriptions,
|
|
7
8
|
EnumTypes,
|
|
8
9
|
ModelTypes,
|
|
9
10
|
} from '@aws-amplify/data-schema-types';
|
|
@@ -23,6 +24,7 @@ import { isApiGraphQLConfig } from './utils/runtimeTypeGuards/isApiGraphQLProvid
|
|
|
23
24
|
import {
|
|
24
25
|
generateCustomMutationsProperty,
|
|
25
26
|
generateCustomQueriesProperty,
|
|
27
|
+
generateCustomSubscriptionsProperty,
|
|
26
28
|
} from './generateCustomOperationsProperty';
|
|
27
29
|
import { ClientGenerationParams } from './types';
|
|
28
30
|
import { isConfigureEventWithResourceConfig } from './utils/runtimeTypeGuards/isConfigureEventWithResourceConfig';
|
|
@@ -51,6 +53,7 @@ export function generateClient<T extends Record<any, any> = never>(
|
|
|
51
53
|
enums: emptyProperty as EnumTypes<never>,
|
|
52
54
|
queries: emptyProperty as CustomQueries<never>,
|
|
53
55
|
mutations: emptyProperty as CustomMutations<never>,
|
|
56
|
+
subscriptions: emptyProperty as CustomSubscriptions<never>,
|
|
54
57
|
} as any;
|
|
55
58
|
|
|
56
59
|
const apiGraphqlConfig = params.amplify.getConfig().API?.GraphQL;
|
|
@@ -63,6 +66,10 @@ export function generateClient<T extends Record<any, any> = never>(
|
|
|
63
66
|
client,
|
|
64
67
|
apiGraphqlConfig,
|
|
65
68
|
);
|
|
69
|
+
client.subscriptions = generateCustomSubscriptionsProperty(
|
|
70
|
+
client,
|
|
71
|
+
apiGraphqlConfig,
|
|
72
|
+
);
|
|
66
73
|
} else {
|
|
67
74
|
// This happens when the `Amplify.configure()` call gets evaluated after the `generateClient()` call.
|
|
68
75
|
//
|
|
@@ -101,6 +108,10 @@ const generateModelsPropertyOnAmplifyConfigure = (clientRef: any) => {
|
|
|
101
108
|
clientRef,
|
|
102
109
|
apiGraphQLConfig,
|
|
103
110
|
);
|
|
111
|
+
clientRef.subscriptions = generateCustomSubscriptionsProperty(
|
|
112
|
+
clientRef,
|
|
113
|
+
apiGraphQLConfig,
|
|
114
|
+
);
|
|
104
115
|
}
|
|
105
116
|
});
|
|
106
117
|
};
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
CustomMutations,
|
|
5
|
+
CustomQueries,
|
|
6
|
+
CustomSubscriptions,
|
|
7
|
+
} from '@aws-amplify/data-schema-types';
|
|
4
8
|
import {
|
|
5
9
|
GraphQLProviderConfig,
|
|
6
10
|
ModelIntrospectionSchema,
|
|
@@ -10,16 +14,23 @@ import { V6Client, __amplify } from '../types';
|
|
|
10
14
|
|
|
11
15
|
import { customOpFactory } from './operations/custom';
|
|
12
16
|
|
|
13
|
-
type OpTypes = 'queries' | 'mutations';
|
|
17
|
+
type OpTypes = 'queries' | 'mutations' | 'subscriptions';
|
|
14
18
|
|
|
15
19
|
type CustomOpsProperty<
|
|
16
20
|
T extends Record<any, any>,
|
|
17
21
|
OpType extends OpTypes,
|
|
18
|
-
> = OpType extends 'queries'
|
|
22
|
+
> = OpType extends 'queries'
|
|
23
|
+
? CustomQueries<T>
|
|
24
|
+
: OpType extends 'mutations'
|
|
25
|
+
? CustomMutations<T>
|
|
26
|
+
: OpType extends 'subscriptions'
|
|
27
|
+
? CustomSubscriptions<T>
|
|
28
|
+
: never;
|
|
19
29
|
|
|
20
30
|
const operationTypeMap = {
|
|
21
31
|
queries: 'query',
|
|
22
32
|
mutations: 'mutation',
|
|
33
|
+
subscriptions: 'subscription',
|
|
23
34
|
} as const;
|
|
24
35
|
|
|
25
36
|
export function generateCustomOperationsProperty<
|
|
@@ -88,3 +99,14 @@ export function generateCustomQueriesProperty<T extends Record<any, any>>(
|
|
|
88
99
|
'queries',
|
|
89
100
|
);
|
|
90
101
|
}
|
|
102
|
+
|
|
103
|
+
export function generateCustomSubscriptionsProperty<T extends Record<any, any>>(
|
|
104
|
+
client: V6Client<Record<string, any>>,
|
|
105
|
+
config: GraphQLProviderConfig['GraphQL'],
|
|
106
|
+
) {
|
|
107
|
+
return generateCustomOperationsProperty<T, 'subscriptions'>(
|
|
108
|
+
client,
|
|
109
|
+
config,
|
|
110
|
+
'subscriptions',
|
|
111
|
+
);
|
|
112
|
+
}
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
CustomOperation,
|
|
6
6
|
ModelIntrospectionSchema,
|
|
7
7
|
} from '@aws-amplify/core/internals/utils';
|
|
8
|
+
import { map } from 'rxjs';
|
|
8
9
|
|
|
9
10
|
import {
|
|
10
11
|
authModeParams,
|
|
@@ -18,14 +19,36 @@ import {
|
|
|
18
19
|
import {
|
|
19
20
|
AuthModeParams,
|
|
20
21
|
ClientWithModels,
|
|
21
|
-
GraphQLOptionsV6,
|
|
22
22
|
GraphQLResult,
|
|
23
|
+
GraphqlSubscriptionResult,
|
|
23
24
|
ListArgs,
|
|
24
25
|
QueryArgs,
|
|
25
26
|
V6Client,
|
|
26
27
|
V6ClientSSRRequest,
|
|
27
28
|
} from '../../types';
|
|
28
29
|
|
|
30
|
+
type CustomOperationOptions = AuthModeParams & ListArgs;
|
|
31
|
+
|
|
32
|
+
// these are the 4 possible sets of arguments custom operations methods can receive
|
|
33
|
+
type OpArgs =
|
|
34
|
+
// SSR Request Client w Args defined
|
|
35
|
+
| [AmplifyServer.ContextSpec, QueryArgs, CustomOperationOptions]
|
|
36
|
+
// SSR Request Client without Args defined
|
|
37
|
+
| [AmplifyServer.ContextSpec, CustomOperationOptions]
|
|
38
|
+
// Client or SSR Cookies Client w Args defined
|
|
39
|
+
| [QueryArgs, CustomOperationOptions]
|
|
40
|
+
// Client or SSR Cookies Client without Args defined
|
|
41
|
+
| [CustomOperationOptions];
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Type guard for checking whether a Custom Operation argument is a contextSpec object
|
|
45
|
+
*/
|
|
46
|
+
const argIsContextSpec = (
|
|
47
|
+
arg: OpArgs[number],
|
|
48
|
+
): arg is AmplifyServer.ContextSpec => {
|
|
49
|
+
return typeof (arg as AmplifyServer.ContextSpec)?.token?.value === 'symbol';
|
|
50
|
+
};
|
|
51
|
+
|
|
29
52
|
/**
|
|
30
53
|
* Builds an operation function, embedded with all client and context data, that
|
|
31
54
|
* can be attached to a client as a custom query or mutation.
|
|
@@ -85,27 +108,50 @@ import {
|
|
|
85
108
|
export function customOpFactory(
|
|
86
109
|
client: ClientWithModels,
|
|
87
110
|
modelIntrospection: ModelIntrospectionSchema,
|
|
88
|
-
operationType: 'query' | 'mutation',
|
|
111
|
+
operationType: 'query' | 'mutation' | 'subscription',
|
|
89
112
|
operation: CustomOperation,
|
|
90
113
|
useContext: boolean,
|
|
91
114
|
) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
) => {
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
115
|
+
// .arguments() are defined for the custom operation in the schema builder
|
|
116
|
+
// and are present in the model introspection schema
|
|
117
|
+
const argsDefined = operation.arguments !== undefined;
|
|
118
|
+
|
|
119
|
+
const op = (...args: OpArgs) => {
|
|
120
|
+
// options is always the last argument
|
|
121
|
+
const options = args[args.length - 1] as CustomOperationOptions;
|
|
122
|
+
|
|
123
|
+
let contextSpec: AmplifyServer.ContextSpec | undefined;
|
|
124
|
+
let arg: QueryArgs | undefined;
|
|
125
|
+
|
|
126
|
+
if (useContext) {
|
|
127
|
+
if (argIsContextSpec(args[0])) {
|
|
128
|
+
contextSpec = args[0];
|
|
129
|
+
} else {
|
|
130
|
+
throw new Error(
|
|
131
|
+
`Invalid first argument passed to ${operation.name}. Expected contextSpec`,
|
|
132
|
+
);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
if (argsDefined) {
|
|
137
|
+
if (useContext) {
|
|
138
|
+
arg = args[1] as QueryArgs;
|
|
139
|
+
} else {
|
|
140
|
+
arg = args[0] as QueryArgs;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (operationType === 'subscription') {
|
|
145
|
+
return _opSubscription(
|
|
146
|
+
// subscriptions are only enabled on the clientside
|
|
147
|
+
client as V6Client<Record<string, any>>,
|
|
148
|
+
modelIntrospection,
|
|
149
|
+
operation,
|
|
150
|
+
arg,
|
|
151
|
+
options,
|
|
152
|
+
);
|
|
153
|
+
}
|
|
107
154
|
|
|
108
|
-
const op = async (arg?: QueryArgs, options?: AuthModeParams & ListArgs) => {
|
|
109
155
|
return _op(
|
|
110
156
|
client,
|
|
111
157
|
modelIntrospection,
|
|
@@ -113,10 +159,11 @@ export function customOpFactory(
|
|
|
113
159
|
operation,
|
|
114
160
|
arg,
|
|
115
161
|
options,
|
|
162
|
+
contextSpec,
|
|
116
163
|
);
|
|
117
164
|
};
|
|
118
165
|
|
|
119
|
-
return
|
|
166
|
+
return op;
|
|
120
167
|
}
|
|
121
168
|
|
|
122
169
|
/**
|
|
@@ -160,6 +207,9 @@ function hasStringField<Field extends string>(
|
|
|
160
207
|
* @returns "outer" arguments string
|
|
161
208
|
*/
|
|
162
209
|
function outerArguments(operation: CustomOperation): string {
|
|
210
|
+
if (operation.arguments === undefined) {
|
|
211
|
+
return '';
|
|
212
|
+
}
|
|
163
213
|
const args = Object.entries(operation.arguments)
|
|
164
214
|
.map(([k, v]) => {
|
|
165
215
|
const baseType = v.type + (v.isRequired ? '!' : '');
|
|
@@ -194,6 +244,9 @@ function outerArguments(operation: CustomOperation): string {
|
|
|
194
244
|
* @returns "outer" arguments string
|
|
195
245
|
*/
|
|
196
246
|
function innerArguments(operation: CustomOperation): string {
|
|
247
|
+
if (operation.arguments === undefined) {
|
|
248
|
+
return '';
|
|
249
|
+
}
|
|
197
250
|
const args = Object.keys(operation.arguments)
|
|
198
251
|
.map(k => `${k}: $${k}`)
|
|
199
252
|
.join(', ');
|
|
@@ -259,6 +312,9 @@ function operationVariables(
|
|
|
259
312
|
args: QueryArgs = {},
|
|
260
313
|
): Record<string, unknown> {
|
|
261
314
|
const variables = {} as Record<string, unknown>;
|
|
315
|
+
if (operation.arguments === undefined) {
|
|
316
|
+
return variables;
|
|
317
|
+
}
|
|
262
318
|
for (const argDef of Object.values(operation.arguments)) {
|
|
263
319
|
if (typeof args[argDef.name] !== 'undefined') {
|
|
264
320
|
variables[argDef.name] = args[argDef.name];
|
|
@@ -366,3 +422,71 @@ async function _op(
|
|
|
366
422
|
}
|
|
367
423
|
}
|
|
368
424
|
}
|
|
425
|
+
|
|
426
|
+
/**
|
|
427
|
+
* Executes an operation from the given model intro schema against a client, returning
|
|
428
|
+
* a fully instantiated model when relevant.
|
|
429
|
+
*
|
|
430
|
+
* @param client The client to operate `graphql()` calls through.
|
|
431
|
+
* @param modelIntrospection The model intro schema to construct requests from.
|
|
432
|
+
* @param operation The specific operation name, args, return type details.
|
|
433
|
+
* @param args The arguments to provide to the operation as variables.
|
|
434
|
+
* @param options Request options like headers, etc.
|
|
435
|
+
* @returns Result from the graphql request, model-instantiated when relevant.
|
|
436
|
+
*/
|
|
437
|
+
function _opSubscription(
|
|
438
|
+
client: V6Client<Record<string, any>>,
|
|
439
|
+
modelIntrospection: ModelIntrospectionSchema,
|
|
440
|
+
operation: CustomOperation,
|
|
441
|
+
args?: QueryArgs,
|
|
442
|
+
options?: AuthModeParams & ListArgs,
|
|
443
|
+
) {
|
|
444
|
+
const operationType = 'subscription';
|
|
445
|
+
const { name: operationName } = operation;
|
|
446
|
+
const auth = authModeParams(client, options);
|
|
447
|
+
const headers = getCustomHeaders(client, options?.headers);
|
|
448
|
+
const outerArgsString = outerArguments(operation);
|
|
449
|
+
const innerArgsString = innerArguments(operation);
|
|
450
|
+
const selectionSet = operationSelectionSet(modelIntrospection, operation);
|
|
451
|
+
|
|
452
|
+
const returnTypeModelName = hasStringField(operation.type, 'model')
|
|
453
|
+
? operation.type.model
|
|
454
|
+
: undefined;
|
|
455
|
+
|
|
456
|
+
const query = `
|
|
457
|
+
${operationType.toLocaleLowerCase()}${outerArgsString} {
|
|
458
|
+
${operationName}${innerArgsString} ${selectionSet}
|
|
459
|
+
}
|
|
460
|
+
`;
|
|
461
|
+
|
|
462
|
+
const variables = operationVariables(operation, args);
|
|
463
|
+
|
|
464
|
+
const observable = client.graphql(
|
|
465
|
+
{
|
|
466
|
+
...auth,
|
|
467
|
+
query,
|
|
468
|
+
variables,
|
|
469
|
+
},
|
|
470
|
+
headers,
|
|
471
|
+
) as GraphqlSubscriptionResult<object>;
|
|
472
|
+
|
|
473
|
+
return observable.pipe(
|
|
474
|
+
map(value => {
|
|
475
|
+
const [key] = Object.keys(value.data);
|
|
476
|
+
const data = (value.data as any)[key];
|
|
477
|
+
|
|
478
|
+
const [initialized] = returnTypeModelName
|
|
479
|
+
? initializeModel(
|
|
480
|
+
client as V6Client<Record<string, any>>,
|
|
481
|
+
returnTypeModelName,
|
|
482
|
+
[data],
|
|
483
|
+
modelIntrospection,
|
|
484
|
+
auth.authMode,
|
|
485
|
+
auth.authToken,
|
|
486
|
+
)
|
|
487
|
+
: [data];
|
|
488
|
+
|
|
489
|
+
return initialized;
|
|
490
|
+
}),
|
|
491
|
+
);
|
|
492
|
+
}
|
|
@@ -15,13 +15,16 @@ import { getFactory } from '../operations/get';
|
|
|
15
15
|
import { getSecondaryIndexesFromSchemaModel } from '../clientUtils';
|
|
16
16
|
|
|
17
17
|
export function generateModelsProperty<
|
|
18
|
-
|
|
18
|
+
T extends Record<any, any> = never,
|
|
19
19
|
ClientType extends
|
|
20
20
|
| V6ClientSSRRequest<Record<string, any>>
|
|
21
21
|
| V6ClientSSRCookies<Record<string, any>> = V6ClientSSRCookies<
|
|
22
22
|
Record<string, any>
|
|
23
23
|
>,
|
|
24
|
-
>(
|
|
24
|
+
>(
|
|
25
|
+
client: ClientType,
|
|
26
|
+
params: ServerClientGenerationParams,
|
|
27
|
+
): ModelTypes<T> | ModelTypes<never> {
|
|
25
28
|
const models = {} as any;
|
|
26
29
|
const { config } = params;
|
|
27
30
|
const useContext = params.amplify === null;
|
|
@@ -18,7 +18,7 @@ import { getSecondaryIndexesFromSchemaModel } from '../../clientUtils';
|
|
|
18
18
|
export function generateModelsProperty<T extends Record<any, any> = never>(
|
|
19
19
|
client: V6Client<Record<string, any>>,
|
|
20
20
|
apiGraphQLConfig: GraphQLProviderConfig['GraphQL'],
|
|
21
|
-
): ModelTypes<T> {
|
|
21
|
+
): ModelTypes<T> | ModelTypes<never> {
|
|
22
22
|
const models = {} as any;
|
|
23
23
|
|
|
24
24
|
const modelIntrospection: ModelIntrospectionSchema | undefined =
|
package/src/types/index.ts
CHANGED
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
CustomHeaders,
|
|
6
6
|
CustomMutations,
|
|
7
7
|
CustomQueries,
|
|
8
|
+
CustomSubscriptions,
|
|
8
9
|
EnumTypes,
|
|
9
10
|
ModelTypes,
|
|
10
11
|
} from '@aws-amplify/data-schema-types';
|
|
@@ -394,6 +395,7 @@ export type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
|
|
|
394
395
|
enums: EnumTypes<T>;
|
|
395
396
|
queries: CustomQueries<T>;
|
|
396
397
|
mutations: CustomMutations<T>;
|
|
398
|
+
subscriptions: CustomSubscriptions<T>;
|
|
397
399
|
}>;
|
|
398
400
|
|
|
399
401
|
export type V6ClientSSRRequest<T extends Record<any, any> = never> =
|