@aws-amplify/data-schema 1.3.10 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/ModelType.js +5 -0
- package/dist/cjs/ModelType.js.map +1 -1
- package/dist/cjs/SchemaProcessor.js +58 -1
- package/dist/cjs/SchemaProcessor.js.map +1 -1
- package/dist/cjs/runtime/addSchemaToClient.js +1 -0
- package/dist/cjs/runtime/addSchemaToClient.js.map +1 -1
- package/dist/cjs/runtime/addSchemaToClientWithInstance.js +1 -0
- package/dist/cjs/runtime/addSchemaToClientWithInstance.js.map +1 -1
- package/dist/cjs/runtime/internals/APIClient.js +63 -42
- package/dist/cjs/runtime/internals/APIClient.js.map +1 -1
- package/dist/cjs/runtime/internals/cancellation.js +48 -0
- package/dist/cjs/runtime/internals/cancellation.js.map +1 -0
- package/dist/cjs/runtime/internals/clientUtils.js +45 -3
- package/dist/cjs/runtime/internals/clientUtils.js.map +1 -1
- package/dist/cjs/runtime/internals/index.js +3 -1
- package/dist/cjs/runtime/internals/index.js.map +1 -1
- package/dist/cjs/runtime/internals/operations/custom.js +91 -85
- package/dist/cjs/runtime/internals/operations/custom.js.map +1 -1
- package/dist/cjs/runtime/internals/operations/get.js +71 -65
- package/dist/cjs/runtime/internals/operations/get.js.map +1 -1
- package/dist/cjs/runtime/internals/operations/indexQuery.js +66 -60
- package/dist/cjs/runtime/internals/operations/indexQuery.js.map +1 -1
- package/dist/cjs/runtime/internals/operations/list.js +90 -84
- package/dist/cjs/runtime/internals/operations/list.js.map +1 -1
- package/dist/cjs/runtime/internals/server/generateModelsProperty.js +3 -3
- package/dist/cjs/runtime/internals/server/generateModelsProperty.js.map +1 -1
- package/dist/cjs/runtime/internals/utils/clientProperties/generateModelsProperty.js +3 -3
- package/dist/cjs/runtime/internals/utils/clientProperties/generateModelsProperty.js.map +1 -1
- package/dist/cjs/runtime/utils/index.js +3 -1
- package/dist/cjs/runtime/utils/index.js.map +1 -1
- package/dist/cjs/runtime/utils/selfAwareAsync.js +40 -0
- package/dist/cjs/runtime/utils/selfAwareAsync.js.map +1 -0
- package/dist/esm/Authorization.d.ts +1 -1
- package/dist/esm/ClientSchema/Core/ClientModel.d.ts +20 -1
- package/dist/esm/ClientSchema/utilities/ResolveField.d.ts +5 -1
- package/dist/esm/ModelType.d.ts +6 -0
- package/dist/esm/ModelType.mjs +5 -0
- package/dist/esm/ModelType.mjs.map +1 -1
- package/dist/esm/SchemaProcessor.mjs +58 -1
- package/dist/esm/SchemaProcessor.mjs.map +1 -1
- package/dist/esm/runtime/addSchemaToClient.mjs +2 -0
- package/dist/esm/runtime/addSchemaToClient.mjs.map +1 -1
- package/dist/esm/runtime/addSchemaToClientWithInstance.mjs +2 -0
- package/dist/esm/runtime/addSchemaToClientWithInstance.mjs.map +1 -1
- package/dist/esm/runtime/bridge-types.d.ts +2 -2
- package/dist/esm/runtime/client/index.d.ts +6 -6
- package/dist/esm/runtime/internals/APIClient.d.ts +2 -2
- package/dist/esm/runtime/internals/APIClient.mjs +64 -42
- package/dist/esm/runtime/internals/APIClient.mjs.map +1 -1
- package/dist/esm/runtime/internals/cancellation.d.ts +10 -0
- package/dist/esm/runtime/internals/cancellation.mjs +44 -0
- package/dist/esm/runtime/internals/cancellation.mjs.map +1 -0
- package/dist/esm/runtime/internals/clientUtils.d.ts +78 -1
- package/dist/esm/runtime/internals/clientUtils.mjs +45 -3
- package/dist/esm/runtime/internals/clientUtils.mjs.map +1 -1
- package/dist/esm/runtime/internals/index.d.ts +1 -0
- package/dist/esm/runtime/internals/index.mjs +1 -0
- package/dist/esm/runtime/internals/index.mjs.map +1 -1
- package/dist/esm/runtime/internals/operations/custom.d.ts +1 -1
- package/dist/esm/runtime/internals/operations/custom.mjs +91 -85
- package/dist/esm/runtime/internals/operations/custom.mjs.map +1 -1
- package/dist/esm/runtime/internals/operations/get.d.ts +1 -1
- package/dist/esm/runtime/internals/operations/get.mjs +71 -65
- package/dist/esm/runtime/internals/operations/get.mjs.map +1 -1
- package/dist/esm/runtime/internals/operations/indexQuery.d.ts +1 -1
- package/dist/esm/runtime/internals/operations/indexQuery.mjs +66 -60
- package/dist/esm/runtime/internals/operations/indexQuery.mjs.map +1 -1
- package/dist/esm/runtime/internals/operations/list.d.ts +1 -1
- package/dist/esm/runtime/internals/operations/list.mjs +90 -84
- package/dist/esm/runtime/internals/operations/list.mjs.map +1 -1
- package/dist/esm/runtime/internals/server/generateModelsProperty.mjs +4 -4
- package/dist/esm/runtime/internals/server/generateModelsProperty.mjs.map +1 -1
- package/dist/esm/runtime/internals/utils/clientProperties/generateModelsProperty.mjs +4 -4
- package/dist/esm/runtime/internals/utils/clientProperties/generateModelsProperty.mjs.map +1 -1
- package/dist/esm/runtime/utils/index.d.ts +1 -0
- package/dist/esm/runtime/utils/index.mjs +1 -0
- package/dist/esm/runtime/utils/index.mjs.map +1 -1
- package/dist/esm/runtime/utils/selfAwareAsync.d.ts +19 -0
- package/dist/esm/runtime/utils/selfAwareAsync.mjs +37 -0
- package/dist/esm/runtime/utils/selfAwareAsync.mjs.map +1 -0
- package/dist/meta/cjs.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/ClientSchema/Core/ClientModel.ts +29 -0
- package/src/ClientSchema/utilities/ResolveField.ts +26 -6
- package/src/ModelType.ts +31 -0
- package/src/SchemaProcessor.ts +77 -2
- package/src/runtime/addSchemaToClient.ts +2 -0
- package/src/runtime/addSchemaToClientWithInstance.ts +2 -0
- package/src/runtime/bridge-types.ts +2 -2
- package/src/runtime/client/index.ts +207 -184
- package/src/runtime/internals/APIClient.ts +67 -23
- package/src/runtime/internals/cancellation.ts +57 -0
- package/src/runtime/internals/clientUtils.ts +61 -1
- package/src/runtime/internals/index.ts +1 -0
- package/src/runtime/internals/operations/custom.ts +117 -109
- package/src/runtime/internals/operations/get.ts +111 -95
- package/src/runtime/internals/operations/indexQuery.ts +100 -94
- package/src/runtime/internals/operations/list.ts +132 -119
- package/src/runtime/internals/server/generateModelsProperty.ts +31 -28
- package/src/runtime/internals/utils/clientProperties/generateModelsProperty.ts +36 -33
- package/src/runtime/utils/index.ts +1 -0
- package/src/runtime/utils/selfAwareAsync.ts +39 -0
|
@@ -4,92 +4,98 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.getFactory = void 0;
|
|
5
5
|
const APIClient_1 = require("../APIClient");
|
|
6
6
|
const utils_1 = require("./utils");
|
|
7
|
+
const utils_2 = require("../../utils");
|
|
8
|
+
const cancellation_1 = require("../cancellation");
|
|
7
9
|
function getFactory(client, modelIntrospection, model, operation, getInternals, useContext = false) {
|
|
8
|
-
const getWithContext =
|
|
10
|
+
const getWithContext = (contextSpec, arg, options) => {
|
|
9
11
|
return _get(client, modelIntrospection, model, arg, options, operation, getInternals, contextSpec);
|
|
10
12
|
};
|
|
11
|
-
const get =
|
|
13
|
+
const get = (arg, options) => {
|
|
12
14
|
return _get(client, modelIntrospection, model, arg, options, operation, getInternals);
|
|
13
15
|
};
|
|
14
16
|
return useContext ? getWithContext : get;
|
|
15
17
|
}
|
|
16
18
|
exports.getFactory = getFactory;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
19
|
+
function _get(client, modelIntrospection, model, arg, options, operation, getInternals, context) {
|
|
20
|
+
return (0, utils_2.selfAwareAsync)(async (resultPromise) => {
|
|
21
|
+
const { name } = model;
|
|
22
|
+
const query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection, name, operation, options);
|
|
23
|
+
const variables = (0, APIClient_1.buildGraphQLVariables)(model, operation, arg, modelIntrospection);
|
|
24
|
+
const auth = (0, APIClient_1.authModeParams)(client, getInternals, options);
|
|
25
|
+
try {
|
|
26
|
+
const headers = (0, APIClient_1.getCustomHeaders)(client, getInternals, options?.headers);
|
|
27
|
+
const basePromise = context
|
|
28
|
+
? client.graphql(context, {
|
|
29
|
+
...auth,
|
|
30
|
+
query,
|
|
31
|
+
variables,
|
|
32
|
+
}, headers)
|
|
33
|
+
: client.graphql({
|
|
34
|
+
...auth,
|
|
35
|
+
query,
|
|
36
|
+
variables,
|
|
37
|
+
}, headers);
|
|
38
|
+
const extendedPromise = (0, cancellation_1.extendCancellability)(basePromise, resultPromise);
|
|
39
|
+
const { data, extensions } = await extendedPromise;
|
|
40
|
+
// flatten response
|
|
41
|
+
if (data) {
|
|
42
|
+
const [key] = Object.keys(data);
|
|
43
|
+
const flattenedResult = (0, APIClient_1.flattenItems)(modelIntrospection, name, data[key]);
|
|
44
|
+
if (flattenedResult === null) {
|
|
45
|
+
return { data: null, extensions };
|
|
46
|
+
}
|
|
47
|
+
else if (options?.selectionSet) {
|
|
48
|
+
return { data: flattenedResult, extensions };
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
// TODO: refactor to avoid destructuring here
|
|
52
|
+
const [initialized] = (0, APIClient_1.initializeModel)(client, name, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context);
|
|
53
|
+
return { data: initialized, extensions };
|
|
54
|
+
}
|
|
44
55
|
}
|
|
45
56
|
else {
|
|
46
|
-
|
|
47
|
-
const [initialized] = (0, APIClient_1.initializeModel)(client, name, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context);
|
|
48
|
-
return { data: initialized, extensions };
|
|
57
|
+
return { data: null, extensions };
|
|
49
58
|
}
|
|
50
59
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
* 3) "populated" but with a `null` value `{ getPost: null }`
|
|
61
|
-
* 4) an actual record `{ getPost: { id: '1', title: 'Hello, World!' } }`
|
|
62
|
-
*/
|
|
63
|
-
const { data, errors } = error;
|
|
64
|
-
/**
|
|
65
|
-
* `data` is not `null`, and is not an empty object:
|
|
66
|
-
*/
|
|
67
|
-
if (data && Object.keys(data).length !== 0 && errors) {
|
|
68
|
-
const [key] = Object.keys(data);
|
|
69
|
-
const flattenedResult = (0, APIClient_1.flattenItems)(modelIntrospection, name, data[key]);
|
|
60
|
+
catch (error) {
|
|
61
|
+
/**
|
|
62
|
+
* The `data` type returned by `error` here could be:
|
|
63
|
+
* 1) `null`
|
|
64
|
+
* 2) an empty object
|
|
65
|
+
* 3) "populated" but with a `null` value `{ getPost: null }`
|
|
66
|
+
* 4) an actual record `{ getPost: { id: '1', title: 'Hello, World!' } }`
|
|
67
|
+
*/
|
|
68
|
+
const { data, errors } = error;
|
|
70
69
|
/**
|
|
71
|
-
* `
|
|
72
|
-
* if `flattenedResult`, result is an actual record:
|
|
70
|
+
* `data` is not `null`, and is not an empty object:
|
|
73
71
|
*/
|
|
74
|
-
if (
|
|
75
|
-
|
|
76
|
-
|
|
72
|
+
if (data && Object.keys(data).length !== 0 && errors) {
|
|
73
|
+
const [key] = Object.keys(data);
|
|
74
|
+
const flattenedResult = (0, APIClient_1.flattenItems)(modelIntrospection, name, data[key]);
|
|
75
|
+
/**
|
|
76
|
+
* `flattenedResult` could be `null` here (e.g. `data: { getPost: null }`)
|
|
77
|
+
* if `flattenedResult`, result is an actual record:
|
|
78
|
+
*/
|
|
79
|
+
if (flattenedResult) {
|
|
80
|
+
if (options?.selectionSet) {
|
|
81
|
+
return { data: flattenedResult, errors };
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
// TODO: refactor to avoid destructuring here
|
|
85
|
+
const [initialized] = (0, APIClient_1.initializeModel)(client, name, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context);
|
|
86
|
+
return { data: initialized, errors };
|
|
87
|
+
}
|
|
77
88
|
}
|
|
78
89
|
else {
|
|
79
|
-
//
|
|
80
|
-
|
|
81
|
-
return { data: initialized, errors };
|
|
90
|
+
// was `data: { getPost: null }`)
|
|
91
|
+
return (0, utils_1.handleSingularGraphQlError)(error);
|
|
82
92
|
}
|
|
83
93
|
}
|
|
84
94
|
else {
|
|
85
|
-
//
|
|
95
|
+
// `data` is `null`:
|
|
86
96
|
return (0, utils_1.handleSingularGraphQlError)(error);
|
|
87
97
|
}
|
|
88
98
|
}
|
|
89
|
-
|
|
90
|
-
// `data` is `null`:
|
|
91
|
-
return (0, utils_1.handleSingularGraphQlError)(error);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
99
|
+
});
|
|
94
100
|
}
|
|
95
101
|
//# sourceMappingURL=get.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get.js","sources":["../../../../../src/runtime/internals/operations/get.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getFactory = void 0;\nconst APIClient_1 = require(\"../APIClient\");\nconst utils_1 = require(\"./utils\");\nfunction getFactory(client, modelIntrospection, model, operation, getInternals, useContext = false) {\n const getWithContext =
|
|
1
|
+
{"version":3,"file":"get.js","sources":["../../../../../src/runtime/internals/operations/get.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.getFactory = void 0;\nconst APIClient_1 = require(\"../APIClient\");\nconst utils_1 = require(\"./utils\");\nconst utils_2 = require(\"../../utils\");\nconst cancellation_1 = require(\"../cancellation\");\nfunction getFactory(client, modelIntrospection, model, operation, getInternals, useContext = false) {\n const getWithContext = (contextSpec, arg, options) => {\n return _get(client, modelIntrospection, model, arg, options, operation, getInternals, contextSpec);\n };\n const get = (arg, options) => {\n return _get(client, modelIntrospection, model, arg, options, operation, getInternals);\n };\n return useContext ? getWithContext : get;\n}\nexports.getFactory = getFactory;\nfunction _get(client, modelIntrospection, model, arg, options, operation, getInternals, context) {\n return (0, utils_2.selfAwareAsync)(async (resultPromise) => {\n const { name } = model;\n const query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection, name, operation, options);\n const variables = (0, APIClient_1.buildGraphQLVariables)(model, operation, arg, modelIntrospection);\n const auth = (0, APIClient_1.authModeParams)(client, getInternals, options);\n try {\n const headers = (0, APIClient_1.getCustomHeaders)(client, getInternals, options?.headers);\n const basePromise = context\n ? client.graphql(context, {\n ...auth,\n query,\n variables,\n }, headers)\n : client.graphql({\n ...auth,\n query,\n variables,\n }, headers);\n const extendedPromise = (0, cancellation_1.extendCancellability)(basePromise, resultPromise);\n const { data, extensions } = await extendedPromise;\n // flatten response\n if (data) {\n const [key] = Object.keys(data);\n const flattenedResult = (0, APIClient_1.flattenItems)(modelIntrospection, name, data[key]);\n if (flattenedResult === null) {\n return { data: null, extensions };\n }\n else if (options?.selectionSet) {\n return { data: flattenedResult, extensions };\n }\n else {\n // TODO: refactor to avoid destructuring here\n const [initialized] = (0, APIClient_1.initializeModel)(client, name, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context);\n return { data: initialized, extensions };\n }\n }\n else {\n return { data: null, extensions };\n }\n }\n catch (error) {\n /**\n * The `data` type returned by `error` here could be:\n * 1) `null`\n * 2) an empty object\n * 3) \"populated\" but with a `null` value `{ getPost: null }`\n * 4) an actual record `{ getPost: { id: '1', title: 'Hello, World!' } }`\n */\n const { data, errors } = error;\n /**\n * `data` is not `null`, and is not an empty object:\n */\n if (data && Object.keys(data).length !== 0 && errors) {\n const [key] = Object.keys(data);\n const flattenedResult = (0, APIClient_1.flattenItems)(modelIntrospection, name, data[key]);\n /**\n * `flattenedResult` could be `null` here (e.g. `data: { getPost: null }`)\n * if `flattenedResult`, result is an actual record:\n */\n if (flattenedResult) {\n if (options?.selectionSet) {\n return { data: flattenedResult, errors };\n }\n else {\n // TODO: refactor to avoid destructuring here\n const [initialized] = (0, APIClient_1.initializeModel)(client, name, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context);\n return { data: initialized, errors };\n }\n }\n else {\n // was `data: { getPost: null }`)\n return (0, utils_1.handleSingularGraphQlError)(error);\n }\n }\n else {\n // `data` is `null`:\n return (0, utils_1.handleSingularGraphQlError)(error);\n }\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,UAAU,GAAG,KAAK,CAAC,CAAC;AAC5B,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AACnC,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AACvC,MAAM,cAAc,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;AAClD,SAAS,UAAU,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,GAAG,KAAK,EAAE;AACpG,IAAI,MAAM,cAAc,GAAG,CAAC,WAAW,EAAE,GAAG,EAAE,OAAO,KAAK;AAC1D,QAAQ,OAAO,IAAI,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;AAC3G,KAAK,CAAC;AACN,IAAI,MAAM,GAAG,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK;AAClC,QAAQ,OAAO,IAAI,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;AAC9F,KAAK,CAAC;AACN,IAAI,OAAO,UAAU,GAAG,cAAc,GAAG,GAAG,CAAC;AAC7C,CAAC;AACD,OAAO,CAAC,UAAU,GAAG,UAAU,CAAC;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,MAAM,EAAE;AAClE,gBAAgB,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAChD,gBAAgB,MAAM,eAAe,GAAG,IAAI,WAAW,CAAC,YAAY,EAAE,kBAAkB,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAC3G;AACA;AACA;AACA;AACA,gBAAgB,IAAI,eAAe,EAAE;AACrC,oBAAoB,IAAI,OAAO,EAAE,YAAY,EAAE;AAC/C,wBAAwB,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,CAAC;AACjE,qBAAqB;AACrB,yBAAyB;AACzB;AACA,wBAAwB,MAAM,CAAC,WAAW,CAAC,GAAG,IAAI,WAAW,CAAC,eAAe,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,eAAe,CAAC,EAAE,kBAAkB,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;AAC9K,wBAAwB,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AAC7D,qBAAqB;AACrB,iBAAiB;AACjB,qBAAqB;AACrB;AACA,oBAAoB,OAAO,IAAI,OAAO,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC;AAC1E,iBAAiB;AACjB,aAAa;AACb,iBAAiB;AACjB;AACA,gBAAgB,OAAO,IAAI,OAAO,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC;AACtE,aAAa;AACb,SAAS;AACT,KAAK,CAAC,CAAC;AACP;;"}
|
|
@@ -4,14 +4,16 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.indexQueryFactory = void 0;
|
|
5
5
|
const APIClient_1 = require("../APIClient");
|
|
6
6
|
const utils_1 = require("./utils");
|
|
7
|
+
const utils_2 = require("../../utils");
|
|
8
|
+
const cancellation_1 = require("../cancellation");
|
|
7
9
|
function indexQueryFactory(client, modelIntrospection, model, indexMeta, getInternals, context = false) {
|
|
8
|
-
const indexQueryWithContext =
|
|
10
|
+
const indexQueryWithContext = (contextSpec, args, options) => {
|
|
9
11
|
return _indexQuery(client, modelIntrospection, model, indexMeta, getInternals, {
|
|
10
12
|
...args,
|
|
11
13
|
...options,
|
|
12
14
|
}, contextSpec);
|
|
13
15
|
};
|
|
14
|
-
const indexQuery =
|
|
16
|
+
const indexQuery = (args, options) => {
|
|
15
17
|
return _indexQuery(client, modelIntrospection, model, indexMeta, getInternals, {
|
|
16
18
|
...args,
|
|
17
19
|
...options,
|
|
@@ -38,67 +40,71 @@ function processGraphQlResponse(modelIntroSchema, modelName, result, selectionSe
|
|
|
38
40
|
extensions,
|
|
39
41
|
};
|
|
40
42
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
43
|
+
function _indexQuery(client, modelIntrospection, model, indexMeta, getInternals, args, contextSpec) {
|
|
44
|
+
return (0, utils_2.selfAwareAsync)(async (resultPromise) => {
|
|
45
|
+
const { name } = model;
|
|
46
|
+
const query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection, name, 'INDEX_QUERY', args, indexMeta);
|
|
47
|
+
const variables = (0, APIClient_1.buildGraphQLVariables)(model, 'INDEX_QUERY', args, modelIntrospection, indexMeta);
|
|
48
|
+
const auth = (0, APIClient_1.authModeParams)(client, getInternals, args);
|
|
49
|
+
const modelInitializer = (flattenedResult) => (0, APIClient_1.initializeModel)(client, name, flattenedResult, modelIntrospection, auth.authMode, auth.authToken, !!contextSpec);
|
|
50
|
+
try {
|
|
51
|
+
const headers = (0, APIClient_1.getCustomHeaders)(client, getInternals, args?.headers);
|
|
52
|
+
const graphQlParams = {
|
|
53
|
+
...auth,
|
|
54
|
+
query,
|
|
55
|
+
variables,
|
|
56
|
+
};
|
|
57
|
+
const requestArgs = [graphQlParams, headers];
|
|
58
|
+
if (contextSpec !== undefined) {
|
|
59
|
+
requestArgs.unshift(contextSpec);
|
|
60
|
+
}
|
|
61
|
+
const basePromise = client.graphql(...requestArgs);
|
|
62
|
+
const extendedPromise = (0, cancellation_1.extendCancellability)(basePromise, resultPromise);
|
|
63
|
+
const response = await extendedPromise;
|
|
64
|
+
if (response.data !== undefined) {
|
|
65
|
+
return processGraphQlResponse(modelIntrospection, name, response, args?.selectionSet, modelInitializer);
|
|
66
|
+
}
|
|
61
67
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
:
|
|
88
|
-
|
|
89
|
-
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
/**
|
|
70
|
+
* The `data` type returned by `error` here could be:
|
|
71
|
+
* 1) `null`
|
|
72
|
+
* 2) an empty object
|
|
73
|
+
* 3) "populated" but with a `null` value:
|
|
74
|
+
* `data: { listByExampleId: null }`
|
|
75
|
+
* 4) an actual record:
|
|
76
|
+
* `data: { listByExampleId: items: [{ id: '1', ...etc } }]`
|
|
77
|
+
*/
|
|
78
|
+
const { data, errors } = error;
|
|
79
|
+
// `data` is not `null`, and is not an empty object:
|
|
80
|
+
if (data !== undefined && Object.keys(data).length !== 0 && errors) {
|
|
81
|
+
const [key] = Object.keys(data);
|
|
82
|
+
if (data[key]?.items) {
|
|
83
|
+
const flattenedResult = data[key]?.items.map((value) => (0, APIClient_1.flattenItems)(modelIntrospection, name, value));
|
|
84
|
+
/**
|
|
85
|
+
* Check exists since `flattenedResult` could be `null`.
|
|
86
|
+
* if `flattenedResult` exists, result is an actual record.
|
|
87
|
+
*/
|
|
88
|
+
if (flattenedResult) {
|
|
89
|
+
return {
|
|
90
|
+
data: args?.selectionSet
|
|
91
|
+
? flattenedResult
|
|
92
|
+
: modelInitializer(flattenedResult),
|
|
93
|
+
nextToken: data[key]?.nextToken,
|
|
94
|
+
};
|
|
95
|
+
}
|
|
90
96
|
}
|
|
97
|
+
// response is of type `data: { listByExampleId: null }`
|
|
98
|
+
return {
|
|
99
|
+
data: data[key],
|
|
100
|
+
nextToken: data[key]?.nextToken,
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
// `data` is `null` or an empty object:
|
|
105
|
+
return (0, utils_1.handleListGraphQlError)(error);
|
|
91
106
|
}
|
|
92
|
-
// response is of type `data: { listByExampleId: null }`
|
|
93
|
-
return {
|
|
94
|
-
data: data[key],
|
|
95
|
-
nextToken: data[key]?.nextToken,
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
// `data` is `null` or an empty object:
|
|
100
|
-
return (0, utils_1.handleListGraphQlError)(error);
|
|
101
107
|
}
|
|
102
|
-
}
|
|
108
|
+
});
|
|
103
109
|
}
|
|
104
110
|
//# sourceMappingURL=indexQuery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indexQuery.js","sources":["../../../../../src/runtime/internals/operations/indexQuery.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.indexQueryFactory = void 0;\nconst APIClient_1 = require(\"../APIClient\");\nconst utils_1 = require(\"./utils\");\nfunction indexQueryFactory(client, modelIntrospection, model, indexMeta, getInternals, context = false) {\n const indexQueryWithContext =
|
|
1
|
+
{"version":3,"file":"indexQuery.js","sources":["../../../../../src/runtime/internals/operations/indexQuery.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.indexQueryFactory = void 0;\nconst APIClient_1 = require(\"../APIClient\");\nconst utils_1 = require(\"./utils\");\nconst utils_2 = require(\"../../utils\");\nconst cancellation_1 = require(\"../cancellation\");\nfunction indexQueryFactory(client, modelIntrospection, model, indexMeta, getInternals, context = false) {\n const indexQueryWithContext = (contextSpec, args, options) => {\n return _indexQuery(client, modelIntrospection, model, indexMeta, getInternals, {\n ...args,\n ...options,\n }, contextSpec);\n };\n const indexQuery = (args, options) => {\n return _indexQuery(client, modelIntrospection, model, indexMeta, getInternals, {\n ...args,\n ...options,\n });\n };\n return context ? indexQueryWithContext : indexQuery;\n}\nexports.indexQueryFactory = indexQueryFactory;\nfunction processGraphQlResponse(modelIntroSchema, modelName, result, selectionSet, modelInitializer) {\n const { data, extensions } = result;\n const [key] = Object.keys(data);\n if (data[key].items) {\n const flattenedResult = data[key].items.map((value) => (0, APIClient_1.flattenItems)(modelIntroSchema, modelName, value));\n return {\n data: selectionSet ? flattenedResult : modelInitializer(flattenedResult),\n nextToken: data[key].nextToken,\n extensions,\n };\n }\n // Index queries are always list queries. No `items`? No flattening needed.\n return {\n data: data[key],\n nextToken: data[key].nextToken,\n extensions,\n };\n}\nfunction _indexQuery(client, modelIntrospection, model, indexMeta, getInternals, args, contextSpec) {\n return (0, utils_2.selfAwareAsync)(async (resultPromise) => {\n const { name } = model;\n const query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection, name, 'INDEX_QUERY', args, indexMeta);\n const variables = (0, APIClient_1.buildGraphQLVariables)(model, 'INDEX_QUERY', args, modelIntrospection, indexMeta);\n const auth = (0, APIClient_1.authModeParams)(client, getInternals, args);\n const modelInitializer = (flattenedResult) => (0, APIClient_1.initializeModel)(client, name, flattenedResult, modelIntrospection, auth.authMode, auth.authToken, !!contextSpec);\n try {\n const headers = (0, APIClient_1.getCustomHeaders)(client, getInternals, args?.headers);\n const graphQlParams = {\n ...auth,\n query,\n variables,\n };\n const requestArgs = [graphQlParams, headers];\n if (contextSpec !== undefined) {\n requestArgs.unshift(contextSpec);\n }\n const basePromise = client.graphql(...requestArgs);\n const extendedPromise = (0, cancellation_1.extendCancellability)(basePromise, resultPromise);\n const response = await extendedPromise;\n if (response.data !== undefined) {\n return processGraphQlResponse(modelIntrospection, name, response, args?.selectionSet, modelInitializer);\n }\n }\n catch (error) {\n /**\n * The `data` type returned by `error` here could be:\n * 1) `null`\n * 2) an empty object\n * 3) \"populated\" but with a `null` value:\n * `data: { listByExampleId: null }`\n * 4) an actual record:\n * `data: { listByExampleId: items: [{ id: '1', ...etc } }]`\n */\n const { data, errors } = error;\n // `data` is not `null`, and is not an empty object:\n if (data !== undefined && Object.keys(data).length !== 0 && errors) {\n const [key] = Object.keys(data);\n if (data[key]?.items) {\n const flattenedResult = data[key]?.items.map((value) => (0, APIClient_1.flattenItems)(modelIntrospection, name, value));\n /**\n * Check exists since `flattenedResult` could be `null`.\n * if `flattenedResult` exists, result is an actual record.\n */\n if (flattenedResult) {\n return {\n data: args?.selectionSet\n ? flattenedResult\n : modelInitializer(flattenedResult),\n nextToken: data[key]?.nextToken,\n };\n }\n }\n // response is of type `data: { listByExampleId: null }`\n return {\n data: data[key],\n nextToken: data[key]?.nextToken,\n };\n }\n else {\n // `data` is `null` or an empty object:\n return (0, utils_1.handleListGraphQlError)(error);\n }\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,iBAAiB,GAAG,KAAK,CAAC,CAAC;AACnC,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AACnC,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;A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AC;AAChD,gBAAgB,IAAI,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE;AACtC,oBAAoB,MAAM,eAAe,GAAG,IAAI,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,KAAK,IAAI,WAAW,CAAC,YAAY,EAAE,kBAAkB,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;AAC5I;AACA;AACA;AACA;AACA,oBAAoB,IAAI,eAAe,EAAE;AACzC,wBAAwB,OAAO;AAC/B,4BAA4B,IAAI,EAAE,IAAI,EAAE,YAAY;AACpD,kCAAkC,eAAe;AACjD,kCAAkC,gBAAgB,CAAC,eAAe,CAAC;AACnE,4BAA4B,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,SAAS;AAC3D,yBAAyB,CAAC;AAC1B,qBAAqB;AACrB,iBAAiB;AACjB;AACA,gBAAgB,OAAO;AACvB,oBAAoB,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;AACnC,oBAAoB,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,SAAS;AACnD,iBAAiB,CAAC;AAClB,aAAa;AACb,iBAAiB;AACjB;AACA,gBAAgB,OAAO,IAAI,OAAO,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;AAClE,aAAa;AACb,SAAS;AACT,KAAK,CAAC,CAAC;AACP;;"}
|
|
@@ -4,118 +4,124 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.listFactory = void 0;
|
|
5
5
|
const APIClient_1 = require("../APIClient");
|
|
6
6
|
const utils_1 = require("./utils");
|
|
7
|
+
const utils_2 = require("../../utils");
|
|
8
|
+
const cancellation_1 = require("../cancellation");
|
|
7
9
|
function listFactory(client, modelIntrospection, model, getInternals, context = false) {
|
|
8
|
-
const listWithContext =
|
|
10
|
+
const listWithContext = (contextSpec, args) => {
|
|
9
11
|
return _list(client, modelIntrospection, model, getInternals, args, contextSpec);
|
|
10
12
|
};
|
|
11
|
-
const list =
|
|
13
|
+
const list = (args) => {
|
|
12
14
|
return _list(client, modelIntrospection, model, getInternals, args);
|
|
13
15
|
};
|
|
14
16
|
return context ? listWithContext : list;
|
|
15
17
|
}
|
|
16
18
|
exports.listFactory = listFactory;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
if (
|
|
42
|
-
|
|
43
|
-
data: flattenedResult,
|
|
44
|
-
nextToken: data[key].nextToken,
|
|
45
|
-
extensions,
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
const initialized = (0, APIClient_1.initializeModel)(client, name, flattenedResult, modelIntrospection, auth.authMode, auth.authToken, !!contextSpec);
|
|
50
|
-
return {
|
|
51
|
-
data: initialized,
|
|
52
|
-
nextToken: data[key].nextToken,
|
|
53
|
-
extensions,
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return {
|
|
58
|
-
data: data[key],
|
|
59
|
-
nextToken: data[key].nextToken,
|
|
60
|
-
extensions,
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
catch (error) {
|
|
65
|
-
/**
|
|
66
|
-
* The `data` type returned by `error` here could be:
|
|
67
|
-
* 1) `null`
|
|
68
|
-
* 2) an empty object
|
|
69
|
-
* 3) "populated" but with a `null` value `data: { listPosts: null }`
|
|
70
|
-
* 4) actual records `data: { listPosts: items: [{ id: '1', ...etc }] }`
|
|
71
|
-
*/
|
|
72
|
-
const { data, errors } = error;
|
|
73
|
-
// `data` is not `null`, and is not an empty object:
|
|
74
|
-
if (data !== undefined &&
|
|
75
|
-
data !== null &&
|
|
76
|
-
Object.keys(data).length !== 0 &&
|
|
77
|
-
errors) {
|
|
78
|
-
const [key] = Object.keys(data);
|
|
79
|
-
if (data[key]?.items) {
|
|
80
|
-
const flattenedResult = data[key].items.map((value) => (0, APIClient_1.flattenItems)(modelIntrospection, name, value));
|
|
81
|
-
/**
|
|
82
|
-
* Check exists since `flattenedResult` could be `null`.
|
|
83
|
-
* if `flattenedResult` exists, result is an actual record.
|
|
84
|
-
*/
|
|
85
|
-
if (flattenedResult) {
|
|
19
|
+
function _list(client, modelIntrospection, model, getInternals, args, contextSpec) {
|
|
20
|
+
return (0, utils_2.selfAwareAsync)(async (resultPromise) => {
|
|
21
|
+
const { name } = model;
|
|
22
|
+
const query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection, name, 'LIST', args);
|
|
23
|
+
const variables = (0, APIClient_1.buildGraphQLVariables)(model, 'LIST', args, modelIntrospection);
|
|
24
|
+
const auth = (0, APIClient_1.authModeParams)(client, getInternals, args);
|
|
25
|
+
try {
|
|
26
|
+
const headers = (0, APIClient_1.getCustomHeaders)(client, getInternals, args?.headers);
|
|
27
|
+
const basePromise = contextSpec
|
|
28
|
+
? client.graphql(contextSpec, {
|
|
29
|
+
...auth,
|
|
30
|
+
query,
|
|
31
|
+
variables,
|
|
32
|
+
}, headers)
|
|
33
|
+
: client.graphql({
|
|
34
|
+
...auth,
|
|
35
|
+
query,
|
|
36
|
+
variables,
|
|
37
|
+
}, headers);
|
|
38
|
+
const extendedPromise = (0, cancellation_1.extendCancellability)(basePromise, resultPromise);
|
|
39
|
+
const { data, extensions } = await extendedPromise;
|
|
40
|
+
// flatten response
|
|
41
|
+
if (data !== undefined) {
|
|
42
|
+
const [key] = Object.keys(data);
|
|
43
|
+
if (data[key].items) {
|
|
44
|
+
const flattenedResult = data[key].items.map((value) => (0, APIClient_1.flattenItems)(modelIntrospection, name, value));
|
|
86
45
|
// don't init if custom selection set
|
|
87
46
|
if (args?.selectionSet) {
|
|
88
47
|
return {
|
|
89
48
|
data: flattenedResult,
|
|
90
|
-
nextToken: data[key]
|
|
91
|
-
|
|
49
|
+
nextToken: data[key].nextToken,
|
|
50
|
+
extensions,
|
|
92
51
|
};
|
|
93
52
|
}
|
|
94
53
|
else {
|
|
95
54
|
const initialized = (0, APIClient_1.initializeModel)(client, name, flattenedResult, modelIntrospection, auth.authMode, auth.authToken, !!contextSpec);
|
|
96
|
-
// data is full record w/out selection set:
|
|
97
55
|
return {
|
|
98
56
|
data: initialized,
|
|
99
|
-
nextToken: data[key]
|
|
100
|
-
|
|
57
|
+
nextToken: data[key].nextToken,
|
|
58
|
+
extensions,
|
|
101
59
|
};
|
|
102
60
|
}
|
|
103
61
|
}
|
|
104
62
|
return {
|
|
105
63
|
data: data[key],
|
|
106
|
-
nextToken: data[key]
|
|
107
|
-
|
|
64
|
+
nextToken: data[key].nextToken,
|
|
65
|
+
extensions,
|
|
108
66
|
};
|
|
109
67
|
}
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
/**
|
|
71
|
+
* The `data` type returned by `error` here could be:
|
|
72
|
+
* 1) `null`
|
|
73
|
+
* 2) an empty object
|
|
74
|
+
* 3) "populated" but with a `null` value `data: { listPosts: null }`
|
|
75
|
+
* 4) actual records `data: { listPosts: items: [{ id: '1', ...etc }] }`
|
|
76
|
+
*/
|
|
77
|
+
const { data, errors } = error;
|
|
78
|
+
// `data` is not `null`, and is not an empty object:
|
|
79
|
+
if (data !== undefined &&
|
|
80
|
+
data !== null &&
|
|
81
|
+
Object.keys(data).length !== 0 &&
|
|
82
|
+
errors) {
|
|
83
|
+
const [key] = Object.keys(data);
|
|
84
|
+
if (data[key]?.items) {
|
|
85
|
+
const flattenedResult = data[key].items.map((value) => (0, APIClient_1.flattenItems)(modelIntrospection, name, value));
|
|
86
|
+
/**
|
|
87
|
+
* Check exists since `flattenedResult` could be `null`.
|
|
88
|
+
* if `flattenedResult` exists, result is an actual record.
|
|
89
|
+
*/
|
|
90
|
+
if (flattenedResult) {
|
|
91
|
+
// don't init if custom selection set
|
|
92
|
+
if (args?.selectionSet) {
|
|
93
|
+
return {
|
|
94
|
+
data: flattenedResult,
|
|
95
|
+
nextToken: data[key]?.nextToken,
|
|
96
|
+
errors,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
const initialized = (0, APIClient_1.initializeModel)(client, name, flattenedResult, modelIntrospection, auth.authMode, auth.authToken, !!contextSpec);
|
|
101
|
+
// data is full record w/out selection set:
|
|
102
|
+
return {
|
|
103
|
+
data: initialized,
|
|
104
|
+
nextToken: data[key]?.nextToken,
|
|
105
|
+
errors,
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return {
|
|
110
|
+
data: data[key],
|
|
111
|
+
nextToken: data[key]?.nextToken,
|
|
112
|
+
errors,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
// response is of type `data: { getPost: null }`)
|
|
117
|
+
return (0, utils_1.handleListGraphQlError)(error);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
110
120
|
else {
|
|
111
|
-
//
|
|
121
|
+
// `data` is `null` or an empty object:
|
|
112
122
|
return (0, utils_1.handleListGraphQlError)(error);
|
|
113
123
|
}
|
|
114
124
|
}
|
|
115
|
-
|
|
116
|
-
// `data` is `null` or an empty object:
|
|
117
|
-
return (0, utils_1.handleListGraphQlError)(error);
|
|
118
|
-
}
|
|
119
|
-
}
|
|
125
|
+
});
|
|
120
126
|
}
|
|
121
127
|
//# sourceMappingURL=list.js.map
|