@aws-amplify/api 5.4.5 → 5.4.6-api-v6.2fd20b7.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/lib/API.d.ts +18 -2
- package/lib/API.js +166 -0
- package/lib/API.js.map +1 -1
- package/lib/internals/InternalAPI.d.ts +1 -2
- package/lib/internals/InternalAPI.js.map +1 -1
- package/lib/types/index.d.ts +1 -8
- package/lib/types/index.js.map +1 -1
- package/lib-esm/API.d.ts +18 -2
- package/lib-esm/API.js +167 -1
- package/lib-esm/API.js.map +1 -1
- package/lib-esm/internals/InternalAPI.d.ts +1 -2
- package/lib-esm/internals/InternalAPI.js.map +1 -1
- package/lib-esm/types/index.d.ts +1 -8
- package/lib-esm/types/index.js.map +1 -1
- package/package.json +10 -8
- package/src/API.ts +234 -2
- package/src/internals/InternalAPI.ts +2 -1
- package/src/types/index.ts +2 -8
package/lib/API.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { AWSAppSyncRealTimeProvider } from '@aws-amplify/pubsub';
|
|
2
|
-
import { GraphQLOptions, GraphQLResult } from '@aws-amplify/api-graphql';
|
|
2
|
+
import { GraphQLOptions, GraphQLResult, GraphQLQuery, GraphQLSubscription } from '@aws-amplify/api-graphql';
|
|
3
|
+
import { graphql as v6graphql } from '@aws-amplify/api-graphql/internals';
|
|
3
4
|
import Observable from 'zen-observable-ts';
|
|
4
|
-
import { GraphQLQuery, GraphQLSubscription } from './types';
|
|
5
5
|
import { InternalAPIClass } from './internals/InternalAPI';
|
|
6
|
+
import type { ModelTypes } from '@aws-amplify/types-package-alpha';
|
|
6
7
|
/**
|
|
7
8
|
* @deprecated
|
|
8
9
|
* Use RestApi or GraphQLAPI to reduce your application bundle size
|
|
@@ -23,5 +24,20 @@ export declare class APIClass extends InternalAPIClass {
|
|
|
23
24
|
provider: AWSAppSyncRealTimeProvider;
|
|
24
25
|
value: GraphQLResult<T>;
|
|
25
26
|
}> : Promise<GraphQLResult<any>> | Observable<object>;
|
|
27
|
+
/**
|
|
28
|
+
* Generates an API client that can work with models or raw GraphQL
|
|
29
|
+
*/
|
|
30
|
+
generateClient<T extends Record<any, any> = never>(): V6Client<T>;
|
|
26
31
|
}
|
|
32
|
+
declare type FilteredKeys<T> = {
|
|
33
|
+
[P in keyof T]: T[P] extends never ? never : P;
|
|
34
|
+
}[keyof T];
|
|
35
|
+
declare type ExcludeNeverFields<O> = {
|
|
36
|
+
[K in FilteredKeys<O>]: O[K];
|
|
37
|
+
};
|
|
38
|
+
declare type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
|
|
39
|
+
graphql: typeof v6graphql;
|
|
40
|
+
models: ModelTypes<T>;
|
|
41
|
+
}>;
|
|
27
42
|
export declare const API: APIClass;
|
|
43
|
+
export {};
|
package/lib/API.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
|
+
var internals_1 = require("@aws-amplify/api-graphql/internals");
|
|
4
5
|
var core_1 = require("@aws-amplify/core");
|
|
5
6
|
var InternalAPI_1 = require("./internals/InternalAPI");
|
|
6
7
|
var logger = new core_1.ConsoleLogger('API');
|
|
@@ -20,9 +21,174 @@ var APIClass = /** @class */ (function (_super) {
|
|
|
20
21
|
APIClass.prototype.graphql = function (options, additionalHeaders) {
|
|
21
22
|
return _super.prototype.graphql.call(this, options, additionalHeaders);
|
|
22
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Generates an API client that can work with models or raw GraphQL
|
|
26
|
+
*/
|
|
27
|
+
APIClass.prototype.generateClient = function () {
|
|
28
|
+
var e_1, _a;
|
|
29
|
+
var _this = this;
|
|
30
|
+
var config = _super.prototype.configure.call(this, {});
|
|
31
|
+
var modelIntrospection = config.modelIntrospection;
|
|
32
|
+
var client = {
|
|
33
|
+
graphql: internals_1.graphql,
|
|
34
|
+
models: {},
|
|
35
|
+
};
|
|
36
|
+
var _loop_1 = function (model) {
|
|
37
|
+
var name_1 = model.name;
|
|
38
|
+
client.models[name_1] = {};
|
|
39
|
+
Object.entries(graphQLOperationsInfo).forEach(function (_a) {
|
|
40
|
+
var _b = tslib_1.__read(_a, 2), key = _b[0], operationPrefix = _b[1].operationPrefix;
|
|
41
|
+
var operation = key;
|
|
42
|
+
// e.g. clients.models.Todo.update
|
|
43
|
+
client.models[name_1][operationPrefix] = function (arg) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
44
|
+
var query, variables, res, _a, key_1;
|
|
45
|
+
return tslib_1.__generator(this, function (_b) {
|
|
46
|
+
switch (_b.label) {
|
|
47
|
+
case 0:
|
|
48
|
+
query = generateGraphQLDocument(model, operation);
|
|
49
|
+
variables = buildGraphQLVariables(model, operation, arg);
|
|
50
|
+
return [4 /*yield*/, this.graphql({
|
|
51
|
+
query: query,
|
|
52
|
+
variables: variables,
|
|
53
|
+
})];
|
|
54
|
+
case 1:
|
|
55
|
+
res = (_b.sent());
|
|
56
|
+
// flatten response
|
|
57
|
+
if (res.data !== undefined) {
|
|
58
|
+
_a = tslib_1.__read(Object.keys(res.data), 1), key_1 = _a[0];
|
|
59
|
+
if (res.data[key_1].items) {
|
|
60
|
+
return [2 /*return*/, res.data[key_1].items];
|
|
61
|
+
}
|
|
62
|
+
return [2 /*return*/, res.data[key_1]];
|
|
63
|
+
}
|
|
64
|
+
return [2 /*return*/, res];
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}); };
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
try {
|
|
71
|
+
for (var _b = tslib_1.__values(Object.values(modelIntrospection.models)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
72
|
+
var model = _c.value;
|
|
73
|
+
_loop_1(model);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
77
|
+
finally {
|
|
78
|
+
try {
|
|
79
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
80
|
+
}
|
|
81
|
+
finally { if (e_1) throw e_1.error; }
|
|
82
|
+
}
|
|
83
|
+
return client;
|
|
84
|
+
};
|
|
23
85
|
return APIClass;
|
|
24
86
|
}(InternalAPI_1.InternalAPIClass));
|
|
25
87
|
exports.APIClass = APIClass;
|
|
88
|
+
var graphQLOperationsInfo = {
|
|
89
|
+
CREATE: { operationPrefix: 'create', usePlural: false },
|
|
90
|
+
READ: { operationPrefix: 'get', usePlural: false },
|
|
91
|
+
UPDATE: { operationPrefix: 'update', usePlural: false },
|
|
92
|
+
DELETE: { operationPrefix: 'delete', usePlural: false },
|
|
93
|
+
LIST: { operationPrefix: 'list', usePlural: true },
|
|
94
|
+
};
|
|
95
|
+
var graphQLDocumentsCache = new Map();
|
|
96
|
+
function generateGraphQLDocument(modelDefinition, modelOperation) {
|
|
97
|
+
var _a;
|
|
98
|
+
var _b, _c;
|
|
99
|
+
var name = modelDefinition.name, pluralName = modelDefinition.pluralName, fields = modelDefinition.fields, _d = modelDefinition.primaryKeyInfo, isCustomPrimaryKey = _d.isCustomPrimaryKey, primaryKeyFieldName = _d.primaryKeyFieldName, sortKeyFieldNames = _d.sortKeyFieldNames;
|
|
100
|
+
var _e = graphQLOperationsInfo[modelOperation], operationPrefix = _e.operationPrefix, usePlural = _e.usePlural;
|
|
101
|
+
var fromCache = (_b = graphQLDocumentsCache.get(name)) === null || _b === void 0 ? void 0 : _b.get(modelOperation);
|
|
102
|
+
if (fromCache !== undefined) {
|
|
103
|
+
return fromCache;
|
|
104
|
+
}
|
|
105
|
+
if (!graphQLDocumentsCache.has(name)) {
|
|
106
|
+
graphQLDocumentsCache.set(name, new Map());
|
|
107
|
+
}
|
|
108
|
+
var graphQLFieldName = "" + operationPrefix + (usePlural ? pluralName : name);
|
|
109
|
+
var graphQLOperationType;
|
|
110
|
+
var graphQLSelectionSet;
|
|
111
|
+
var graphQLArguments;
|
|
112
|
+
var selectionSetFields = Object.values(fields)
|
|
113
|
+
.map(function (_a) {
|
|
114
|
+
var type = _a.type, name = _a.name;
|
|
115
|
+
return typeof type === 'string' && name;
|
|
116
|
+
}) // Only scalars for now
|
|
117
|
+
.filter(Boolean)
|
|
118
|
+
.join(' ');
|
|
119
|
+
switch (modelOperation) {
|
|
120
|
+
case 'CREATE':
|
|
121
|
+
case 'UPDATE':
|
|
122
|
+
case 'DELETE':
|
|
123
|
+
graphQLArguments !== null && graphQLArguments !== void 0 ? graphQLArguments : (graphQLArguments = {
|
|
124
|
+
input: "" + (operationPrefix.charAt(0).toLocaleUpperCase() +
|
|
125
|
+
operationPrefix.slice(1)) + name + "Input!",
|
|
126
|
+
});
|
|
127
|
+
graphQLOperationType !== null && graphQLOperationType !== void 0 ? graphQLOperationType : (graphQLOperationType = 'mutation');
|
|
128
|
+
case 'READ':
|
|
129
|
+
graphQLArguments !== null && graphQLArguments !== void 0 ? graphQLArguments : (graphQLArguments = isCustomPrimaryKey
|
|
130
|
+
? tslib_1.__spread([primaryKeyFieldName], sortKeyFieldNames).reduce(function (acc, fieldName) {
|
|
131
|
+
acc[fieldName] = fields[fieldName].type;
|
|
132
|
+
return acc;
|
|
133
|
+
}, {})
|
|
134
|
+
: (_a = {},
|
|
135
|
+
_a[primaryKeyFieldName] = fields[primaryKeyFieldName].type + "!",
|
|
136
|
+
_a));
|
|
137
|
+
graphQLSelectionSet !== null && graphQLSelectionSet !== void 0 ? graphQLSelectionSet : (graphQLSelectionSet = selectionSetFields);
|
|
138
|
+
case 'LIST':
|
|
139
|
+
graphQLOperationType !== null && graphQLOperationType !== void 0 ? graphQLOperationType : (graphQLOperationType = 'query');
|
|
140
|
+
graphQLSelectionSet !== null && graphQLSelectionSet !== void 0 ? graphQLSelectionSet : (graphQLSelectionSet = "items { " + selectionSetFields + " }");
|
|
141
|
+
}
|
|
142
|
+
var graphQLDocument = "" + graphQLOperationType + (graphQLArguments
|
|
143
|
+
? "(" + Object.entries(graphQLArguments).map(function (_a) {
|
|
144
|
+
var _b = tslib_1.__read(_a, 2), fieldName = _b[0], type = _b[1];
|
|
145
|
+
return "$" + fieldName + ": " + type;
|
|
146
|
+
}) + ")"
|
|
147
|
+
: '') + " { " + graphQLFieldName + (graphQLArguments
|
|
148
|
+
? "(" + Object.keys(graphQLArguments).map(function (fieldName) { return fieldName + ": $" + fieldName; }) + ")"
|
|
149
|
+
: '') + " { " + graphQLSelectionSet + " } }";
|
|
150
|
+
(_c = graphQLDocumentsCache.get(name)) === null || _c === void 0 ? void 0 : _c.set(modelOperation, graphQLDocument);
|
|
151
|
+
return graphQLDocument;
|
|
152
|
+
}
|
|
153
|
+
function buildGraphQLVariables(modelDefinition, operation, arg) {
|
|
154
|
+
var _a;
|
|
155
|
+
var fields = modelDefinition.fields, _b = modelDefinition.primaryKeyInfo, isCustomPrimaryKey = _b.isCustomPrimaryKey, primaryKeyFieldName = _b.primaryKeyFieldName, sortKeyFieldNames = _b.sortKeyFieldNames;
|
|
156
|
+
var variables = {};
|
|
157
|
+
switch (operation) {
|
|
158
|
+
case 'CREATE':
|
|
159
|
+
variables = { input: arg };
|
|
160
|
+
break;
|
|
161
|
+
case 'UPDATE':
|
|
162
|
+
// readonly fields are not updated
|
|
163
|
+
variables = {
|
|
164
|
+
input: Object.fromEntries(Object.entries(arg).filter(function (_a) {
|
|
165
|
+
var _b = tslib_1.__read(_a, 1), fieldName = _b[0];
|
|
166
|
+
var isReadOnly = fields[fieldName].isReadOnly;
|
|
167
|
+
return !isReadOnly;
|
|
168
|
+
})),
|
|
169
|
+
};
|
|
170
|
+
break;
|
|
171
|
+
case 'READ':
|
|
172
|
+
case 'DELETE':
|
|
173
|
+
// only identifiers are sent
|
|
174
|
+
variables = isCustomPrimaryKey
|
|
175
|
+
? tslib_1.__spread([primaryKeyFieldName], sortKeyFieldNames).reduce(function (acc, fieldName) {
|
|
176
|
+
acc[fieldName] = arg[fieldName];
|
|
177
|
+
return acc;
|
|
178
|
+
}, {})
|
|
179
|
+
: (_a = {}, _a[primaryKeyFieldName] = arg[primaryKeyFieldName], _a);
|
|
180
|
+
if (operation === 'DELETE') {
|
|
181
|
+
variables = { input: variables };
|
|
182
|
+
}
|
|
183
|
+
break;
|
|
184
|
+
case 'LIST':
|
|
185
|
+
break;
|
|
186
|
+
default:
|
|
187
|
+
var exhaustiveCheck = operation;
|
|
188
|
+
throw new Error("Unhandled operation case: " + exhaustiveCheck);
|
|
189
|
+
}
|
|
190
|
+
return variables;
|
|
191
|
+
}
|
|
26
192
|
exports.API = new APIClass(null);
|
|
27
193
|
core_1.Amplify.register(exports.API);
|
|
28
194
|
//# sourceMappingURL=API.js.map
|
package/lib/API.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"API.js","sourceRoot":"","sources":["../src/API.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"API.js","sourceRoot":"","sources":["../src/API.ts"],"names":[],"mappings":";;;AASA,gEAA0E;AAC1E,0CAAqE;AAErE,uDAA2D;AAG3D,IAAM,MAAM,GAAG,IAAI,oBAAM,CAAC,KAAK,CAAC,CAAC;AACjC;;;;GAIG;AACH;IAA8B,oCAAgB;IAA9C;;IAiFA,CAAC;IAhFO,gCAAa,GAApB;QACC,OAAO,KAAK,CAAC;IACd,CAAC;IAoBD,0BAAO,GAAP,UACC,OAAuB,EACvB,iBAA6C;QAE7C,OAAO,iBAAM,OAAO,YAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IAClD,CAAC;IAED;;OAEG;IACH,iCAAc,GAAd;;QAAA,iBA+CC;QA9CA,IAAM,MAAM,GAAG,iBAAM,SAAS,YAAC,EAAE,CAAC,CAAC;QAE3B,IAAA,8CAAkB,CAAY;QAEtC,IAAM,MAAM,GAAkB;YAC7B,OAAO,EAAE,mBAAS;YAClB,MAAM,EAAE,EAAE;SACV,CAAC;gCAES,KAAK;YACP,IAAA,mBAAI,CAAkB;YAE9B,MAAM,CAAC,MAAM,C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EAAW;wBAAX,0BAAW,EAAV,iBAAS;oBAC7B,IAAA,yCAAU,CAAuB;oBAEzC,OAAO,CAAC,UAAU,CAAC;gBACpB,CAAC,CAAC,CACF;aACD,CAAC;YACF,MAAM;QACP,KAAK,MAAM,CAAC;QACZ,KAAK,QAAQ;YACZ,4BAA4B;YAC5B,SAAS,GAAG,kBAAkB;gBAC7B,CAAC,CAAC,kBAAC,mBAAmB,GAAK,iBAAiB,EAAE,MAAM,CAClD,UAAC,GAAG,EAAE,SAAS;oBACd,GAAG,CAAC,SAAS,CAAC,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC;oBAEhC,OAAO,GAAG,CAAC;gBACZ,CAAC,EACD,EAAE,CACD;gBACH,CAAC,WAAG,GAAC,mBAAmB,IAAG,GAAG,CAAC,mBAAmB,CAAC,KAAE,CAAC;YAEvD,IAAI,SAAS,KAAK,QAAQ,EAAE;gBAC3B,SAAS,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;aACjC;YACD,MAAM;QACP,KAAK,MAAM;YACV,MAAM;QACP;YACC,IAAM,eAAe,GAAU,SAAS,CAAC;YACzC,MAAM,IAAI,KAAK,CAAC,+BAA6B,eAAiB,CAAC,CAAC;KACjE;IAED,OAAO,SAAS,CAAC;AAClB,CAAC;AAeY,QAAA,GAAG,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC;AACtC,cAAO,CAAC,QAAQ,CAAC,WAAG,CAAC,CAAC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { GraphQLOperation, GraphQLOptions, GraphQLResult, OperationTypeNode } from '@aws-amplify/api-graphql';
|
|
1
|
+
import { GraphQLOperation, GraphQLOptions, GraphQLResult, OperationTypeNode, GraphQLQuery, GraphQLSubscription } from '@aws-amplify/api-graphql';
|
|
2
2
|
import { CustomUserAgentDetails } from '@aws-amplify/core';
|
|
3
3
|
import { AWSAppSyncRealTimeProvider } from '@aws-amplify/pubsub';
|
|
4
4
|
import Observable from 'zen-observable-ts';
|
|
5
|
-
import { GraphQLQuery, GraphQLSubscription } from '../types';
|
|
6
5
|
/**
|
|
7
6
|
* @deprecated
|
|
8
7
|
* Use RestApi or GraphQLAPI to reduce your application bundle size
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InternalAPI.js","sourceRoot":"","sources":["../../src/internals/InternalAPI.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"InternalAPI.js","sourceRoot":"","sources":["../../src/internals/InternalAPI.ts"],"names":[],"mappings":";;;AAUA,gEAA6E;AAC7E,kDAAqD;AACrD,0CAAyC;AACzC,4CAA2C;AAC3C,0CAO2B;AAI3B,IAAM,MAAM,GAAG,IAAI,oBAAM,CAAC,KAAK,CAAC,CAAC;AACjC;;;;GAIG;AACH;IAaC;;;OAGG;IACH,0BAAY,OAAO;QARnB,SAAI,GAAG,WAAI,CAAC;QACZ,UAAK,GAAG,aAAK,CAAC;QACd,gBAAW,GAAG,kBAAW,CAAC;QAOzB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,QAAQ,GAAG,IAAI,uBAAY,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,CAAC,WAAW,GAAG,IAAI,mCAAuB,CAAC,OAAO,CAAC,CAAC;QACxD,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5C,CAAC;IAEM,wCAAa,GAApB;QACC,OAAO,aAAa,CAAC;IACtB,CAAC;IAED;;;;OAIG;IACH,oCAAS,GAAT,UAAU,OAAO;QAChB,IAAI,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAE1D,6CAA6C;QAC7C,IAAI,CAAC,QAAQ,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QAE7C,IAAI,CAAC,WAAW,CAAC,IAAI,GAAG,IAAI,CAAC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yCAAQ,IAAI,KAAE,sBAAsB,wBAAA,GAAE,CAAC;QACvD,OAAO,UAAU,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACG,mCAAQ,GAAd,UAAe,OAAe;;;gBAC7B,sBAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAC;;;KACvC;IAED;;;OAGG;IACH,kDAAuB,GAAvB,UAAwB,SAA2B;QAClD,OAAO,IAAI,CAAC,WAAW,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;IAC5D,CAAC;IAqBD,kCAAO,GAAP,UACC,OAAuB,EACvB,iBAA6C,EAC7C,sBAA+C;QAE/C,IAAM,mBAAmB,sBACxB,QAAQ,EAAE,eAAQ,CAAC,GAAG,EACtB,MAAM,EAAE,gBAAS,CAAC,OAAO,IACtB,sBAAsB,CACzB,CAAC;QAEF,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAC9B,OAAO,EACP,iBAAiB,EACjB,mBAAmB,CACnB,CAAC;IACH,CAAC;IACF,uBAAC;AAAD,CAAC,AA3PD,IA2PC;AA3PY,4CAAgB;AA6PhB,QAAA,WAAW,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC;AACtD,cAAO,CAAC,QAAQ,CAAC,mBAAW,CAAC,CAAC"}
|
package/lib/types/index.d.ts
CHANGED
|
@@ -3,11 +3,4 @@
|
|
|
3
3
|
* generates code that relies on this import path https://github.com/aws-amplify/amplify-cli/issues/3863
|
|
4
4
|
* This will be removed in future release when CLI and customers moves to recommeneded import styles.
|
|
5
5
|
*/
|
|
6
|
-
export { graphqlOperation, GraphQLAuthError, GraphQLResult, GRAPHQL_AUTH_MODE, } from '@aws-amplify/api-graphql';
|
|
7
|
-
declare const queryType: unique symbol;
|
|
8
|
-
export declare type GraphQLQuery<T> = T & {
|
|
9
|
-
readonly [queryType]: 'query';
|
|
10
|
-
};
|
|
11
|
-
export declare type GraphQLSubscription<T> = T & {
|
|
12
|
-
readonly [queryType]: 'subscription';
|
|
13
|
-
};
|
|
6
|
+
export { graphqlOperation, GraphQLAuthError, GraphQLResult, GRAPHQL_AUTH_MODE, GraphQLQuery, GraphQLSubscription, } from '@aws-amplify/api-graphql';
|
package/lib/types/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;AAEtC;;;;GAIG;AACH,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":";AAAA,qEAAqE;AACrE,sCAAsC;;AAEtC;;;;GAIG;AACH,wDAOkC;AANjC,yCAAA,gBAAgB,CAAA;AAChB,yCAAA,gBAAgB,CAAA;AAEhB,0CAAA,iBAAiB,CAAA"}
|
package/lib-esm/API.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { AWSAppSyncRealTimeProvider } from '@aws-amplify/pubsub';
|
|
2
|
-
import { GraphQLOptions, GraphQLResult } from '@aws-amplify/api-graphql';
|
|
2
|
+
import { GraphQLOptions, GraphQLResult, GraphQLQuery, GraphQLSubscription } from '@aws-amplify/api-graphql';
|
|
3
|
+
import { graphql as v6graphql } from '@aws-amplify/api-graphql/internals';
|
|
3
4
|
import Observable from 'zen-observable-ts';
|
|
4
|
-
import { GraphQLQuery, GraphQLSubscription } from './types';
|
|
5
5
|
import { InternalAPIClass } from './internals/InternalAPI';
|
|
6
|
+
import type { ModelTypes } from '@aws-amplify/types-package-alpha';
|
|
6
7
|
/**
|
|
7
8
|
* @deprecated
|
|
8
9
|
* Use RestApi or GraphQLAPI to reduce your application bundle size
|
|
@@ -23,5 +24,20 @@ export declare class APIClass extends InternalAPIClass {
|
|
|
23
24
|
provider: AWSAppSyncRealTimeProvider;
|
|
24
25
|
value: GraphQLResult<T>;
|
|
25
26
|
}> : Promise<GraphQLResult<any>> | Observable<object>;
|
|
27
|
+
/**
|
|
28
|
+
* Generates an API client that can work with models or raw GraphQL
|
|
29
|
+
*/
|
|
30
|
+
generateClient<T extends Record<any, any> = never>(): V6Client<T>;
|
|
26
31
|
}
|
|
32
|
+
declare type FilteredKeys<T> = {
|
|
33
|
+
[P in keyof T]: T[P] extends never ? never : P;
|
|
34
|
+
}[keyof T];
|
|
35
|
+
declare type ExcludeNeverFields<O> = {
|
|
36
|
+
[K in FilteredKeys<O>]: O[K];
|
|
37
|
+
};
|
|
38
|
+
declare type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
|
|
39
|
+
graphql: typeof v6graphql;
|
|
40
|
+
models: ModelTypes<T>;
|
|
41
|
+
}>;
|
|
27
42
|
export declare const API: APIClass;
|
|
43
|
+
export {};
|
package/lib-esm/API.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { __extends } from "tslib";
|
|
1
|
+
import { __awaiter, __extends, __generator, __read, __spread, __values } from "tslib";
|
|
2
|
+
import { graphql as v6graphql } from '@aws-amplify/api-graphql/internals';
|
|
2
3
|
import { Amplify, ConsoleLogger as Logger } from '@aws-amplify/core';
|
|
3
4
|
import { InternalAPIClass } from './internals/InternalAPI';
|
|
4
5
|
var logger = new Logger('API');
|
|
@@ -18,9 +19,174 @@ var APIClass = /** @class */ (function (_super) {
|
|
|
18
19
|
APIClass.prototype.graphql = function (options, additionalHeaders) {
|
|
19
20
|
return _super.prototype.graphql.call(this, options, additionalHeaders);
|
|
20
21
|
};
|
|
22
|
+
/**
|
|
23
|
+
* Generates an API client that can work with models or raw GraphQL
|
|
24
|
+
*/
|
|
25
|
+
APIClass.prototype.generateClient = function () {
|
|
26
|
+
var e_1, _a;
|
|
27
|
+
var _this = this;
|
|
28
|
+
var config = _super.prototype.configure.call(this, {});
|
|
29
|
+
var modelIntrospection = config.modelIntrospection;
|
|
30
|
+
var client = {
|
|
31
|
+
graphql: v6graphql,
|
|
32
|
+
models: {},
|
|
33
|
+
};
|
|
34
|
+
var _loop_1 = function (model) {
|
|
35
|
+
var name_1 = model.name;
|
|
36
|
+
client.models[name_1] = {};
|
|
37
|
+
Object.entries(graphQLOperationsInfo).forEach(function (_a) {
|
|
38
|
+
var _b = __read(_a, 2), key = _b[0], operationPrefix = _b[1].operationPrefix;
|
|
39
|
+
var operation = key;
|
|
40
|
+
// e.g. clients.models.Todo.update
|
|
41
|
+
client.models[name_1][operationPrefix] = function (arg) { return __awaiter(_this, void 0, void 0, function () {
|
|
42
|
+
var query, variables, res, _a, key_1;
|
|
43
|
+
return __generator(this, function (_b) {
|
|
44
|
+
switch (_b.label) {
|
|
45
|
+
case 0:
|
|
46
|
+
query = generateGraphQLDocument(model, operation);
|
|
47
|
+
variables = buildGraphQLVariables(model, operation, arg);
|
|
48
|
+
return [4 /*yield*/, this.graphql({
|
|
49
|
+
query: query,
|
|
50
|
+
variables: variables,
|
|
51
|
+
})];
|
|
52
|
+
case 1:
|
|
53
|
+
res = (_b.sent());
|
|
54
|
+
// flatten response
|
|
55
|
+
if (res.data !== undefined) {
|
|
56
|
+
_a = __read(Object.keys(res.data), 1), key_1 = _a[0];
|
|
57
|
+
if (res.data[key_1].items) {
|
|
58
|
+
return [2 /*return*/, res.data[key_1].items];
|
|
59
|
+
}
|
|
60
|
+
return [2 /*return*/, res.data[key_1]];
|
|
61
|
+
}
|
|
62
|
+
return [2 /*return*/, res];
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
}); };
|
|
66
|
+
});
|
|
67
|
+
};
|
|
68
|
+
try {
|
|
69
|
+
for (var _b = __values(Object.values(modelIntrospection.models)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
70
|
+
var model = _c.value;
|
|
71
|
+
_loop_1(model);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
75
|
+
finally {
|
|
76
|
+
try {
|
|
77
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
78
|
+
}
|
|
79
|
+
finally { if (e_1) throw e_1.error; }
|
|
80
|
+
}
|
|
81
|
+
return client;
|
|
82
|
+
};
|
|
21
83
|
return APIClass;
|
|
22
84
|
}(InternalAPIClass));
|
|
23
85
|
export { APIClass };
|
|
86
|
+
var graphQLOperationsInfo = {
|
|
87
|
+
CREATE: { operationPrefix: 'create', usePlural: false },
|
|
88
|
+
READ: { operationPrefix: 'get', usePlural: false },
|
|
89
|
+
UPDATE: { operationPrefix: 'update', usePlural: false },
|
|
90
|
+
DELETE: { operationPrefix: 'delete', usePlural: false },
|
|
91
|
+
LIST: { operationPrefix: 'list', usePlural: true },
|
|
92
|
+
};
|
|
93
|
+
var graphQLDocumentsCache = new Map();
|
|
94
|
+
function generateGraphQLDocument(modelDefinition, modelOperation) {
|
|
95
|
+
var _a;
|
|
96
|
+
var _b, _c;
|
|
97
|
+
var name = modelDefinition.name, pluralName = modelDefinition.pluralName, fields = modelDefinition.fields, _d = modelDefinition.primaryKeyInfo, isCustomPrimaryKey = _d.isCustomPrimaryKey, primaryKeyFieldName = _d.primaryKeyFieldName, sortKeyFieldNames = _d.sortKeyFieldNames;
|
|
98
|
+
var _e = graphQLOperationsInfo[modelOperation], operationPrefix = _e.operationPrefix, usePlural = _e.usePlural;
|
|
99
|
+
var fromCache = (_b = graphQLDocumentsCache.get(name)) === null || _b === void 0 ? void 0 : _b.get(modelOperation);
|
|
100
|
+
if (fromCache !== undefined) {
|
|
101
|
+
return fromCache;
|
|
102
|
+
}
|
|
103
|
+
if (!graphQLDocumentsCache.has(name)) {
|
|
104
|
+
graphQLDocumentsCache.set(name, new Map());
|
|
105
|
+
}
|
|
106
|
+
var graphQLFieldName = "" + operationPrefix + (usePlural ? pluralName : name);
|
|
107
|
+
var graphQLOperationType;
|
|
108
|
+
var graphQLSelectionSet;
|
|
109
|
+
var graphQLArguments;
|
|
110
|
+
var selectionSetFields = Object.values(fields)
|
|
111
|
+
.map(function (_a) {
|
|
112
|
+
var type = _a.type, name = _a.name;
|
|
113
|
+
return typeof type === 'string' && name;
|
|
114
|
+
}) // Only scalars for now
|
|
115
|
+
.filter(Boolean)
|
|
116
|
+
.join(' ');
|
|
117
|
+
switch (modelOperation) {
|
|
118
|
+
case 'CREATE':
|
|
119
|
+
case 'UPDATE':
|
|
120
|
+
case 'DELETE':
|
|
121
|
+
graphQLArguments !== null && graphQLArguments !== void 0 ? graphQLArguments : (graphQLArguments = {
|
|
122
|
+
input: "" + (operationPrefix.charAt(0).toLocaleUpperCase() +
|
|
123
|
+
operationPrefix.slice(1)) + name + "Input!",
|
|
124
|
+
});
|
|
125
|
+
graphQLOperationType !== null && graphQLOperationType !== void 0 ? graphQLOperationType : (graphQLOperationType = 'mutation');
|
|
126
|
+
case 'READ':
|
|
127
|
+
graphQLArguments !== null && graphQLArguments !== void 0 ? graphQLArguments : (graphQLArguments = isCustomPrimaryKey
|
|
128
|
+
? __spread([primaryKeyFieldName], sortKeyFieldNames).reduce(function (acc, fieldName) {
|
|
129
|
+
acc[fieldName] = fields[fieldName].type;
|
|
130
|
+
return acc;
|
|
131
|
+
}, {})
|
|
132
|
+
: (_a = {},
|
|
133
|
+
_a[primaryKeyFieldName] = fields[primaryKeyFieldName].type + "!",
|
|
134
|
+
_a));
|
|
135
|
+
graphQLSelectionSet !== null && graphQLSelectionSet !== void 0 ? graphQLSelectionSet : (graphQLSelectionSet = selectionSetFields);
|
|
136
|
+
case 'LIST':
|
|
137
|
+
graphQLOperationType !== null && graphQLOperationType !== void 0 ? graphQLOperationType : (graphQLOperationType = 'query');
|
|
138
|
+
graphQLSelectionSet !== null && graphQLSelectionSet !== void 0 ? graphQLSelectionSet : (graphQLSelectionSet = "items { " + selectionSetFields + " }");
|
|
139
|
+
}
|
|
140
|
+
var graphQLDocument = "" + graphQLOperationType + (graphQLArguments
|
|
141
|
+
? "(" + Object.entries(graphQLArguments).map(function (_a) {
|
|
142
|
+
var _b = __read(_a, 2), fieldName = _b[0], type = _b[1];
|
|
143
|
+
return "$" + fieldName + ": " + type;
|
|
144
|
+
}) + ")"
|
|
145
|
+
: '') + " { " + graphQLFieldName + (graphQLArguments
|
|
146
|
+
? "(" + Object.keys(graphQLArguments).map(function (fieldName) { return fieldName + ": $" + fieldName; }) + ")"
|
|
147
|
+
: '') + " { " + graphQLSelectionSet + " } }";
|
|
148
|
+
(_c = graphQLDocumentsCache.get(name)) === null || _c === void 0 ? void 0 : _c.set(modelOperation, graphQLDocument);
|
|
149
|
+
return graphQLDocument;
|
|
150
|
+
}
|
|
151
|
+
function buildGraphQLVariables(modelDefinition, operation, arg) {
|
|
152
|
+
var _a;
|
|
153
|
+
var fields = modelDefinition.fields, _b = modelDefinition.primaryKeyInfo, isCustomPrimaryKey = _b.isCustomPrimaryKey, primaryKeyFieldName = _b.primaryKeyFieldName, sortKeyFieldNames = _b.sortKeyFieldNames;
|
|
154
|
+
var variables = {};
|
|
155
|
+
switch (operation) {
|
|
156
|
+
case 'CREATE':
|
|
157
|
+
variables = { input: arg };
|
|
158
|
+
break;
|
|
159
|
+
case 'UPDATE':
|
|
160
|
+
// readonly fields are not updated
|
|
161
|
+
variables = {
|
|
162
|
+
input: Object.fromEntries(Object.entries(arg).filter(function (_a) {
|
|
163
|
+
var _b = __read(_a, 1), fieldName = _b[0];
|
|
164
|
+
var isReadOnly = fields[fieldName].isReadOnly;
|
|
165
|
+
return !isReadOnly;
|
|
166
|
+
})),
|
|
167
|
+
};
|
|
168
|
+
break;
|
|
169
|
+
case 'READ':
|
|
170
|
+
case 'DELETE':
|
|
171
|
+
// only identifiers are sent
|
|
172
|
+
variables = isCustomPrimaryKey
|
|
173
|
+
? __spread([primaryKeyFieldName], sortKeyFieldNames).reduce(function (acc, fieldName) {
|
|
174
|
+
acc[fieldName] = arg[fieldName];
|
|
175
|
+
return acc;
|
|
176
|
+
}, {})
|
|
177
|
+
: (_a = {}, _a[primaryKeyFieldName] = arg[primaryKeyFieldName], _a);
|
|
178
|
+
if (operation === 'DELETE') {
|
|
179
|
+
variables = { input: variables };
|
|
180
|
+
}
|
|
181
|
+
break;
|
|
182
|
+
case 'LIST':
|
|
183
|
+
break;
|
|
184
|
+
default:
|
|
185
|
+
var exhaustiveCheck = operation;
|
|
186
|
+
throw new Error("Unhandled operation case: " + exhaustiveCheck);
|
|
187
|
+
}
|
|
188
|
+
return variables;
|
|
189
|
+
}
|
|
24
190
|
export var API = new APIClass(null);
|
|
25
191
|
Amplify.register(API);
|
|
26
192
|
//# sourceMappingURL=API.js.map
|
package/lib-esm/API.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"API.js","sourceRoot":"","sources":["../src/API.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"API.js","sourceRoot":"","sources":["../src/API.ts"],"names":[],"mappings":";AASA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAC1E,OAAO,EAAE,OAAO,EAAE,aAAa,IAAI,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAErE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAG3D,IAAM,MAAM,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;AACjC;;;;GAIG;AACH;IAA8B,4BAAgB;IAA9C;;IAiFA,CAAC;IAhFO,gCAAa,GAApB;QACC,OAAO,KAAK,CAAC;IACd,CAAC;IAoBD,0BAAO,GAAP,UACC,OAAuB,EACvB,iBAA6C;QAE7C,OAAO,iBAAM,OAAO,YAAC,OAAO,EAAE,iBAAiB,CAAC,CAAC;IAClD,CAAC;IAED;;OAEG;IACH,iCAAc,GAAd;;QAAA,iBA+CC;QA9CA,IAAM,MAAM,GAAG,iBAAM,SAAS,YAAC,EAAE,CAAC,CAAC;QAE3B,IAAA,8CAAkB,CAAY;QAEtC,IAAM,MAAM,GAAkB;YAC7B,OAAO,EAAE,SAAS;YAClB,MAAM,EAAE,EAAE;SACV,CAAC;gCAES,KAAK;YACP,IAAA,mBAAI,CAAkB;YAE9B,MAAM,CAA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X,kBAAW,EAAV,iBAAS;oBAC7B,IAAA,yCAAU,CAAuB;oBAEzC,OAAO,CAAC,UAAU,CAAC;gBACpB,CAAC,CAAC,CACF;aACD,CAAC;YACF,MAAM;QACP,KAAK,MAAM,CAAC;QACZ,KAAK,QAAQ;YACZ,4BAA4B;YAC5B,SAAS,GAAG,kBAAkB;gBAC7B,CAAC,CAAC,UAAC,mBAAmB,GAAK,iBAAiB,EAAE,MAAM,CAClD,UAAC,GAAG,EAAE,SAAS;oBACd,GAAG,CAAC,SAAS,CAAC,GAAG,GAAG,CAAC,SAAS,CAAC,CAAC;oBAEhC,OAAO,GAAG,CAAC;gBACZ,CAAC,EACD,EAAE,CACD;gBACH,CAAC,WAAG,GAAC,mBAAmB,IAAG,GAAG,CAAC,mBAAmB,CAAC,KAAE,CAAC;YAEvD,IAAI,SAAS,KAAK,QAAQ,EAAE;gBAC3B,SAAS,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC;aACjC;YACD,MAAM;QACP,KAAK,MAAM;YACV,MAAM;QACP;YACC,IAAM,eAAe,GAAU,SAAS,CAAC;YACzC,MAAM,IAAI,KAAK,CAAC,+BAA6B,eAAiB,CAAC,CAAC;KACjE;IAED,OAAO,SAAS,CAAC;AAClB,CAAC;AAeD,MAAM,CAAC,IAAM,GAAG,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC;AACtC,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
|
-
import { GraphQLOperation, GraphQLOptions, GraphQLResult, OperationTypeNode } from '@aws-amplify/api-graphql';
|
|
1
|
+
import { GraphQLOperation, GraphQLOptions, GraphQLResult, OperationTypeNode, GraphQLQuery, GraphQLSubscription } from '@aws-amplify/api-graphql';
|
|
2
2
|
import { CustomUserAgentDetails } from '@aws-amplify/core';
|
|
3
3
|
import { AWSAppSyncRealTimeProvider } from '@aws-amplify/pubsub';
|
|
4
4
|
import Observable from 'zen-observable-ts';
|
|
5
|
-
import { GraphQLQuery, GraphQLSubscription } from '../types';
|
|
6
5
|
/**
|
|
7
6
|
* @deprecated
|
|
8
7
|
* Use RestApi or GraphQLAPI to reduce your application bundle size
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InternalAPI.js","sourceRoot":"","sources":["../../src/internals/InternalAPI.ts"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"InternalAPI.js","sourceRoot":"","sources":["../../src/internals/InternalAPI.ts"],"names":[],"mappings":";AAUA,OAAO,EAAE,uBAAuB,EAAE,MAAM,oCAAoC,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AACrD,OAAO,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AACzC,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EACN,OAAO,EACP,SAAS,EACT,QAAQ,EACR,WAAW,EAEX,aAAa,IAAI,MAAM,GACvB,MAAM,mBAAmB,CAAC;AAI3B,IAAM,MAAM,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC;AACjC;;;;GAIG;AACH;IAaC;;;OAGG;IACH,0BAAY,OAAO;QARnB,SAAI,GAAG,IAAI,CAAC;QACZ,UAAK,GAAG,KAAK,CAAC;QACd,gBAAW,GAAG,WAAW,CAAC;QAOzB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,QAAQ,GAAG,IAAI,YAAY,CAAC,OAAO,CAAC,CAAC;QAC1C,IAAI,CAAC,WAAW,GAAG,IAAI,uBAAuB,CAAC,OAAO,CAAC,CAAC;QACxD,MAAM,CAAC,KAAK,CAAC,aAAa,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC5C,CAAC;IAEM,wCAAa,GAApB;QACC,OAAO,aAAa,CAAC;IACtB,CAAC;IAED;;;;OAIG;IACH,oCAAS,GAAT,UAAU,OAAO;QAChB,IAAI,CAAC,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AAE,OAAO,CAAC,CAAC;SACjD;QACD,OAAO,KAAK,CAAC;IACd,CAAC;IAEO,4DAAiC,GAAzC,UACC,IAA4B,EAC5B,MAAiB;QAEjB,IAAM,sBAAsB,GAA2B;YACtD,QAAQ,EAAE,QAAQ,CAAC,GAAG;YACtB,MAAM,QAAA;SACN,CAAC;QACF,IAAM,UAAU,yBAAQ,IAAI,KAAE,sBAAsB,wBAAA,GAAE,CAAC;QACvD,OAAO,UAAU,CAAC;IACnB,CAAC;IAED;;;;OAIG;IACG,mCAAQ,GAAd,UAAe,OAAe;;;gBAC7B,sBAAO,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAC;;;KACvC;IAED;;;OAGG;IACH,kDAAuB,GAAvB,UAAwB,SAA2B;QAClD,OAAO,IAAI,CAAC,WAAW,CAAC,uBAAuB,CAAC,SAAS,CAAC,CAAC;IAC5D,CAAC;IAqBD,kCAAO,GAAP,UACC,OAAuB,EACvB,iBAA6C,EAC7C,sBAA+C;QAE/C,IAAM,mBAAmB,cACxB,QAAQ,EAAE,QAAQ,CAAC,GAAG,EACtB,MAAM,EAAE,SAAS,CAAC,OAAO,IACtB,sBAAsB,CACzB,CAAC;QAEF,OAAO,IAAI,CAAC,WAAW,CAAC,OAAO,CAC9B,OAAO,EACP,iBAAiB,EACjB,mBAAmB,CACnB,CAAC;IACH,CAAC;IACF,uBAAC;AAAD,CAAC,AA3PD,IA2PC;;AAED,MAAM,CAAC,IAAM,WAAW,GAAG,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC;AACtD,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC"}
|
package/lib-esm/types/index.d.ts
CHANGED
|
@@ -3,11 +3,4 @@
|
|
|
3
3
|
* generates code that relies on this import path https://github.com/aws-amplify/amplify-cli/issues/3863
|
|
4
4
|
* This will be removed in future release when CLI and customers moves to recommeneded import styles.
|
|
5
5
|
*/
|
|
6
|
-
export { graphqlOperation, GraphQLAuthError, GraphQLResult, GRAPHQL_AUTH_MODE, } from '@aws-amplify/api-graphql';
|
|
7
|
-
declare const queryType: unique symbol;
|
|
8
|
-
export declare type GraphQLQuery<T> = T & {
|
|
9
|
-
readonly [queryType]: 'query';
|
|
10
|
-
};
|
|
11
|
-
export declare type GraphQLSubscription<T> = T & {
|
|
12
|
-
readonly [queryType]: 'subscription';
|
|
13
|
-
};
|
|
6
|
+
export { graphqlOperation, GraphQLAuthError, GraphQLResult, GRAPHQL_AUTH_MODE, GraphQLQuery, GraphQLSubscription, } from '@aws-amplify/api-graphql';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC;;;;GAIG;AACH,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAEhB,iBAAiB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,sCAAsC;AAEtC;;;;GAIG;AACH,OAAO,EACN,gBAAgB,EAChB,gBAAgB,EAEhB,iBAAiB,GAGjB,MAAM,0BAA0B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/api",
|
|
3
|
-
"version": "5.4.
|
|
3
|
+
"version": "5.4.6-api-v6.2fd20b7.0+2fd20b7",
|
|
4
4
|
"description": "Api category of aws-amplify",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib-esm/index.js",
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"clean:size": "rimraf dual-publish-tmp tmp*",
|
|
36
36
|
"format": "echo \"Not implemented\"",
|
|
37
37
|
"lint": "tslint 'src/**/*.ts' && npm run ts-coverage",
|
|
38
|
-
"ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t
|
|
38
|
+
"ts-coverage": "typescript-coverage-report -p ./tsconfig.build.json -t 88"
|
|
39
39
|
},
|
|
40
40
|
"repository": {
|
|
41
41
|
"type": "git",
|
|
@@ -48,7 +48,8 @@
|
|
|
48
48
|
},
|
|
49
49
|
"homepage": "https://aws-amplify.github.io/",
|
|
50
50
|
"devDependencies": {
|
|
51
|
-
"@types/zen-observable": "^0.8.0"
|
|
51
|
+
"@types/zen-observable": "^0.8.0",
|
|
52
|
+
"typescript": "5.1.6"
|
|
52
53
|
},
|
|
53
54
|
"files": [
|
|
54
55
|
"lib",
|
|
@@ -58,16 +59,17 @@
|
|
|
58
59
|
"internals"
|
|
59
60
|
],
|
|
60
61
|
"dependencies": {
|
|
61
|
-
"@aws-amplify/api-graphql": "3.4.
|
|
62
|
-
"@aws-amplify/api-rest": "3.5.
|
|
63
|
-
"
|
|
62
|
+
"@aws-amplify/api-graphql": "3.4.12-api-v6.2fd20b7.0+2fd20b7",
|
|
63
|
+
"@aws-amplify/api-rest": "3.5.6-api-v6.2fd20b7.0+2fd20b7",
|
|
64
|
+
"@aws-amplify/types-package-alpha": "0.0.1-api-v6.2fd20b7.0+2fd20b7",
|
|
65
|
+
"tslib": "^2.6.1"
|
|
64
66
|
},
|
|
65
67
|
"size-limit": [
|
|
66
68
|
{
|
|
67
69
|
"name": "API (top-level class)",
|
|
68
70
|
"path": "./lib-esm/index.js",
|
|
69
71
|
"import": "{ Amplify, API }",
|
|
70
|
-
"limit": "
|
|
72
|
+
"limit": "93.82 kB"
|
|
71
73
|
}
|
|
72
74
|
],
|
|
73
75
|
"jest": {
|
|
@@ -114,5 +116,5 @@
|
|
|
114
116
|
"lib-esm"
|
|
115
117
|
]
|
|
116
118
|
},
|
|
117
|
-
"gitHead": "
|
|
119
|
+
"gitHead": "2fd20b795c222663f811d4daf68a475497127fd7"
|
|
118
120
|
}
|
package/src/API.ts
CHANGED
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { AWSAppSyncRealTimeProvider } from '@aws-amplify/pubsub';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
GraphQLOptions,
|
|
6
|
+
GraphQLResult,
|
|
7
|
+
GraphQLQuery,
|
|
8
|
+
GraphQLSubscription,
|
|
9
|
+
} from '@aws-amplify/api-graphql';
|
|
10
|
+
import { graphql as v6graphql } from '@aws-amplify/api-graphql/internals';
|
|
5
11
|
import { Amplify, ConsoleLogger as Logger } from '@aws-amplify/core';
|
|
6
12
|
import Observable from 'zen-observable-ts';
|
|
7
|
-
import { GraphQLQuery, GraphQLSubscription } from './types';
|
|
8
13
|
import { InternalAPIClass } from './internals/InternalAPI';
|
|
14
|
+
import type { ModelTypes } from '@aws-amplify/types-package-alpha';
|
|
9
15
|
|
|
10
16
|
const logger = new Logger('API');
|
|
11
17
|
/**
|
|
@@ -42,7 +48,233 @@ export class APIClass extends InternalAPIClass {
|
|
|
42
48
|
): Promise<GraphQLResult<any>> | Observable<object> {
|
|
43
49
|
return super.graphql(options, additionalHeaders);
|
|
44
50
|
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Generates an API client that can work with models or raw GraphQL
|
|
54
|
+
*/
|
|
55
|
+
generateClient<T extends Record<any, any> = never>(): V6Client<T> {
|
|
56
|
+
const config = super.configure({});
|
|
57
|
+
|
|
58
|
+
const { modelIntrospection } = config;
|
|
59
|
+
|
|
60
|
+
const client: V6Client<any> = {
|
|
61
|
+
graphql: v6graphql,
|
|
62
|
+
models: {},
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
for (const model of Object.values(modelIntrospection.models)) {
|
|
66
|
+
const { name } = model as any;
|
|
67
|
+
|
|
68
|
+
client.models[name] = {} as any;
|
|
69
|
+
|
|
70
|
+
Object.entries(graphQLOperationsInfo).forEach(
|
|
71
|
+
([key, { operationPrefix }]) => {
|
|
72
|
+
const operation = key as ModelOperation;
|
|
73
|
+
|
|
74
|
+
// e.g. clients.models.Todo.update
|
|
75
|
+
client.models[name][operationPrefix] = async (arg?: any) => {
|
|
76
|
+
const query = generateGraphQLDocument(model, operation);
|
|
77
|
+
const variables = buildGraphQLVariables(model, operation, arg);
|
|
78
|
+
|
|
79
|
+
const res = (await this.graphql({
|
|
80
|
+
query,
|
|
81
|
+
variables,
|
|
82
|
+
})) as any;
|
|
83
|
+
|
|
84
|
+
// flatten response
|
|
85
|
+
if (res.data !== undefined) {
|
|
86
|
+
const [key] = Object.keys(res.data);
|
|
87
|
+
|
|
88
|
+
if (res.data[key].items) {
|
|
89
|
+
return res.data[key].items;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
return res.data[key];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return res;
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return client as V6Client<T>;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const graphQLOperationsInfo = {
|
|
106
|
+
CREATE: { operationPrefix: 'create' as const, usePlural: false },
|
|
107
|
+
READ: { operationPrefix: 'get' as const, usePlural: false },
|
|
108
|
+
UPDATE: { operationPrefix: 'update' as const, usePlural: false },
|
|
109
|
+
DELETE: { operationPrefix: 'delete' as const, usePlural: false },
|
|
110
|
+
LIST: { operationPrefix: 'list' as const, usePlural: true },
|
|
111
|
+
};
|
|
112
|
+
type ModelOperation = keyof typeof graphQLOperationsInfo;
|
|
113
|
+
type OperationPrefix =
|
|
114
|
+
(typeof graphQLOperationsInfo)[ModelOperation]['operationPrefix'];
|
|
115
|
+
|
|
116
|
+
const graphQLDocumentsCache = new Map<string, Map<ModelOperation, string>>();
|
|
117
|
+
|
|
118
|
+
function generateGraphQLDocument(
|
|
119
|
+
modelDefinition: any,
|
|
120
|
+
modelOperation: ModelOperation
|
|
121
|
+
): string {
|
|
122
|
+
const {
|
|
123
|
+
name,
|
|
124
|
+
pluralName,
|
|
125
|
+
fields,
|
|
126
|
+
primaryKeyInfo: {
|
|
127
|
+
isCustomPrimaryKey,
|
|
128
|
+
primaryKeyFieldName,
|
|
129
|
+
sortKeyFieldNames,
|
|
130
|
+
},
|
|
131
|
+
} = modelDefinition;
|
|
132
|
+
const { operationPrefix, usePlural } = graphQLOperationsInfo[modelOperation];
|
|
133
|
+
|
|
134
|
+
const fromCache = graphQLDocumentsCache.get(name)?.get(modelOperation);
|
|
135
|
+
|
|
136
|
+
if (fromCache !== undefined) {
|
|
137
|
+
return fromCache;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (!graphQLDocumentsCache.has(name)) {
|
|
141
|
+
graphQLDocumentsCache.set(name, new Map());
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
const graphQLFieldName = `${operationPrefix}${usePlural ? pluralName : name}`;
|
|
145
|
+
let graphQLOperationType: 'mutation' | 'query' | undefined;
|
|
146
|
+
let graphQLSelectionSet: string | undefined;
|
|
147
|
+
let graphQLArguments: Record<string, any> | undefined;
|
|
148
|
+
|
|
149
|
+
const selectionSetFields = Object.values<any>(fields)
|
|
150
|
+
.map(({ type, name }) => typeof type === 'string' && name) // Only scalars for now
|
|
151
|
+
.filter(Boolean)
|
|
152
|
+
.join(' ');
|
|
153
|
+
|
|
154
|
+
switch (modelOperation) {
|
|
155
|
+
case 'CREATE':
|
|
156
|
+
case 'UPDATE':
|
|
157
|
+
case 'DELETE':
|
|
158
|
+
graphQLArguments ??
|
|
159
|
+
(graphQLArguments = {
|
|
160
|
+
input: `${
|
|
161
|
+
operationPrefix.charAt(0).toLocaleUpperCase() +
|
|
162
|
+
operationPrefix.slice(1)
|
|
163
|
+
}${name}Input!`,
|
|
164
|
+
});
|
|
165
|
+
graphQLOperationType ?? (graphQLOperationType = 'mutation');
|
|
166
|
+
case 'READ':
|
|
167
|
+
graphQLArguments ??
|
|
168
|
+
(graphQLArguments = isCustomPrimaryKey
|
|
169
|
+
? [primaryKeyFieldName, ...sortKeyFieldNames].reduce(
|
|
170
|
+
(acc, fieldName) => {
|
|
171
|
+
acc[fieldName] = fields[fieldName].type;
|
|
172
|
+
|
|
173
|
+
return acc;
|
|
174
|
+
},
|
|
175
|
+
{}
|
|
176
|
+
)
|
|
177
|
+
: {
|
|
178
|
+
[primaryKeyFieldName]: `${fields[primaryKeyFieldName].type}!`,
|
|
179
|
+
});
|
|
180
|
+
graphQLSelectionSet ?? (graphQLSelectionSet = selectionSetFields);
|
|
181
|
+
case 'LIST':
|
|
182
|
+
graphQLOperationType ?? (graphQLOperationType = 'query');
|
|
183
|
+
graphQLSelectionSet ??
|
|
184
|
+
(graphQLSelectionSet = `items { ${selectionSetFields} }`);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const graphQLDocument = `${graphQLOperationType}${
|
|
188
|
+
graphQLArguments
|
|
189
|
+
? `(${Object.entries(graphQLArguments).map(
|
|
190
|
+
([fieldName, type]) => `\$${fieldName}: ${type}`
|
|
191
|
+
)})`
|
|
192
|
+
: ''
|
|
193
|
+
} { ${graphQLFieldName}${
|
|
194
|
+
graphQLArguments
|
|
195
|
+
? `(${Object.keys(graphQLArguments).map(
|
|
196
|
+
fieldName => `${fieldName}: \$${fieldName}`
|
|
197
|
+
)})`
|
|
198
|
+
: ''
|
|
199
|
+
} { ${graphQLSelectionSet} } }`;
|
|
200
|
+
|
|
201
|
+
graphQLDocumentsCache.get(name)?.set(modelOperation, graphQLDocument);
|
|
202
|
+
|
|
203
|
+
return graphQLDocument;
|
|
45
204
|
}
|
|
46
205
|
|
|
206
|
+
function buildGraphQLVariables(
|
|
207
|
+
modelDefinition: any,
|
|
208
|
+
operation: ModelOperation,
|
|
209
|
+
arg: any
|
|
210
|
+
): object {
|
|
211
|
+
const {
|
|
212
|
+
fields,
|
|
213
|
+
primaryKeyInfo: {
|
|
214
|
+
isCustomPrimaryKey,
|
|
215
|
+
primaryKeyFieldName,
|
|
216
|
+
sortKeyFieldNames,
|
|
217
|
+
},
|
|
218
|
+
} = modelDefinition;
|
|
219
|
+
|
|
220
|
+
let variables = {};
|
|
221
|
+
|
|
222
|
+
switch (operation) {
|
|
223
|
+
case 'CREATE':
|
|
224
|
+
variables = { input: arg };
|
|
225
|
+
break;
|
|
226
|
+
case 'UPDATE':
|
|
227
|
+
// readonly fields are not updated
|
|
228
|
+
variables = {
|
|
229
|
+
input: Object.fromEntries(
|
|
230
|
+
Object.entries(arg).filter(([fieldName]) => {
|
|
231
|
+
const { isReadOnly } = fields[fieldName];
|
|
232
|
+
|
|
233
|
+
return !isReadOnly;
|
|
234
|
+
})
|
|
235
|
+
),
|
|
236
|
+
};
|
|
237
|
+
break;
|
|
238
|
+
case 'READ':
|
|
239
|
+
case 'DELETE':
|
|
240
|
+
// only identifiers are sent
|
|
241
|
+
variables = isCustomPrimaryKey
|
|
242
|
+
? [primaryKeyFieldName, ...sortKeyFieldNames].reduce(
|
|
243
|
+
(acc, fieldName) => {
|
|
244
|
+
acc[fieldName] = arg[fieldName];
|
|
245
|
+
|
|
246
|
+
return acc;
|
|
247
|
+
},
|
|
248
|
+
{}
|
|
249
|
+
)
|
|
250
|
+
: { [primaryKeyFieldName]: arg[primaryKeyFieldName] };
|
|
251
|
+
|
|
252
|
+
if (operation === 'DELETE') {
|
|
253
|
+
variables = { input: variables };
|
|
254
|
+
}
|
|
255
|
+
break;
|
|
256
|
+
case 'LIST':
|
|
257
|
+
break;
|
|
258
|
+
default:
|
|
259
|
+
const exhaustiveCheck: never = operation;
|
|
260
|
+
throw new Error(`Unhandled operation case: ${exhaustiveCheck}`);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
return variables;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
type FilteredKeys<T> = {
|
|
267
|
+
[P in keyof T]: T[P] extends never ? never : P;
|
|
268
|
+
}[keyof T];
|
|
269
|
+
type ExcludeNeverFields<O> = {
|
|
270
|
+
[K in FilteredKeys<O>]: O[K];
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
// If no T is passed, ExcludeNeverFields removes "models" from the client
|
|
274
|
+
declare type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
|
|
275
|
+
graphql: typeof v6graphql;
|
|
276
|
+
models: ModelTypes<T>;
|
|
277
|
+
}>;
|
|
278
|
+
|
|
47
279
|
export const API = new APIClass(null);
|
|
48
280
|
Amplify.register(API);
|
|
@@ -5,6 +5,8 @@ import {
|
|
|
5
5
|
GraphQLOptions,
|
|
6
6
|
GraphQLResult,
|
|
7
7
|
OperationTypeNode,
|
|
8
|
+
GraphQLQuery,
|
|
9
|
+
GraphQLSubscription,
|
|
8
10
|
} from '@aws-amplify/api-graphql';
|
|
9
11
|
import { InternalGraphQLAPIClass } from '@aws-amplify/api-graphql/internals';
|
|
10
12
|
import { RestAPIClass } from '@aws-amplify/api-rest';
|
|
@@ -20,7 +22,6 @@ import {
|
|
|
20
22
|
} from '@aws-amplify/core';
|
|
21
23
|
import { AWSAppSyncRealTimeProvider } from '@aws-amplify/pubsub';
|
|
22
24
|
import Observable from 'zen-observable-ts';
|
|
23
|
-
import { GraphQLQuery, GraphQLSubscription } from '../types';
|
|
24
25
|
|
|
25
26
|
const logger = new Logger('API');
|
|
26
27
|
/**
|
package/src/types/index.ts
CHANGED
|
@@ -11,12 +11,6 @@ export {
|
|
|
11
11
|
GraphQLAuthError,
|
|
12
12
|
GraphQLResult,
|
|
13
13
|
GRAPHQL_AUTH_MODE,
|
|
14
|
+
GraphQLQuery,
|
|
15
|
+
GraphQLSubscription,
|
|
14
16
|
} from '@aws-amplify/api-graphql';
|
|
15
|
-
|
|
16
|
-
// Opaque type used for determining the graphql query type
|
|
17
|
-
declare const queryType: unique symbol;
|
|
18
|
-
|
|
19
|
-
export type GraphQLQuery<T> = T & { readonly [queryType]: 'query' };
|
|
20
|
-
export type GraphQLSubscription<T> = T & {
|
|
21
|
-
readonly [queryType]: 'subscription';
|
|
22
|
-
};
|