@aws-amplify/data-schema 0.16.2 → 0.17.1

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 (39) hide show
  1. package/dist/cjs/SchemaProcessor.js +6 -6
  2. package/dist/cjs/SchemaProcessor.js.map +1 -1
  3. package/dist/cjs/runtime/internals/operations/custom.js +33 -5
  4. package/dist/cjs/runtime/internals/operations/custom.js.map +1 -1
  5. package/dist/cjs/runtime/internals/operations/get.js +36 -6
  6. package/dist/cjs/runtime/internals/operations/get.js.map +1 -1
  7. package/dist/cjs/runtime/internals/operations/indexQuery.js +39 -11
  8. package/dist/cjs/runtime/internals/operations/indexQuery.js.map +1 -1
  9. package/dist/cjs/runtime/internals/operations/list.js +50 -6
  10. package/dist/cjs/runtime/internals/operations/list.js.map +1 -1
  11. package/dist/cjs/runtime/internals/operations/utils.js +42 -0
  12. package/dist/cjs/runtime/internals/operations/utils.js.map +1 -0
  13. package/dist/esm/Authorization.d.ts +2 -2
  14. package/dist/esm/MappedTypes/MapSecondaryIndexes.d.ts +2 -2
  15. package/dist/esm/ModelRelationalField.d.ts +1 -1
  16. package/dist/esm/SchemaProcessor.mjs +6 -6
  17. package/dist/esm/SchemaProcessor.mjs.map +1 -1
  18. package/dist/esm/runtime/client/index.d.ts +20 -21
  19. package/dist/esm/runtime/internals/operations/custom.mjs +33 -5
  20. package/dist/esm/runtime/internals/operations/custom.mjs.map +1 -1
  21. package/dist/esm/runtime/internals/operations/get.mjs +36 -6
  22. package/dist/esm/runtime/internals/operations/get.mjs.map +1 -1
  23. package/dist/esm/runtime/internals/operations/indexQuery.mjs +39 -11
  24. package/dist/esm/runtime/internals/operations/indexQuery.mjs.map +1 -1
  25. package/dist/esm/runtime/internals/operations/list.mjs +50 -6
  26. package/dist/esm/runtime/internals/operations/list.mjs.map +1 -1
  27. package/dist/esm/runtime/internals/operations/utils.d.ts +8 -0
  28. package/dist/esm/runtime/internals/operations/utils.mjs +38 -0
  29. package/dist/esm/runtime/internals/operations/utils.mjs.map +1 -0
  30. package/dist/meta/cjs.tsbuildinfo +1 -1
  31. package/package.json +1 -1
  32. package/src/MappedTypes/MapSecondaryIndexes.ts +22 -26
  33. package/src/SchemaProcessor.ts +6 -1
  34. package/src/runtime/client/index.ts +34 -11
  35. package/src/runtime/internals/operations/custom.ts +44 -5
  36. package/src/runtime/internals/operations/get.ts +47 -7
  37. package/src/runtime/internals/operations/indexQuery.ts +43 -11
  38. package/src/runtime/internals/operations/list.ts +63 -7
  39. package/src/runtime/internals/operations/utils.ts +35 -0
@@ -1,4 +1,5 @@
1
1
  import { generateGraphQLDocument, buildGraphQLVariables, authModeParams, getCustomHeaders, flattenItems, initializeModel } from '../APIClient.mjs';
2
+ import { handleSingularGraphQlError } from './utils.mjs';
2
3
 
3
4
  function getFactory(client, modelIntrospection, model, operation, getInternals, useContext = false) {
4
5
  const getWithContext = async (contextSpec, arg, options) => {
@@ -13,8 +14,8 @@ async function _get(client, modelIntrospection, model, arg, options, operation,
13
14
  const { name } = model;
14
15
  const query = generateGraphQLDocument(modelIntrospection, name, operation, options);
15
16
  const variables = buildGraphQLVariables(model, operation, arg, modelIntrospection);
17
+ const auth = authModeParams(client, getInternals, options);
16
18
  try {
17
- const auth = authModeParams(client, getInternals, options);
18
19
  const headers = getCustomHeaders(client, getInternals, options?.headers);
19
20
  const { data, extensions } = context
20
21
  ? (await client.graphql(context, {
@@ -45,13 +46,42 @@ async function _get(client, modelIntrospection, model, arg, options, operation,
45
46
  }
46
47
  }
47
48
  catch (error) {
48
- if (error.errors) {
49
- // graphql errors pass through
50
- return error;
49
+ /**
50
+ * The `data` type returned by `error` here could be:
51
+ * 1) `null`
52
+ * 2) an empty object
53
+ * 3) "populated" but with a `null` value `{ getPost: null }`
54
+ * 4) an actual record `{ getPost: { id: '1', title: 'Hello, World!' } }`
55
+ */
56
+ const { data, errors } = error;
57
+ /**
58
+ * `data` is not `null`, and is not an empty object:
59
+ */
60
+ if (data && Object.keys(data).length !== 0 && errors) {
61
+ const [key] = Object.keys(data);
62
+ const flattenedResult = flattenItems(data)[key];
63
+ /**
64
+ * `flattenedResult` could be `null` here (e.g. `data: { getPost: null }`)
65
+ * if `flattenedResult`, result is an actual record:
66
+ */
67
+ if (flattenedResult) {
68
+ if (options?.selectionSet) {
69
+ return { data: flattenedResult, errors };
70
+ }
71
+ else {
72
+ // TODO: refactor to avoid destructuring here
73
+ const [initialized] = initializeModel(client, name, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context);
74
+ return { data: initialized, errors };
75
+ }
76
+ }
77
+ else {
78
+ // was `data: { getPost: null }`)
79
+ return handleSingularGraphQlError(error);
80
+ }
51
81
  }
52
82
  else {
53
- // non-graphql errors re re-thrown
54
- throw error;
83
+ // `data` is `null`:
84
+ return handleSingularGraphQlError(error);
55
85
  }
56
86
  }
57
87
  }
@@ -1 +1 @@
1
- {"version":3,"file":"get.mjs","sources":["../../../../../src/runtime/internals/operations/get.ts"],"sourcesContent":["import { authModeParams, buildGraphQLVariables, flattenItems, generateGraphQLDocument, getCustomHeaders, initializeModel, } from '../APIClient';\nexport function getFactory(client, modelIntrospection, model, operation, getInternals, useContext = false) {\n const getWithContext = async (contextSpec, arg, options) => {\n return _get(client, modelIntrospection, model, arg, options, operation, getInternals, contextSpec);\n };\n const get = async (arg, options) => {\n return _get(client, modelIntrospection, model, arg, options, operation, getInternals);\n };\n return useContext ? getWithContext : get;\n}\nasync function _get(client, modelIntrospection, model, arg, options, operation, getInternals, context) {\n const { name } = model;\n const query = generateGraphQLDocument(modelIntrospection, name, operation, options);\n const variables = buildGraphQLVariables(model, operation, arg, modelIntrospection);\n try {\n const auth = authModeParams(client, getInternals, options);\n const headers = getCustomHeaders(client, getInternals, options?.headers);\n const { data, extensions } = context\n ? (await client.graphql(context, {\n ...auth,\n query,\n variables,\n }, headers))\n : (await client.graphql({\n ...auth,\n query,\n variables,\n }, headers));\n // flatten response\n if (data) {\n const [key] = Object.keys(data);\n const flattenedResult = flattenItems(data)[key];\n if (options?.selectionSet) {\n return { data: flattenedResult, extensions };\n }\n else {\n // TODO: refactor to avoid destructuring here\n const [initialized] = 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 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":";;AACO,SAAS,UAAU,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,GAAG,KAAK,EAAE;AAC3G,IAAI,MAAM,cAAc,GAAG,OAAO,WAAW,EAAE,GAAG,EAAE,OAAO,KAAK;AAChE,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,OAAO,GAAG,EAAE,OAAO,KAAK;AACxC,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,eAAe,IAAI,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE;AACvG,IAAI,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;AAC3B,IAAI,MAAM,KAAK,GAAG,uBAAuB,CAAC,kBAAkB,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AACxF,IAAI,MAAM,SAAS,GAAG,qBAAqB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EAAE,CAAC;AACzD,aAAa;AACb,SAAS;AACT,aAAa;AACb,YAAY,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;AAC9C,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,IAAI,KAAK,CAAC,MAAM,EAAE;AAC1B;AACA,YAAY,OAAO,KAAK,CAAC;AACzB,SAAS;AACT,aAAa;AACb;AACA,YAAY,MAAM,KAAK,CAAC;AACxB,SAAS;AACT,KAAK;AACL;;;;"}
1
+ {"version":3,"file":"get.mjs","sources":["../../../../../src/runtime/internals/operations/get.ts"],"sourcesContent":["import { authModeParams, buildGraphQLVariables, flattenItems, generateGraphQLDocument, getCustomHeaders, initializeModel, } from '../APIClient';\nimport { handleSingularGraphQlError } from './utils';\nexport function getFactory(client, modelIntrospection, model, operation, getInternals, useContext = false) {\n const getWithContext = async (contextSpec, arg, options) => {\n return _get(client, modelIntrospection, model, arg, options, operation, getInternals, contextSpec);\n };\n const get = async (arg, options) => {\n return _get(client, modelIntrospection, model, arg, options, operation, getInternals);\n };\n return useContext ? getWithContext : get;\n}\nasync function _get(client, modelIntrospection, model, arg, options, operation, getInternals, context) {\n const { name } = model;\n const query = generateGraphQLDocument(modelIntrospection, name, operation, options);\n const variables = buildGraphQLVariables(model, operation, arg, modelIntrospection);\n const auth = authModeParams(client, getInternals, options);\n try {\n const headers = getCustomHeaders(client, getInternals, options?.headers);\n const { data, extensions } = context\n ? (await client.graphql(context, {\n ...auth,\n query,\n variables,\n }, headers))\n : (await client.graphql({\n ...auth,\n query,\n variables,\n }, headers));\n // flatten response\n if (data) {\n const [key] = Object.keys(data);\n const flattenedResult = flattenItems(data)[key];\n if (options?.selectionSet) {\n return { data: flattenedResult, extensions };\n }\n else {\n // TODO: refactor to avoid destructuring here\n const [initialized] = 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 = flattenItems(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] = 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 handleSingularGraphQlError(error);\n }\n }\n else {\n // `data` is `null`:\n return handleSingularGraphQlError(error);\n }\n }\n}\n"],"names":[],"mappings":";;;AAEO,SAAS,UAAU,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,GAAG,KAAK,EAAE;AAC3G,IAAI,MAAM,cAAc,GAAG,OAAO,WAAW,EAAE,GAAG,EAAE,OAAO,KAAK;AAChE,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,OAAO,GAAG,EAAE,OAAO,KAAK;AACxC,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;AA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AC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;AACzJ,oBAAoB,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AACzD,iBAAiB;AACjB,aAAa;AACb,iBAAiB;AACjB;AACA,gBAAgB,OAAO,0BAA0B,CAAC,KAAK,CAAC,CAAC;AACzD,aAAa;AACb,SAAS;AACT,aAAa;AACb;AACA,YAAY,OAAO,0BAA0B,CAAC,KAAK,CAAC,CAAC;AACrD,SAAS;AACT,KAAK;AACL;;;;"}
@@ -1,4 +1,5 @@
1
1
  import { generateGraphQLDocument, buildGraphQLVariables, authModeParams, getCustomHeaders, flattenItems, initializeModel } from '../APIClient.mjs';
2
+ import { handleListGraphQlError } from './utils.mjs';
2
3
 
3
4
  function indexQueryFactory(client, modelIntrospection, model, indexMeta, getInternals, context = false) {
4
5
  const indexQueryWithContext = async (contextSpec, args, options) => {
@@ -32,16 +33,6 @@ function processGraphQlResponse(result, selectionSet, modelInitializer) {
32
33
  extensions,
33
34
  };
34
35
  }
35
- function handleGraphQlError(error) {
36
- if (error.errors) {
37
- // graphql errors pass through
38
- return error;
39
- }
40
- else {
41
- // non-graphql errors re re-thrown
42
- throw error;
43
- }
44
- }
45
36
  async function _indexQuery(client, modelIntrospection, model, indexMeta, getInternals, args, contextSpec) {
46
37
  const { name } = model;
47
38
  const query = generateGraphQLDocument(modelIntrospection, name, 'INDEX_QUERY', args, indexMeta);
@@ -65,7 +56,44 @@ async function _indexQuery(client, modelIntrospection, model, indexMeta, getInte
65
56
  }
66
57
  }
67
58
  catch (error) {
68
- return handleGraphQlError(error);
59
+ /**
60
+ * The `data` type returned by `error` here could be:
61
+ * 1) `null`
62
+ * 2) an empty object
63
+ * 3) "populated" but with a `null` value:
64
+ * `data: { listByExampleId: null }`
65
+ * 4) an actual record:
66
+ * `data: { listByExampleId: items: [{ id: '1', ...etc } }]`
67
+ */
68
+ const { data, errors } = error;
69
+ // `data` is not `null`, and is not an empty object:
70
+ if (data !== undefined && Object.keys(data).length !== 0 && errors) {
71
+ const [key] = Object.keys(data);
72
+ if (data[key]?.items) {
73
+ const flattenedResult = flattenItems(data)[key];
74
+ /**
75
+ * Check exists since `flattenedResult` could be `null`.
76
+ * if `flattenedResult` exists, result is an actual record.
77
+ */
78
+ if (flattenedResult) {
79
+ return {
80
+ data: args?.selectionSet
81
+ ? flattenedResult
82
+ : modelInitializer(flattenedResult),
83
+ nextToken: data[key]?.nextToken,
84
+ };
85
+ }
86
+ }
87
+ // response is of type `data: { listByExampleId: null }`
88
+ return {
89
+ data: data[key],
90
+ nextToken: data[key]?.nextToken,
91
+ };
92
+ }
93
+ else {
94
+ // `data` is `null` or an empty object:
95
+ return handleListGraphQlError(error);
96
+ }
69
97
  }
70
98
  }
71
99
 
@@ -1 +1 @@
1
- {"version":3,"file":"indexQuery.mjs","sources":["../../../../../src/runtime/internals/operations/indexQuery.ts"],"sourcesContent":["import { authModeParams, buildGraphQLVariables, flattenItems, generateGraphQLDocument, getCustomHeaders, initializeModel, } from '../APIClient';\nexport function indexQueryFactory(client, modelIntrospection, model, indexMeta, getInternals, context = false) {\n const indexQueryWithContext = async (contextSpec, args, options) => {\n return _indexQuery(client, modelIntrospection, model, indexMeta, getInternals, {\n ...args,\n ...options,\n }, contextSpec);\n };\n const indexQuery = async (args, options) => {\n return _indexQuery(client, modelIntrospection, model, indexMeta, getInternals, {\n ...args,\n ...options,\n });\n };\n return context ? indexQueryWithContext : indexQuery;\n}\nfunction processGraphQlResponse(result, selectionSet, modelInitializer) {\n const { data, extensions } = result;\n const [key] = Object.keys(data);\n if (data[key].items) {\n const flattenedResult = flattenItems(data)[key];\n return {\n data: selectionSet ? flattenedResult : modelInitializer(flattenedResult),\n nextToken: data[key].nextToken,\n extensions,\n };\n }\n return {\n data: data[key],\n nextToken: data[key].nextToken,\n extensions,\n };\n}\nfunction handleGraphQlError(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}\nasync function _indexQuery(client, modelIntrospection, model, indexMeta, getInternals, args, contextSpec) {\n const { name } = model;\n const query = generateGraphQLDocument(modelIntrospection, name, 'INDEX_QUERY', args, indexMeta);\n const variables = buildGraphQLVariables(model, 'INDEX_QUERY', args, modelIntrospection, indexMeta);\n const auth = authModeParams(client, getInternals, args);\n const modelInitializer = (flattenedResult) => initializeModel(client, name, flattenedResult, modelIntrospection, auth.authMode, auth.authToken, !!contextSpec);\n try {\n const headers = 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 response = (await client.graphql(...requestArgs));\n if (response.data !== undefined) {\n return processGraphQlResponse(response, args?.selectionSet, modelInitializer);\n }\n }\n catch (error) {\n return handleGraphQlError(error);\n }\n}\n"],"names":[],"mappings":";;AACO,SAAS,iBAAiB,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,GAAG,KAAK,EAAE;AAC/G,IAAI,MAAM,qBAAqB,GAAG,OAAO,WAAW,EAAE,IAAI,EAAE,OAAO,KAAK;AACxE,QAAQ,OAAO,WAAW,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE;AACvF,YAAY,GAAG,IAAI;AACnB,YAAY,GAAG,OAAO;AACtB,SAAS,EAAE,WAAW,CAAC,CAAC;AACxB,KAAK,CAAC;AACN,IAAI,MAAM,UAAU,GAAG,OAAO,IAAI,EAAE,OAAO,KAAK;AAChD,QAAQ,OAAO,WAAW,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE;AACvF,YAAY,GAAG,IAAI;AACnB,YAAY,GAAG,OAAO;AACtB,SAAS,CAAC,CAAC;AACX,KAAK,CAAC;AACN,IAAI,OAAO,OAAO,GAAG,qB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.ts"],"sourcesContent":["import { authModeParams, buildGraphQLVariables, flattenItems, generateGraphQLDocument, getCustomHeaders, initializeModel, } from '../APIClient';\nimport { handleListGraphQlError } from './utils';\nexport function indexQueryFactory(client, modelIntrospection, model, indexMeta, getInternals, context = false) {\n const indexQueryWithContext = async (contextSpec, args, options) => {\n return _indexQuery(client, modelIntrospection, model, indexMeta, getInternals, {\n ...args,\n ...options,\n }, contextSpec);\n };\n const indexQuery = async (args, options) => {\n return _indexQuery(client, modelIntrospection, model, indexMeta, getInternals, {\n ...args,\n ...options,\n });\n };\n return context ? indexQueryWithContext : indexQuery;\n}\nfunction processGraphQlResponse(result, selectionSet, modelInitializer) {\n const { data, extensions } = result;\n const [key] = Object.keys(data);\n if (data[key].items) {\n const flattenedResult = flattenItems(data)[key];\n return {\n data: selectionSet ? flattenedResult : modelInitializer(flattenedResult),\n nextToken: data[key].nextToken,\n extensions,\n };\n }\n return {\n data: data[key],\n nextToken: data[key].nextToken,\n extensions,\n };\n}\nasync function _indexQuery(client, modelIntrospection, model, indexMeta, getInternals, args, contextSpec) {\n const { name } = model;\n const query = generateGraphQLDocument(modelIntrospection, name, 'INDEX_QUERY', args, indexMeta);\n const variables = buildGraphQLVariables(model, 'INDEX_QUERY', args, modelIntrospection, indexMeta);\n const auth = authModeParams(client, getInternals, args);\n const modelInitializer = (flattenedResult) => initializeModel(client, name, flattenedResult, modelIntrospection, auth.authMode, auth.authToken, !!contextSpec);\n try {\n const headers = 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 response = (await client.graphql(...requestArgs));\n if (response.data !== undefined) {\n return processGraphQlResponse(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 = flattenItems(data)[key];\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 handleListGraphQlError(error);\n }\n }\n}\n"],"names":[],"mappings":";;;AAEO,SAAS,iBAAiB,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,GAAG,KAAK,EAAE;AAC/G,IAAI,MAAM,qBAAqB,GAAG,OAAO,WAAW,EAAE,IAAI,EAAE,OAAO,KAAK;AACxE,QAAQ,OAAO,WAAW,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE;AACvF,YAAY,GAAG,IAAI;AACnB,YAAY,GAAG,OAAO;AACtB,SAAS,EAAE,WAAW,CAAC,CAAC;AACxB,KAAK,CAAC;AACN,IAAI,MAAM,UAAU,GAAG,OAAO,IAAI,EAAE,OAAO,KAAK;AAChD,QAAQ,OAAO,WAAW,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE;AACvF,YAAY,GAAG,IAAI;AACnB,YAAY,GAAG,OAAO;AACtB,SAAS,CAAC,CAAC;AACX,KAAK,CAAC;AACN,IAAI,OAAO,OAAO,GAAG,qBAAqB,GAAG,UAAU,CAAC;AACxD,CAAC;AACD,SAAS,sBAAsB,CAAC,MAAM,EAAE,YAAY,EAAE,gB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Y,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;AAChE;AACA;AACA;AACA;AACA,gBAAgB,IAAI,eAAe,EAAE;AACrC,oBAAoB,OAAO;AAC3B,wBAAwB,IAAI,EAAE,IAAI,EAAE,YAAY;AAChD,8BAA8B,eAAe;AAC7C,8BAA8B,gBAAgB,CAAC,eAAe,CAAC;AAC/D,wBAAwB,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,SAAS;AACvD,qBAAqB,CAAC;AACtB,iBAAiB;AACjB,aAAa;AACb;AACA,YAAY,OAAO;AACnB,gBAAgB,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;AAC/B,gBAAgB,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,SAAS;AAC/C,aAAa,CAAC;AACd,SAAS;AACT,aAAa;AACb;AACA,YAAY,OAAO,sBAAsB,CAAC,KAAK,CAAC,CAAC;AACjD,SAAS;AACT,KAAK;AACL;;;;"}
@@ -1,4 +1,5 @@
1
1
  import { generateGraphQLDocument, buildGraphQLVariables, authModeParams, getCustomHeaders, flattenItems, initializeModel } from '../APIClient.mjs';
2
+ import { handleListGraphQlError } from './utils.mjs';
2
3
 
3
4
  function listFactory(client, modelIntrospection, model, getInternals, context = false) {
4
5
  const listWithContext = async (contextSpec, args) => {
@@ -13,8 +14,8 @@ async function _list(client, modelIntrospection, model, getInternals, args, cont
13
14
  const { name } = model;
14
15
  const query = generateGraphQLDocument(modelIntrospection, name, 'LIST', args);
15
16
  const variables = buildGraphQLVariables(model, 'LIST', args, modelIntrospection);
17
+ const auth = authModeParams(client, getInternals, args);
16
18
  try {
17
- const auth = authModeParams(client, getInternals, args);
18
19
  const headers = getCustomHeaders(client, getInternals, args?.headers);
19
20
  const { data, extensions } = contextSpec
20
21
  ? (await client.graphql(contextSpec, {
@@ -57,13 +58,56 @@ async function _list(client, modelIntrospection, model, getInternals, args, cont
57
58
  }
58
59
  }
59
60
  catch (error) {
60
- if (error.errors) {
61
- // graphql errors pass through
62
- return 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 `data: { listPosts: null }`
66
+ * 4) actual records `data: { listPosts: items: [{ id: '1', ...etc }] }`
67
+ */
68
+ const { data, errors } = error;
69
+ // `data` is not `null`, and is not an empty object:
70
+ if (data !== undefined && Object.keys(data).length !== 0 && errors) {
71
+ const [key] = Object.keys(data);
72
+ if (data[key]?.items) {
73
+ const flattenedResult = flattenItems(data)[key];
74
+ /**
75
+ * Check exists since `flattenedResult` could be `null`.
76
+ * if `flattenedResult` exists, result is an actual record.
77
+ */
78
+ if (flattenedResult) {
79
+ // don't init if custom selection set
80
+ if (args?.selectionSet) {
81
+ return {
82
+ data: flattenedResult,
83
+ nextToken: data[key]?.nextToken,
84
+ errors,
85
+ };
86
+ }
87
+ else {
88
+ const initialized = initializeModel(client, name, flattenedResult, modelIntrospection, auth.authMode, auth.authToken, !!contextSpec);
89
+ // data is full record w/out selection set:
90
+ return {
91
+ data: initialized,
92
+ nextToken: data[key]?.nextToken,
93
+ errors,
94
+ };
95
+ }
96
+ }
97
+ return {
98
+ data: data[key],
99
+ nextToken: data[key]?.nextToken,
100
+ errors,
101
+ };
102
+ }
103
+ else {
104
+ // response is of type `data: { getPost: null }`)
105
+ return handleListGraphQlError(error);
106
+ }
63
107
  }
64
108
  else {
65
- // non-graphql errors re re-thrown
66
- throw error;
109
+ // `data` is `null` or an empty object:
110
+ return handleListGraphQlError(error);
67
111
  }
68
112
  }
69
113
  }
@@ -1 +1 @@
1
- {"version":3,"file":"list.mjs","sources":["../../../../../src/runtime/internals/operations/list.ts"],"sourcesContent":["import { authModeParams, buildGraphQLVariables, flattenItems, generateGraphQLDocument, getCustomHeaders, initializeModel, } from '../APIClient';\nexport function listFactory(client, modelIntrospection, model, getInternals, context = false) {\n const listWithContext = async (contextSpec, args) => {\n return _list(client, modelIntrospection, model, getInternals, args, contextSpec);\n };\n const list = async (args) => {\n return _list(client, modelIntrospection, model, getInternals, args);\n };\n return context ? listWithContext : list;\n}\nasync function _list(client, modelIntrospection, model, getInternals, args, contextSpec) {\n const { name } = model;\n const query = generateGraphQLDocument(modelIntrospection, name, 'LIST', args);\n const variables = buildGraphQLVariables(model, 'LIST', args, modelIntrospection);\n try {\n const auth = authModeParams(client, getInternals, args);\n const headers = getCustomHeaders(client, getInternals, args?.headers);\n const { data, extensions } = contextSpec\n ? (await client.graphql(contextSpec, {\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 !== undefined) {\n const [key] = Object.keys(data);\n if (data[key].items) {\n const flattenedResult = flattenItems(data)[key];\n // don't init if custom selection set\n if (args?.selectionSet) {\n return {\n data: flattenedResult,\n nextToken: data[key].nextToken,\n extensions,\n };\n }\n else {\n const initialized = initializeModel(client, name, flattenedResult, modelIntrospection, auth.authMode, auth.authToken, !!contextSpec);\n return {\n data: initialized,\n nextToken: data[key].nextToken,\n extensions,\n };\n }\n }\n return {\n data: data[key],\n nextToken: data[key].nextToken,\n extensions,\n };\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":";;AACO,SAAS,WAAW,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,GAAG,KAAK,EAAE;AAC9F,IAAI,MAAM,eAAe,GAAG,OAAO,WAAW,EAAE,IAAI,KAAK;AACzD,QAAQ,OAAO,KAAK,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;AACzF,KAAK,CAAC;AACN,IAAI,MAAM,IAAI,GAAG,OAAO,IAAI,KAAK;AACjC,QAAQ,OAAO,KAAK,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,YAAY,EAAE,IAA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AAM,eAAe,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;AAChE;AACA,gBAAgB,IAAI,IAAI,EAAE,YAAY,EAAE;AACxC,oBAAoB,OAAO;AAC3B,wBAAwB,IAAI,EAAE,eAAe;AAC7C,wBAAwB,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS;AACtD,wBAAwB,UAAU;AAClC,qBAAqB,CAAC;AACtB,iBAAiB;AACjB,qBAAqB;AACrB,oBAAoB,MAAM,WAAW,GAAG,eAAe,CAAC,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,kBAAkB,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC;AACzJ,oBAAoB,OAAO;AAC3B,wBAAwB,IAAI,EAAE,WAAW;AACzC,wBAAwB,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS;AACtD,wBAAwB,UAAU;AAClC,qBAAqB,CAAC;AACtB,iBAAiB;AACjB,aAAa;AACb,YAAY,OAAO;AACnB,gBAAgB,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;AAC/B,gBAAgB,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS;AAC9C,gBAAgB,UAAU;AAC1B,aAAa,CAAC;AACd,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,IAAI,KAAK,CAAC,MAAM,EAAE;AAC1B;AACA,YAAY,OAAO,KAAK,CAAC;AACzB,SAAS;AACT,aAAa;AACb;AACA,YAAY,MAAM,KAAK,CAAC;AACxB,SAAS;AACT,KAAK;AACL;;;;"}
1
+ {"version":3,"file":"list.mjs","sources":["../../../../../src/runtime/internals/operations/list.ts"],"sourcesContent":["import { authModeParams, buildGraphQLVariables, flattenItems, generateGraphQLDocument, getCustomHeaders, initializeModel, } from '../APIClient';\nimport { handleListGraphQlError } from './utils';\nexport function listFactory(client, modelIntrospection, model, getInternals, context = false) {\n const listWithContext = async (contextSpec, args) => {\n return _list(client, modelIntrospection, model, getInternals, args, contextSpec);\n };\n const list = async (args) => {\n return _list(client, modelIntrospection, model, getInternals, args);\n };\n return context ? listWithContext : list;\n}\nasync function _list(client, modelIntrospection, model, getInternals, args, contextSpec) {\n const { name } = model;\n const query = generateGraphQLDocument(modelIntrospection, name, 'LIST', args);\n const variables = buildGraphQLVariables(model, 'LIST', args, modelIntrospection);\n const auth = authModeParams(client, getInternals, args);\n try {\n const headers = getCustomHeaders(client, getInternals, args?.headers);\n const { data, extensions } = contextSpec\n ? (await client.graphql(contextSpec, {\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 !== undefined) {\n const [key] = Object.keys(data);\n if (data[key].items) {\n const flattenedResult = flattenItems(data)[key];\n // don't init if custom selection set\n if (args?.selectionSet) {\n return {\n data: flattenedResult,\n nextToken: data[key].nextToken,\n extensions,\n };\n }\n else {\n const initialized = initializeModel(client, name, flattenedResult, modelIntrospection, auth.authMode, auth.authToken, !!contextSpec);\n return {\n data: initialized,\n nextToken: data[key].nextToken,\n extensions,\n };\n }\n }\n return {\n data: data[key],\n nextToken: data[key].nextToken,\n extensions,\n };\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 `data: { listPosts: null }`\n * 4) actual records `data: { listPosts: 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 = flattenItems(data)[key];\n /**\n * Check exists since `flattenedResult` could be `null`.\n * if `flattenedResult` exists, result is an actual record.\n */\n if (flattenedResult) {\n // don't init if custom selection set\n if (args?.selectionSet) {\n return {\n data: flattenedResult,\n nextToken: data[key]?.nextToken,\n errors,\n };\n }\n else {\n const initialized = initializeModel(client, name, flattenedResult, modelIntrospection, auth.authMode, auth.authToken, !!contextSpec);\n // data is full record w/out selection set:\n return {\n data: initialized,\n nextToken: data[key]?.nextToken,\n errors,\n };\n }\n }\n return {\n data: data[key],\n nextToken: data[key]?.nextToken,\n errors,\n };\n }\n else {\n // response is of type `data: { getPost: null }`)\n return handleListGraphQlError(error);\n }\n }\n else {\n // `data` is `null` or an empty object:\n return handleListGraphQlError(error);\n }\n }\n}\n"],"names":[],"mappings":";;;AAEO,SAAS,WAAW,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,GAAG,KAAK,EAAE;AAC9F,IAAI,MAAM,eAAe,GAAG,OAAO,WAAW,EAAE,IAAI,KAAK;AACzD,QAAQ,OAAO,KAAK,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;AACzF,KAAK,CAAC;AACN,IAAI,MAAM,IAAI,GAAG,OAAO,IAAI,KAAK;AACjC,QAAQ,OAAO,KAAK,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,CAAC,CAAC;AAC5E,KAAK,CAAC;AACN,IAAI,OAAO,OAAO,GAAG,eAAe,GAAG,IAAI,CAAC;AAC5C,CAAC;AACD,eAAe,KAAK,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,WAAW,EAAE;AACzF,IAAI,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;AAC3B,IAAI,MAAM,KAAK,GAAG,uBAAuB,CAAC,kBAAkB,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AAClF,IAAI,MAAM,SAAS,GAAG,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,CAAC,CAAC;AACrF,IAAI,MAAM,IAAI,GAAG,c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,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC;AAC7J;AACA,wBAAwB,OAAO;AAC/B,4BAA4B,IAAI,EAAE,WAAW;AAC7C,4BAA4B,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,SAAS;AAC3D,4BAA4B,MAAM;AAClC,yBAAyB,CAAC;AAC1B,qBAAqB;AACrB,iBAAiB;AACjB,gBAAgB,OAAO;AACvB,oBAAoB,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;AACnC,oBAAoB,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,EAAE,SAAS;AACnD,oBAAoB,MAAM;AAC1B,iBAAiB,CAAC;AAClB,aAAa;AACb,iBAAiB;AACjB;AACA,gBAAgB,OAAO,sBAAsB,CAAC,KAAK,CAAC,CAAC;AACrD,aAAa;AACb,SAAS;AACT,aAAa;AACb;AACA,YAAY,OAAO,sBAAsB,CAAC,KAAK,CAAC,CAAC;AACjD,SAAS;AACT,KAAK;AACL;;;;"}
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Handle errors for list return types (list and index query operations)
3
+ */
4
+ export declare function handleListGraphQlError(error: any): any;
5
+ /**
6
+ * Handle errors for singular return types (create, get, update, delete operations)
7
+ */
8
+ export declare function handleSingularGraphQlError(error: any): any;
@@ -0,0 +1,38 @@
1
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
+ // SPDX-License-Identifier: Apache-2.0
3
+ // import { GraphQLFormattedError } from '@aws-amplify/data-schema-types';
4
+ /**
5
+ * Handle errors for list return types (list and index query operations)
6
+ */
7
+ function handleListGraphQlError(error) {
8
+ if (error?.errors) {
9
+ // graphql errors pass through
10
+ return {
11
+ ...error,
12
+ data: [],
13
+ };
14
+ }
15
+ else {
16
+ // non-graphql errors are re-thrown
17
+ throw error;
18
+ }
19
+ }
20
+ /**
21
+ * Handle errors for singular return types (create, get, update, delete operations)
22
+ */
23
+ function handleSingularGraphQlError(error) {
24
+ if (error.errors) {
25
+ // graphql errors pass through
26
+ return {
27
+ ...error,
28
+ data: null,
29
+ };
30
+ }
31
+ else {
32
+ // non-graphql errors are re-thrown
33
+ throw error;
34
+ }
35
+ }
36
+
37
+ export { handleListGraphQlError, handleSingularGraphQlError };
38
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","sources":["../../../../../src/runtime/internals/operations/utils.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\n// import { GraphQLFormattedError } from '@aws-amplify/data-schema-types';\n/**\n * Handle errors for list return types (list and index query operations)\n */\nexport function handleListGraphQlError(error) {\n if (error?.errors) {\n // graphql errors pass through\n return {\n ...error,\n data: [],\n };\n }\n else {\n // non-graphql errors are re-thrown\n throw error;\n }\n}\n/**\n * Handle errors for singular return types (create, get, update, delete operations)\n */\nexport function handleSingularGraphQlError(error) {\n if (error.errors) {\n // graphql errors pass through\n return {\n ...error,\n data: null,\n };\n }\n else {\n // non-graphql errors are re-thrown\n throw error;\n }\n}\n"],"names":[],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,sBAAsB,CAAC,KAAK,EAAE;AAC9C,IAAI,IAAI,KAAK,EAAE,MAAM,EAAE;AACvB;AACA,QAAQ,OAAO;AACf,YAAY,GAAG,KAAK;AACpB,YAAY,IAAI,EAAE,EAAE;AACpB,SAAS,CAAC;AACV,KAAK;AACL,SAAS;AACT;AACA,QAAQ,MAAM,KAAK,CAAC;AACpB,KAAK;AACL,CAAC;AACD;AACA;AACA;AACO,SAAS,0BAA0B,CAAC,KAAK,EAAE;AAClD,IAAI,IAAI,KAAK,CAAC,MAAM,EAAE;AACtB;AACA,QAAQ,OAAO;AACf,YAAY,GAAG,KAAK;AACpB,YAAY,IAAI,EAAE,IAAI;AACtB,SAAS,CAAC;AACV,KAAK;AACL,SAAS;AACT;AACA,QAAQ,MAAM,KAAK,CAAC;AACpB,KAAK;AACL;;;;"}