@aws-amplify/api-graphql 4.0.22-unstable.f6055cb.0 → 4.0.23-unstable.701f219.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.
Files changed (30) hide show
  1. package/dist/cjs/internals/generateClient.js +3 -0
  2. package/dist/cjs/internals/generateClient.js.map +1 -1
  3. package/dist/cjs/internals/generateCustomOperationsProperty.js +6 -1
  4. package/dist/cjs/internals/generateCustomOperationsProperty.js.map +1 -1
  5. package/dist/cjs/internals/operations/custom.js +88 -5
  6. package/dist/cjs/internals/operations/custom.js.map +1 -1
  7. package/dist/cjs/utils/resolveOwnerFields.js +3 -0
  8. package/dist/cjs/utils/resolveOwnerFields.js.map +1 -1
  9. package/dist/esm/internals/generateClient.mjs +4 -1
  10. package/dist/esm/internals/generateClient.mjs.map +1 -1
  11. package/dist/esm/internals/generateCustomOperationsProperty.d.ts +2 -1
  12. package/dist/esm/internals/generateCustomOperationsProperty.mjs +5 -1
  13. package/dist/esm/internals/generateCustomOperationsProperty.mjs.map +1 -1
  14. package/dist/esm/internals/operations/custom.d.ts +5 -2
  15. package/dist/esm/internals/operations/custom.mjs +88 -5
  16. package/dist/esm/internals/operations/custom.mjs.map +1 -1
  17. package/dist/esm/internals/server/generateModelsProperty.d.ts +2 -1
  18. package/dist/esm/internals/utils/clientProperties/generateModelsProperty.d.ts +1 -1
  19. package/dist/esm/types/index.d.ts +2 -1
  20. package/dist/esm/utils/resolveOwnerFields.mjs +3 -0
  21. package/dist/esm/utils/resolveOwnerFields.mjs.map +1 -1
  22. package/package.json +6 -6
  23. package/src/internals/APIClient.ts +24 -31
  24. package/src/internals/generateClient.ts +11 -0
  25. package/src/internals/generateCustomOperationsProperty.ts +25 -3
  26. package/src/internals/operations/custom.ts +143 -19
  27. package/src/internals/server/generateModelsProperty.ts +5 -2
  28. package/src/internals/utils/clientProperties/generateModelsProperty.ts +1 -1
  29. package/src/types/index.ts +2 -0
  30. package/src/utils/resolveOwnerFields.ts +11 -4
@@ -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,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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.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 miss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ACnB,SAAS;AACT,QAAQ,MAAM,gBAAgB,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,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;AACpI,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,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,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,OAAO,CAAC,SAAS,CAAC,KAAK,IAAI,CAAC;AAC1D,IAAI,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,EAAE;AACvD,QAAQ,GAAG,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,IAAI,QAAQ,CAAC,eAAe,EAAE,MAAM,EAAE,kBAAkB,EAAE,gBAAgB,CAAC,cAAc,CAAC,EAAE,SAAS,EAAE,UAAU,CAAC,CAAC;AACjJ,KAAK;AACL,IAAI,OAAO,GAAG,CAAC;AACf,CAAC;AACD,OAAO,CAAC,gCAAgC,GAAG,gCAAgC,CAAC;AAC5E,SAAS,+BAA+B,CAAC,MAAM,EAAE,MAAM,EAAE;AACzD,IAAI,OAAO,gCAAgC,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;AACzE,CAAC;AACD,OAAO,CAAC,+BAA+B,GAAG,+BAA+B,CAAC;AAC1E,SAAS,6BAA6B,CAAC,MAAM,EAAE,MAAM,EAAE;AACvD,IAAI,OAAO,gCAAgC,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;AACvE,CAAC;AACD,OAAO,CAAC,6BAA6B,GAAG,6BAA6B;;"}
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,M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M,EAAE,eAAe,CAAC,CAAC;AAC7E,CAAC;AACD,OAAO,CAAC,mCAAmC,GAAG,mCAAmC;;"}
@@ -2,7 +2,14 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.customOpFactory = void 0;
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
- const opWithContext = async (contextSpec, arg, options) => {
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
- const op = async (arg, options) => {
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;A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T,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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AAC,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;;"}
@@ -16,6 +16,9 @@ function resolveOwnerFields(model) {
16
16
  if (rule.allow === 'owner') {
17
17
  ownerFields.add(rule.ownerField || 'owner');
18
18
  }
19
+ else if (rule.allow === 'groups') {
20
+ ownerFields.add(rule.groupsField);
21
+ }
19
22
  }
20
23
  }
21
24
  }
@@ -1 +1 @@
1
- {"version":3,"file":"resolveOwnerFields.js","sources":["../../../src/utils/resolveOwnerFields.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.resolveOwnerFields = void 0;\n/**\n * Given an introspection schema model, returns all owner fields.\n *\n * @param model Model from an introspection schema\n * @returns List of owner field names\n */\nfunction resolveOwnerFields(model) {\n const ownerFields = new Set();\n for (const attr of model.attributes || []) {\n if (isAuthAttribute(attr)) {\n for (const rule of attr.properties.rules) {\n if (rule.allow === 'owner') {\n ownerFields.add(rule.ownerField || 'owner');\n }\n }\n }\n }\n return Array.from(ownerFields);\n}\nexports.resolveOwnerFields = resolveOwnerFields;\n/**\n * Type guard that identifies an auth attribute with an attached rules list that\n * specifies an `allow` attribute at a minimum.\n *\n * @param attribute Any object. Ideally a model introspection schema model attribute\n * @returns True if given object is an auth attribute\n */\nfunction isAuthAttribute(attribute) {\n if (attribute?.type === 'auth') {\n if (typeof attribute?.properties === 'object') {\n if (Array.isArray(attribute?.properties?.rules)) {\n return (attribute?.properties?.rules).every(rule => !!rule.allow);\n }\n }\n }\n return false;\n}\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE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sources":["../../../src/utils/resolveOwnerFields.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.resolveOwnerFields = void 0;\n/**\n * Given an introspection schema model, returns all owner fields.\n *\n * @param model Model from an introspection schema\n * @returns List of owner field names\n */\nfunction resolveOwnerFields(model) {\n const ownerFields = new Set();\n for (const attr of model.attributes || []) {\n if (isAuthAttribute(attr)) {\n for (const rule of attr.properties.rules) {\n if (rule.allow === 'owner') {\n ownerFields.add(rule.ownerField || 'owner');\n }\n else if (rule.allow === 'groups') {\n ownerFields.add(rule.groupsField);\n }\n }\n }\n }\n return Array.from(ownerFields);\n}\nexports.resolveOwnerFields = resolveOwnerFields;\n/**\n * Type guard that identifies an auth attribute with an attached rules list that\n * specifies an `allow` attribute at a minimum.\n *\n * @param attribute Any object. Ideally a model introspection schema model attribute\n * @returns True if given object is an auth attribute\n */\nfunction isAuthAttribute(attribute) {\n if (attribute?.type === 'auth') {\n if (typeof attribute?.properties === 'object') {\n if (Array.isArray(attribute?.properties?.rules)) {\n return (attribute?.properties?.rules).every(rule => !!rule.allow);\n }\n }\n }\n return false;\n}\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,kBAAkB,GAAG,KAAK,CAAC,CAAC;AACpC;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,kBAAkB,CAAC,KAAK,EAAE;AACnC,IAAI,MAAM,WAAW,GAAG,IAAI,GAAG,EAAE,CAAC;AAClC,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,CAAC,UAAU,IAAI,EAAE,EAAE;AAC/C,QAAQ,IAAI,eAAe,CAAC,IAAI,CAAC,EAAE;AACnC,YAAY,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE;AACtD,gBAAgB,IAAI,IAAI,CAAC,KAAK,KAAK,OAAO,EAAE;AAC5C,oBAAoB,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,UAAU,IAAI,OAAO,CAAC,CAAC;AAChE,iBAAiB;AACjB,qBAAqB,IAAI,IAAI,CAAC,KAAK,KAAK,QAAQ,EAAE;AAClD,oBAAoB,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACtD,iBAAiB;AACjB,aAAa;AACb,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;AACnC,CAAC;AACD,OAAO,CAAC,kBAAkB,GAAG,kBAAkB,CAAC;AAChD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,eAAe,CAAC,SAAS,EAAE;AACpC,IAAI,IAAI,SAAS,EAAE,IAAI,KAAK,MAAM,EAAE;AACpC,QAAQ,IAAI,OAAO,SAAS,EAAE,UAAU,KAAK,QAAQ,EAAE;AACvD,YAAY,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE;AAC7D,gBAAgB,OAAO,CAAC,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;AAClF,aAAa;AACb,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,CAAC;AACjB;;"}
@@ -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,GAAG,EAAE,OAAO,CAAC;AACrE,IAAI,IAAI,kBAAkB,CAAC,gBAAgB,CAAC,EAAE;AAC9C,QAAQ,MAAM,CAAC,MAAM,GAAG,sBAAsB,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AACzE,QAAQ,MAAM,CAAC,KAAK,GAAG,qBAAqB,CAAC,gBAAgB,CAAC,CAAC;AAC/D,QAAQ,MAAM,CAAC,OAAO,GAAG,6BAA6B,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AACjF,QAAQ,MAAM,CAAC,SAAS,GAAG,+BAA+B,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AACrF,KAAK;AACL,SAAS;AACT;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ,wCAAwC,CAAC,MAAM,CAAC,CAAC;AACzD,KAAK;AACL,IAAI,OAAO,MAAM,CAAC;AAClB,CAAC;AACD,MAAM,wCAAwC,GAAG,CAAC,SAAS,KAAK;AAChE,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,IAAI;AACpC,QAAQ,IAAI,CAAC,kCAAkC,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;AACpE,YAAY,OAAO;AACnB,SAAS;AACT,QAAQ,MAAM,gBAAgB,GAAG,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC;AACrE,QAAQ,IAAI,kBAAkB,CAAC,gBAAgB,CAAC,EAAE;AAClD,YAAY,SAAS,CAAC,MAAM,GAAG,sBAAsB,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC;AACnF,YAAY,SAAS,CAAC,KAAK,GAAG,qBAAqB,CAAC,gBAAgB,CAAC,CAAC;AACtE,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,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,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,QAAQ,aAAa,EAAE,aAAa;AACpC,KAAK,CAAC;AACN,IAAI,MAAM,gBAAgB,GAAG,MAAM,CAAC,OAAO,CAAC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6B,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,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omOperationsProperty.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, GraphQLOptionsV6, ListArgs, QueryArgs } from '../../types';
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): ((contextSpec: AmplifyServer.ContextSpec & GraphQLOptionsV6<unknown, string>, arg?: QueryArgs, options?: AuthModeParams & ListArgs) => Promise<any>) | ((arg?: QueryArgs, options?: AuthModeParams & ListArgs) => Promise<any>);
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
- const opWithContext = async (contextSpec, arg, options) => {
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
- const op = async (arg, options) => {
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