@aws-amplify/api-graphql 4.0.1-api-v6-models.572a7b5.0 → 4.0.1-api-v6-models.3eb7748.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.
@@ -30,6 +30,18 @@ export declare const graphQLOperationsInfo: {
30
30
  operationPrefix: "list";
31
31
  usePlural: boolean;
32
32
  };
33
+ ONCREATE: {
34
+ operationPrefix: "onCreate";
35
+ usePlural: boolean;
36
+ };
37
+ ONUPDATE: {
38
+ operationPrefix: "onUpdate";
39
+ usePlural: boolean;
40
+ };
41
+ ONDELETE: {
42
+ operationPrefix: "onDelete";
43
+ usePlural: boolean;
44
+ };
33
45
  };
34
46
  export type ModelOperation = keyof typeof graphQLOperationsInfo;
35
47
  /**
@@ -2,6 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.normalizeMutationInput = exports.buildGraphQLVariables = exports.generateGraphQLDocument = exports.generateSelectionSet = exports.selectionSetIRToString = exports.customSelectionSetToIR = exports.graphQLOperationsInfo = exports.initializeModel = exports.flattenItems = void 0;
4
4
  var tslib_1 = require("tslib");
5
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
6
+ // SPDX-License-Identifier: Apache-2.0
7
+ var resolveOwnerFields_1 = require("../utils/resolveOwnerFields");
5
8
  var connectionType = {
6
9
  HAS_ONE: 'HAS_ONE',
7
10
  HAS_MANY: 'HAS_MANY',
@@ -139,17 +142,26 @@ exports.graphQLOperationsInfo = {
139
142
  UPDATE: { operationPrefix: 'update', usePlural: false },
140
143
  DELETE: { operationPrefix: 'delete', usePlural: false },
141
144
  LIST: { operationPrefix: 'list', usePlural: true },
145
+ ONCREATE: { operationPrefix: 'onCreate', usePlural: false },
146
+ ONUPDATE: { operationPrefix: 'onUpdate', usePlural: false },
147
+ ONDELETE: { operationPrefix: 'onDelete', usePlural: false },
142
148
  };
143
149
  var graphQLDocumentsCache = new Map();
144
150
  var SELECTION_SET_ALL_NESTED = '*';
145
151
  function defaultSelectionSetForModel(modelDefinition) {
152
+ // fields that are explicitly part of the graphql schema; not
153
+ // inferred from owner auth rules.
146
154
  var fields = modelDefinition.fields;
147
- return Object.values(fields)
155
+ var explicitFields = Object.values(fields)
148
156
  .map(function (_a) {
149
157
  var type = _a.type, name = _a.name;
150
158
  return typeof type === 'string' && name;
151
159
  }) // Default selection set omits model fields
152
160
  .filter(Boolean);
161
+ // fields used for owner auth rules that may or may not also
162
+ // be explicit on the model.
163
+ var ownerFields = (0, resolveOwnerFields_1.resolveOwnerFields)(modelDefinition);
164
+ return Array.from(new Set(explicitFields.concat(ownerFields)));
153
165
  }
154
166
  var FIELD_IR = '';
155
167
  /**
@@ -325,6 +337,14 @@ function generateGraphQLDocument(modelIntrospection, modelName, modelOperation,
325
337
  });
326
338
  graphQLOperationType !== null && graphQLOperationType !== void 0 ? graphQLOperationType : (graphQLOperationType = 'query');
327
339
  graphQLSelectionSet !== null && graphQLSelectionSet !== void 0 ? graphQLSelectionSet : (graphQLSelectionSet = "items { ".concat(selectionSetFields, " }"));
340
+ case 'ONCREATE':
341
+ case 'ONUPDATE':
342
+ case 'ONDELETE':
343
+ graphQLArguments !== null && graphQLArguments !== void 0 ? graphQLArguments : (graphQLArguments = {
344
+ filter: "ModelSubscription".concat(name, "FilterInput"),
345
+ });
346
+ graphQLOperationType !== null && graphQLOperationType !== void 0 ? graphQLOperationType : (graphQLOperationType = 'subscription');
347
+ graphQLSelectionSet !== null && graphQLSelectionSet !== void 0 ? graphQLSelectionSet : (graphQLSelectionSet = selectionSetFields);
328
348
  }
329
349
  var graphQLDocument = "".concat(graphQLOperationType).concat(graphQLArguments
330
350
  ? "(".concat(Object.entries(graphQLArguments).map(function (_a) {
@@ -373,6 +393,9 @@ function buildGraphQLVariables(modelDefinition, operation, arg, modelIntrospecti
373
393
  }
374
394
  break;
375
395
  case 'LIST':
396
+ case 'ONCREATE':
397
+ case 'ONUPDATE':
398
+ case 'ONDELETE':
376
399
  if (arg === null || arg === void 0 ? void 0 : arg.filter) {
377
400
  variables = { filter: arg.filter };
378
401
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.generateModelsProperty = void 0;
4
4
  var tslib_1 = require("tslib");
5
5
  var APIClient_1 = require("./APIClient");
6
+ var rxjs_1 = require("rxjs");
6
7
  function generateModelsProperty(client, params) {
7
8
  var e_1, _a;
8
9
  var _this = this;
@@ -81,6 +82,20 @@ function generateModelsProperty(client, params) {
81
82
  });
82
83
  }); };
83
84
  }
85
+ else if (['ONCREATE', 'ONUPDATE', 'ONDELETE'].includes(operation)) {
86
+ models[name_1][operationPrefix] = function (arg, options) {
87
+ var query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection.models, name_1, operation);
88
+ var variables = (0, APIClient_1.buildGraphQLVariables)(model, operation, arg, modelIntrospection);
89
+ var observable = client.graphql({
90
+ query: query,
91
+ variables: variables,
92
+ });
93
+ return observable.pipe((0, rxjs_1.map)(function (value) {
94
+ var _a = tslib_1.__read(Object.keys(value.data), 1), key = _a[0];
95
+ return value.data[key];
96
+ }));
97
+ };
98
+ }
84
99
  else {
85
100
  models[name_1][operationPrefix] = function (arg, options) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
86
101
  var query, variables, _a, data, extensions, _b, key_2, flattenedResult, _c, initialized, error_2;