@aws-amplify/data-schema 0.16.2 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (30) hide show
  1. package/dist/cjs/runtime/internals/operations/custom.js +33 -5
  2. package/dist/cjs/runtime/internals/operations/custom.js.map +1 -1
  3. package/dist/cjs/runtime/internals/operations/get.js +36 -6
  4. package/dist/cjs/runtime/internals/operations/get.js.map +1 -1
  5. package/dist/cjs/runtime/internals/operations/indexQuery.js +39 -11
  6. package/dist/cjs/runtime/internals/operations/indexQuery.js.map +1 -1
  7. package/dist/cjs/runtime/internals/operations/list.js +50 -6
  8. package/dist/cjs/runtime/internals/operations/list.js.map +1 -1
  9. package/dist/cjs/runtime/internals/operations/utils.js +42 -0
  10. package/dist/cjs/runtime/internals/operations/utils.js.map +1 -0
  11. package/dist/esm/Authorization.d.ts +2 -2
  12. package/dist/esm/ModelRelationalField.d.ts +1 -1
  13. package/dist/esm/runtime/internals/operations/custom.mjs +33 -5
  14. package/dist/esm/runtime/internals/operations/custom.mjs.map +1 -1
  15. package/dist/esm/runtime/internals/operations/get.mjs +36 -6
  16. package/dist/esm/runtime/internals/operations/get.mjs.map +1 -1
  17. package/dist/esm/runtime/internals/operations/indexQuery.mjs +39 -11
  18. package/dist/esm/runtime/internals/operations/indexQuery.mjs.map +1 -1
  19. package/dist/esm/runtime/internals/operations/list.mjs +50 -6
  20. package/dist/esm/runtime/internals/operations/list.mjs.map +1 -1
  21. package/dist/esm/runtime/internals/operations/utils.d.ts +8 -0
  22. package/dist/esm/runtime/internals/operations/utils.mjs +38 -0
  23. package/dist/esm/runtime/internals/operations/utils.mjs.map +1 -0
  24. package/dist/meta/cjs.tsbuildinfo +1 -1
  25. package/package.json +1 -1
  26. package/src/runtime/internals/operations/custom.ts +44 -5
  27. package/src/runtime/internals/operations/get.ts +47 -7
  28. package/src/runtime/internals/operations/indexQuery.ts +43 -11
  29. package/src/runtime/internals/operations/list.ts +63 -7
  30. package/src/runtime/internals/operations/utils.ts +35 -0
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.customOpFactory = void 0;
5
5
  const rxjs_1 = require("rxjs");
6
6
  const APIClient_1 = require("../APIClient");
7
+ const utils_1 = require("./utils");
7
8
  /**
8
9
  * Type guard for checking whether a Custom Operation argument is a contextSpec object
9
10
  */
@@ -301,13 +302,40 @@ async function _op(client, modelIntrospection, operationType, operation, getInte
301
302
  }
302
303
  }
303
304
  catch (error) {
304
- if (error.errors) {
305
- // graphql errors pass through
306
- return error;
305
+ /**
306
+ * The `data` type returned by `error` here could be:
307
+ * 1) `null`
308
+ * 2) an empty object
309
+ * 3) "populated" but with a `null` value `{ getPost: null }`
310
+ * 4) an actual record `{ getPost: { id: '1', title: 'Hello, World!' } }`
311
+ */
312
+ const { data, errors } = error;
313
+ /**
314
+ * `data` is not `null`, and is not an empty object:
315
+ */
316
+ if (data && Object.keys(data).length !== 0 && errors) {
317
+ const [key] = Object.keys(data);
318
+ const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];
319
+ /**
320
+ * `flattenedResult` could be `null` here (e.g. `data: { getPost: null }`)
321
+ * if `flattenedResult`, result is an actual record:
322
+ */
323
+ if (flattenedResult) {
324
+ // TODO: custom selection set. current selection set is default selection set only
325
+ // custom selection set requires data-schema-type + runtime updates above.
326
+ const [initialized] = returnTypeModelName
327
+ ? (0, APIClient_1.initializeModel)(client, returnTypeModelName, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context)
328
+ : [flattenedResult];
329
+ return { data: initialized, errors };
330
+ }
331
+ else {
332
+ // was `data: { getPost: null }`)
333
+ return (0, utils_1.handleSingularGraphQlError)(error);
334
+ }
307
335
  }
308
336
  else {
309
- // non-graphql errors re re-thrown
310
- throw error;
337
+ // `data` is `null`:
338
+ return (0, utils_1.handleSingularGraphQlError)(error);
311
339
  }
312
340
  }
313
341
  }
@@ -1 +1 @@
1
- {"version":3,"file":"custom.js","sources":["../../../../../src/runtime/internals/operations/custom.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.customOpFactory = void 0;\nconst rxjs_1 = require(\"rxjs\");\nconst APIClient_1 = require(\"../APIClient\");\n/**\n * Type guard for checking whether a Custom Operation argument is a contextSpec object\n */\nconst argIsContextSpec = (arg) => {\n return typeof arg?.token?.value === 'symbol';\n};\n/**\n * Builds an operation function, embedded with all client and context data, that\n * can be attached to a client as a custom query or mutation.\n *\n * If we have this source schema:\n *\n * ```typescript\n * a.schema({\n * echo: a.query()\n * .arguments({input: a.string().required()})\n * .returns(a.string())\n * })\n * ```\n *\n * Our model intro schema will contain an entry like this:\n *\n * ```ts\n * {\n * queries: {\n * echo: {\n * name: \"echo\",\n * isArray: false,\n * type: 'String',\n * isRequired: false,\n * arguments: {\n * input: {\n * name: 'input',\n * isArray: false,\n * type: String,\n * isRequired: true\n * }\n * }\n * }\n * }\n * }\n * ```\n *\n * The `echo` object is used to build the `echo' method that goes here:\n *\n * ```typescript\n * const client = generateClent()\n * const { data } = await client.queries.echo({input: 'a string'});\n * // ^\n * // |\n * // +-- This one right here.\n * //\n * ```\n *\n *\n * @param client The client to run graphql queries through.\n * @param modelIntrospection The model introspection schema the op comes from.\n * @param operationType The broad category of graphql operation.\n * @param operation The operation definition from the introspection schema.\n * @param useContext Whether the function needs to accept an SSR context.\n * @returns The operation function to attach to query, mutations, etc.\n */\nfunction customOpFactory(client, modelIntrospection, operationType, operation, useContext, getInternals) {\n // .arguments() are defined for the custom operation in the schema builder\n // and are present in the model introspection schema\n const argsDefined = operation.arguments !== undefined;\n const op = (...args) => {\n // options is always the last argument\n const options = args[args.length - 1];\n let contextSpec;\n let arg;\n if (useContext) {\n if (argIsContextSpec(args[0])) {\n contextSpec = args[0];\n }\n else {\n throw new Error(`Invalid first argument passed to ${operation.name}. Expected contextSpec`);\n }\n }\n if (argsDefined) {\n if (useContext) {\n arg = args[1];\n }\n else {\n arg = args[0];\n }\n }\n if (operationType === 'subscription') {\n return _opSubscription(\n // subscriptions are only enabled on the clientside\n client, modelIntrospection, operation, getInternals, arg, options);\n }\n return _op(client, modelIntrospection, operationType, operation, getInternals, arg, options, contextSpec);\n };\n return op;\n}\nexports.customOpFactory = customOpFactory;\n/**\n * Runtime test and type guard to check whether `o[field]` is a `String`.\n *\n * ```typescript\n * if (hasStringField(o, 'prop')) {\n * const s = o.prop;\n * // ^? const s: string\n * }\n * ```\n *\n * @param o Object to inspect\n * @param field Field to look for\n * @returns Boolean: `true` if the `o[field]` is a `string`\n */\nfunction hasStringField(o, field) {\n return typeof o[field] === 'string';\n}\n/**\n * Generates \"outer\" arguments string for a custom operation. For example,\n * in this operation:\n *\n * ```graphql\n * query MyQuery(InputString: String!) {\n * echoString(InputString: $InputString)\n * }\n * ```\n *\n * This function returns the top/outer level arguments as a string:\n *\n * ```json\n * \"InputString: String!\"\n * ```\n *\n * @param operation Operation object from model introspection schema.\n * @returns \"outer\" arguments string\n */\nfunction outerArguments(operation) {\n if (operation.arguments === undefined) {\n return '';\n }\n const args = Object.entries(operation.arguments)\n .map(([k, v]) => {\n const baseType = v.type + (v.isRequired ? '!' : '');\n const finalType = v.isArray\n ? `[${baseType}]${v.isArrayNullable ? '' : '!'}`\n : baseType;\n return `$${k}: ${finalType}`;\n })\n .join(', ');\n return args.length > 0 ? `(${args})` : '';\n}\n/**\n * Generates \"inner\" arguments string for a custom operation. For example,\n * in this operation:\n *\n * ```graphql\n * query MyQuery(InputString: String!) {\n * echoString(InputString: $InputString)\n * }\n * ```\n *\n * This function returns the inner arguments as a string:\n *\n * ```json\n * \"InputString: $InputString\"\n * ```\n *\n * @param operation Operation object from model introspection schema.\n * @returns \"outer\" arguments string\n */\nfunction innerArguments(operation) {\n if (operation.arguments === undefined) {\n return '';\n }\n const args = Object.keys(operation.arguments)\n .map((k) => `${k}: $${k}`)\n .join(', ');\n return args.length > 0 ? `(${args})` : '';\n}\n/**\n * Generates the selection set string for a custom operation. This is slightly\n * different than the selection set generation for models. If the custom op returns\n * a primitive or enum types, it doen't require a selection set at all.\n *\n * E.g., the graphql might look like this:\n *\n * ```graphql\n * query MyQuery {\n * echoString(inputString: \"whatever\")\n * }\n * # ^\n * # |\n * # +-- no selection set\n * ```\n *\n * Non-primitive return type selection set generation will be similar to other\n * model operations.\n *\n * @param modelIntrospection The full code-generated introspection schema.\n * @param operation The operation object from the schema.\n * @returns The selection set as a string.\n */\nfunction operationSelectionSet(modelIntrospection, operation) {\n if (hasStringField(operation, 'type') ||\n hasStringField(operation.type, 'enum')) {\n return '';\n }\n else if (hasStringField(operation.type, 'nonModel')) {\n const nonModel = modelIntrospection.nonModels[operation.type.nonModel];\n return `{${(0, APIClient_1.selectionSetIRToString)((0, APIClient_1.getDefaultSelectionSetForNonModelWithIR)(nonModel, modelIntrospection))}}`;\n }\n else if (hasStringField(operation.type, 'model')) {\n return `{${(0, APIClient_1.generateSelectionSet)(modelIntrospection, operation.type.model)}}`;\n }\n else {\n return '';\n }\n}\n/**\n * Maps an arguments objec to graphql variables, removing superfluous args and\n * screaming loudly when required args are missing.\n *\n * @param operation The operation to construct graphql request variables for.\n * @param args The arguments to map variables from.\n * @returns The graphql variables object.\n */\nfunction operationVariables(operation, args = {}) {\n const variables = {};\n if (operation.arguments === undefined) {\n return variables;\n }\n for (const argDef of Object.values(operation.arguments)) {\n if (typeof args[argDef.name] !== 'undefined') {\n variables[argDef.name] = args[argDef.name];\n }\n else if (argDef.isRequired) {\n // At this point, the variable is both required and missing: We don't need\n // to continue. The operation is expected to fail.\n throw new Error(`${operation.name} requires arguments '${argDef.name}'`);\n }\n }\n return variables;\n}\n/**\n * Executes an operation from the given model intro schema against a client, returning\n * a fully instantiated model when relevant.\n *\n * @param client The client to operate `graphql()` calls through.\n * @param modelIntrospection The model intro schema to construct requests from.\n * @param operationType The high level graphql operation type.\n * @param operation The specific operation name, args, return type details.\n * @param args The arguments to provide to the operation as variables.\n * @param options Request options like headers, etc.\n * @param context SSR context if relevant.\n * @returns Result from the graphql request, model-instantiated when relevant.\n */\nasync function _op(client, modelIntrospection, operationType, operation, getInternals, args, options, context) {\n const { name: operationName } = operation;\n const auth = (0, APIClient_1.authModeParams)(client, getInternals, options);\n const headers = (0, APIClient_1.getCustomHeaders)(client, getInternals, options?.headers);\n const outerArgsString = outerArguments(operation);\n const innerArgsString = innerArguments(operation);\n const selectionSet = operationSelectionSet(modelIntrospection, operation);\n const returnTypeModelName = hasStringField(operation.type, 'model')\n ? operation.type.model\n : undefined;\n const query = `\n ${operationType.toLocaleLowerCase()}${outerArgsString} {\n ${operationName}${innerArgsString} ${selectionSet}\n }\n `;\n const variables = operationVariables(operation, args);\n try {\n const { data, extensions } = context\n ? (await client.graphql(context, {\n ...auth,\n query,\n variables,\n }, headers))\n : (await client.graphql({\n ...auth,\n query,\n variables,\n }, headers));\n // flatten response\n if (data) {\n const [key] = Object.keys(data);\n const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];\n // TODO: custom selection set. current selection set is default selection set only\n // custom selection set requires data-schema-type + runtime updates above.\n const [initialized] = returnTypeModelName\n ? (0, APIClient_1.initializeModel)(client, returnTypeModelName, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context)\n : [flattenedResult];\n return { data: initialized, extensions };\n }\n else {\n return { data: null, extensions };\n }\n }\n catch (error) {\n if (error.errors) {\n // graphql errors pass through\n return error;\n }\n else {\n // non-graphql errors re re-thrown\n throw error;\n }\n }\n}\n/**\n * Executes an operation from the given model intro schema against a client, returning\n * a fully instantiated model when relevant.\n *\n * @param client The client to operate `graphql()` calls through.\n * @param modelIntrospection The model intro schema to construct requests from.\n * @param operation The specific operation name, args, return type details.\n * @param args The arguments to provide to the operation as variables.\n * @param options Request options like headers, etc.\n * @returns Result from the graphql request, model-instantiated when relevant.\n */\nfunction _opSubscription(client, modelIntrospection, operation, getInternals, args, options) {\n const operationType = 'subscription';\n const { name: operationName } = operation;\n const auth = (0, APIClient_1.authModeParams)(client, getInternals, options);\n const headers = (0, APIClient_1.getCustomHeaders)(client, getInternals, options?.headers);\n const outerArgsString = outerArguments(operation);\n const innerArgsString = innerArguments(operation);\n const selectionSet = operationSelectionSet(modelIntrospection, operation);\n const returnTypeModelName = hasStringField(operation.type, 'model')\n ? operation.type.model\n : undefined;\n const query = `\n ${operationType.toLocaleLowerCase()}${outerArgsString} {\n ${operationName}${innerArgsString} ${selectionSet}\n }\n `;\n const variables = operationVariables(operation, args);\n const observable = client.graphql({\n ...auth,\n query,\n variables,\n }, headers);\n return observable.pipe((0, rxjs_1.map)((value) => {\n const [key] = Object.keys(value.data);\n const data = value.data[key];\n const [initialized] = returnTypeModelName\n ? (0, APIClient_1.initializeModel)(client, returnTypeModelName, [data], modelIntrospection, auth.authMode, auth.authToken)\n : [data];\n return initialized;\n }));\n}\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,eAAe,GAAG,KAAK,CAAC,CAAC;AACjC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC/B,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAC5C;AACA;AACA;AACA,MAAM,gBAAgB,GAAG,CAAC,GAAG,KAAK;AAClC,IAAI,OAAO,OAAO,GAAG,EAAE,KAAK,EAAE,KAAK,KAAK,QAAQ,CAAC;AACjD,CAAC,CAAC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,eAAe,CAAC,MAAM,EAAE,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,IAAI,CAAC,GAAG,CAAC,CAAC;AACrC,QAAQ,MAAM,CAAC,WAAW,CAAC,GAAG,mBAAmB;AACjD,cAAc,IAAI,WAAW,CAAC,eAAe,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC,IAAI,CAAC,EAAE,kBAAkB,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC;AACtI,cAAc,CAAC,IAAI,CAAC,CAAC;AACrB,QAAQ,OAAO,WAAW,CAAC;AAC3B,KAAK,CAAC,CAAC,CAAC;AACR;;"}
1
+ {"version":3,"file":"custom.js","sources":["../../../../../src/runtime/internals/operations/custom.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.customOpFactory = void 0;\nconst rxjs_1 = require(\"rxjs\");\nconst APIClient_1 = require(\"../APIClient\");\nconst utils_1 = require(\"./utils\");\n/**\n * Type guard for checking whether a Custom Operation argument is a contextSpec object\n */\nconst argIsContextSpec = (arg) => {\n return typeof arg?.token?.value === 'symbol';\n};\n/**\n * Builds an operation function, embedded with all client and context data, that\n * can be attached to a client as a custom query or mutation.\n *\n * If we have this source schema:\n *\n * ```typescript\n * a.schema({\n * echo: a.query()\n * .arguments({input: a.string().required()})\n * .returns(a.string())\n * })\n * ```\n *\n * Our model intro schema will contain an entry like this:\n *\n * ```ts\n * {\n * queries: {\n * echo: {\n * name: \"echo\",\n * isArray: false,\n * type: 'String',\n * isRequired: false,\n * arguments: {\n * input: {\n * name: 'input',\n * isArray: false,\n * type: String,\n * isRequired: true\n * }\n * }\n * }\n * }\n * }\n * ```\n *\n * The `echo` object is used to build the `echo' method that goes here:\n *\n * ```typescript\n * const client = generateClent()\n * const { data } = await client.queries.echo({input: 'a string'});\n * // ^\n * // |\n * // +-- This one right here.\n * //\n * ```\n *\n *\n * @param client The client to run graphql queries through.\n * @param modelIntrospection The model introspection schema the op comes from.\n * @param operationType The broad category of graphql operation.\n * @param operation The operation definition from the introspection schema.\n * @param useContext Whether the function needs to accept an SSR context.\n * @returns The operation function to attach to query, mutations, etc.\n */\nfunction customOpFactory(client, modelIntrospection, operationType, operation, useContext, getInternals) {\n // .arguments() are defined for the custom operation in the schema builder\n // and are present in the model introspection schema\n const argsDefined = operation.arguments !== undefined;\n const op = (...args) => {\n // options is always the last argument\n const options = args[args.length - 1];\n let contextSpec;\n let arg;\n if (useContext) {\n if (argIsContextSpec(args[0])) {\n contextSpec = args[0];\n }\n else {\n throw new Error(`Invalid first argument passed to ${operation.name}. Expected contextSpec`);\n }\n }\n if (argsDefined) {\n if (useContext) {\n arg = args[1];\n }\n else {\n arg = args[0];\n }\n }\n if (operationType === 'subscription') {\n return _opSubscription(\n // subscriptions are only enabled on the clientside\n client, modelIntrospection, operation, getInternals, arg, options);\n }\n return _op(client, modelIntrospection, operationType, operation, getInternals, arg, options, contextSpec);\n };\n return op;\n}\nexports.customOpFactory = customOpFactory;\n/**\n * Runtime test and type guard to check whether `o[field]` is a `String`.\n *\n * ```typescript\n * if (hasStringField(o, 'prop')) {\n * const s = o.prop;\n * // ^? const s: string\n * }\n * ```\n *\n * @param o Object to inspect\n * @param field Field to look for\n * @returns Boolean: `true` if the `o[field]` is a `string`\n */\nfunction hasStringField(o, field) {\n return typeof o[field] === 'string';\n}\n/**\n * Generates \"outer\" arguments string for a custom operation. For example,\n * in this operation:\n *\n * ```graphql\n * query MyQuery(InputString: String!) {\n * echoString(InputString: $InputString)\n * }\n * ```\n *\n * This function returns the top/outer level arguments as a string:\n *\n * ```json\n * \"InputString: String!\"\n * ```\n *\n * @param operation Operation object from model introspection schema.\n * @returns \"outer\" arguments string\n */\nfunction outerArguments(operation) {\n if (operation.arguments === undefined) {\n return '';\n }\n const args = Object.entries(operation.arguments)\n .map(([k, v]) => {\n const baseType = v.type + (v.isRequired ? '!' : '');\n const finalType = v.isArray\n ? `[${baseType}]${v.isArrayNullable ? '' : '!'}`\n : baseType;\n return `$${k}: ${finalType}`;\n })\n .join(', ');\n return args.length > 0 ? `(${args})` : '';\n}\n/**\n * Generates \"inner\" arguments string for a custom operation. For example,\n * in this operation:\n *\n * ```graphql\n * query MyQuery(InputString: String!) {\n * echoString(InputString: $InputString)\n * }\n * ```\n *\n * This function returns the inner arguments as a string:\n *\n * ```json\n * \"InputString: $InputString\"\n * ```\n *\n * @param operation Operation object from model introspection schema.\n * @returns \"outer\" arguments string\n */\nfunction innerArguments(operation) {\n if (operation.arguments === undefined) {\n return '';\n }\n const args = Object.keys(operation.arguments)\n .map((k) => `${k}: $${k}`)\n .join(', ');\n return args.length > 0 ? `(${args})` : '';\n}\n/**\n * Generates the selection set string for a custom operation. This is slightly\n * different than the selection set generation for models. If the custom op returns\n * a primitive or enum types, it doen't require a selection set at all.\n *\n * E.g., the graphql might look like this:\n *\n * ```graphql\n * query MyQuery {\n * echoString(inputString: \"whatever\")\n * }\n * # ^\n * # |\n * # +-- no selection set\n * ```\n *\n * Non-primitive return type selection set generation will be similar to other\n * model operations.\n *\n * @param modelIntrospection The full code-generated introspection schema.\n * @param operation The operation object from the schema.\n * @returns The selection set as a string.\n */\nfunction operationSelectionSet(modelIntrospection, operation) {\n if (hasStringField(operation, 'type') ||\n hasStringField(operation.type, 'enum')) {\n return '';\n }\n else if (hasStringField(operation.type, 'nonModel')) {\n const nonModel = modelIntrospection.nonModels[operation.type.nonModel];\n return `{${(0, APIClient_1.selectionSetIRToString)((0, APIClient_1.getDefaultSelectionSetForNonModelWithIR)(nonModel, modelIntrospection))}}`;\n }\n else if (hasStringField(operation.type, 'model')) {\n return `{${(0, APIClient_1.generateSelectionSet)(modelIntrospection, operation.type.model)}}`;\n }\n else {\n return '';\n }\n}\n/**\n * Maps an arguments objec to graphql variables, removing superfluous args and\n * screaming loudly when required args are missing.\n *\n * @param operation The operation to construct graphql request variables for.\n * @param args The arguments to map variables from.\n * @returns The graphql variables object.\n */\nfunction operationVariables(operation, args = {}) {\n const variables = {};\n if (operation.arguments === undefined) {\n return variables;\n }\n for (const argDef of Object.values(operation.arguments)) {\n if (typeof args[argDef.name] !== 'undefined') {\n variables[argDef.name] = args[argDef.name];\n }\n else if (argDef.isRequired) {\n // At this point, the variable is both required and missing: We don't need\n // to continue. The operation is expected to fail.\n throw new Error(`${operation.name} requires arguments '${argDef.name}'`);\n }\n }\n return variables;\n}\n/**\n * Executes an operation from the given model intro schema against a client, returning\n * a fully instantiated model when relevant.\n *\n * @param client The client to operate `graphql()` calls through.\n * @param modelIntrospection The model intro schema to construct requests from.\n * @param operationType The high level graphql operation type.\n * @param operation The specific operation name, args, return type details.\n * @param args The arguments to provide to the operation as variables.\n * @param options Request options like headers, etc.\n * @param context SSR context if relevant.\n * @returns Result from the graphql request, model-instantiated when relevant.\n */\nasync function _op(client, modelIntrospection, operationType, operation, getInternals, args, options, context) {\n const { name: operationName } = operation;\n const auth = (0, APIClient_1.authModeParams)(client, getInternals, options);\n const headers = (0, APIClient_1.getCustomHeaders)(client, getInternals, options?.headers);\n const outerArgsString = outerArguments(operation);\n const innerArgsString = innerArguments(operation);\n const selectionSet = operationSelectionSet(modelIntrospection, operation);\n const returnTypeModelName = hasStringField(operation.type, 'model')\n ? operation.type.model\n : undefined;\n const query = `\n ${operationType.toLocaleLowerCase()}${outerArgsString} {\n ${operationName}${innerArgsString} ${selectionSet}\n }\n `;\n const variables = operationVariables(operation, args);\n try {\n const { data, extensions } = context\n ? (await client.graphql(context, {\n ...auth,\n query,\n variables,\n }, headers))\n : (await client.graphql({\n ...auth,\n query,\n variables,\n }, headers));\n // flatten response\n if (data) {\n const [key] = Object.keys(data);\n const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];\n // TODO: custom selection set. current selection set is default selection set only\n // custom selection set requires data-schema-type + runtime updates above.\n const [initialized] = returnTypeModelName\n ? (0, APIClient_1.initializeModel)(client, returnTypeModelName, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context)\n : [flattenedResult];\n return { data: initialized, extensions };\n }\n else {\n return { data: null, extensions };\n }\n }\n catch (error) {\n /**\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)(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 // TODO: custom selection set. current selection set is default selection set only\n // custom selection set requires data-schema-type + runtime updates above.\n const [initialized] = returnTypeModelName\n ? (0, APIClient_1.initializeModel)(client, returnTypeModelName, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context)\n : [flattenedResult];\n return { data: initialized, errors };\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 * Executes an operation from the given model intro schema against a client, returning\n * a fully instantiated model when relevant.\n *\n * @param client The client to operate `graphql()` calls through.\n * @param modelIntrospection The model intro schema to construct requests from.\n * @param operation The specific operation name, args, return type details.\n * @param args The arguments to provide to the operation as variables.\n * @param options Request options like headers, etc.\n * @returns Result from the graphql request, model-instantiated when relevant.\n */\nfunction _opSubscription(client, modelIntrospection, operation, getInternals, args, options) {\n const operationType = 'subscription';\n const { name: operationName } = operation;\n const auth = (0, APIClient_1.authModeParams)(client, getInternals, options);\n const headers = (0, APIClient_1.getCustomHeaders)(client, getInternals, options?.headers);\n const outerArgsString = outerArguments(operation);\n const innerArgsString = innerArguments(operation);\n const selectionSet = operationSelectionSet(modelIntrospection, operation);\n const returnTypeModelName = hasStringField(operation.type, 'model')\n ? operation.type.model\n : undefined;\n const query = `\n ${operationType.toLocaleLowerCase()}${outerArgsString} {\n ${operationName}${innerArgsString} ${selectionSet}\n }\n `;\n const variables = operationVariables(operation, args);\n const observable = client.graphql({\n ...auth,\n query,\n variables,\n }, headers);\n return observable.pipe((0, rxjs_1.map)((value) => {\n const [key] = Object.keys(value.data);\n const data = value.data[key];\n const [initialized] = returnTypeModelName\n ? (0, APIClient_1.initializeModel)(client, returnTypeModelName, [data], modelIntrospection, auth.authMode, auth.authToken)\n : [data];\n return initialized;\n }));\n}\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,eAAe,GAAG,KAAK,CAAC,CAAC;AACjC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;AAC/B,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AACnC;AACA;AACA;AACA,MAAM,gBAAgB,GAAG,CAAC,GAAG,KAAK;AAClC,IAAI,OAAO,OAAO,GAAG,EAAE,KAAK,EAAE,KAAK,KAAK,QAAQ,CAAC;AACjD,CAAC,CAAC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,eAAe,CAAC,MAAM,EAAE,kBAAkB,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE;AACzG;AACA;AACA,IAAI,MAAM,WAAW,GAAG,SAAS,CAAC,SAAS,KAAK,SAAS,CAAC;AAC1D,IAAI,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,KAAK;AAC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,UAAU,SAAS,CAAC;AACpB,IAAI,MAAM,KAAK,GAAG,CAAC;AACnB,IAAI,EAAE,aAAa,CAAC,iBAAiB,EAAE,CAAC,EAAE,eAAe,CAAC;AAC1D,MAAM,EAAE,aAAa,CAAC,EAAE,eAAe,CAAC,CAAC,EAAE,YAAY,CAAC;AACxD;AACA,EAAE,CAAC,CAAC;AACJ,IAAI,MAAM,SAAS,GAAG,kBAAkB,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;AAC1D,IAAI,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC;AACtC,QAAQ,GAAG,IAAI;AACf,QAAQ,KAAK;AACb,QAAQ,SAAS;AACjB,KAAK,EAAE,OAAO,CAAC,CAAC;AAChB,IAAI,OAAO,UAAU,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC,KAAK,KAAK;AACtD,QAAQ,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAC9C,QAAQ,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACrC,QAAQ,MAAM,CAAC,WAAW,CAAC,GAAG,mBAAmB;AACjD,cAAc,IAAI,WAAW,CAAC,eAAe,EAAE,MAAM,EAAE,mBAAmB,EAAE,CAAC,IAAI,CAAC,EAAE,kBAAkB,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC;AACtI,cAAc,CAAC,IAAI,CAAC,CAAC;AACrB,QAAQ,OAAO,WAAW,CAAC;AAC3B,KAAK,CAAC,CAAC,CAAC;AACR;;"}
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.getFactory = void 0;
5
5
  const APIClient_1 = require("../APIClient");
6
+ const utils_1 = require("./utils");
6
7
  function getFactory(client, modelIntrospection, model, operation, getInternals, useContext = false) {
7
8
  const getWithContext = async (contextSpec, arg, options) => {
8
9
  return _get(client, modelIntrospection, model, arg, options, operation, getInternals, contextSpec);
@@ -17,8 +18,8 @@ async function _get(client, modelIntrospection, model, arg, options, operation,
17
18
  const { name } = model;
18
19
  const query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection, name, operation, options);
19
20
  const variables = (0, APIClient_1.buildGraphQLVariables)(model, operation, arg, modelIntrospection);
21
+ const auth = (0, APIClient_1.authModeParams)(client, getInternals, options);
20
22
  try {
21
- const auth = (0, APIClient_1.authModeParams)(client, getInternals, options);
22
23
  const headers = (0, APIClient_1.getCustomHeaders)(client, getInternals, options?.headers);
23
24
  const { data, extensions } = context
24
25
  ? (await client.graphql(context, {
@@ -49,13 +50,42 @@ async function _get(client, modelIntrospection, model, arg, options, operation,
49
50
  }
50
51
  }
51
52
  catch (error) {
52
- if (error.errors) {
53
- // graphql errors pass through
54
- return error;
53
+ /**
54
+ * The `data` type returned by `error` here could be:
55
+ * 1) `null`
56
+ * 2) an empty object
57
+ * 3) "populated" but with a `null` value `{ getPost: null }`
58
+ * 4) an actual record `{ getPost: { id: '1', title: 'Hello, World!' } }`
59
+ */
60
+ const { data, errors } = error;
61
+ /**
62
+ * `data` is not `null`, and is not an empty object:
63
+ */
64
+ if (data && Object.keys(data).length !== 0 && errors) {
65
+ const [key] = Object.keys(data);
66
+ const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];
67
+ /**
68
+ * `flattenedResult` could be `null` here (e.g. `data: { getPost: null }`)
69
+ * if `flattenedResult`, result is an actual record:
70
+ */
71
+ if (flattenedResult) {
72
+ if (options?.selectionSet) {
73
+ return { data: flattenedResult, errors };
74
+ }
75
+ else {
76
+ // TODO: refactor to avoid destructuring here
77
+ const [initialized] = (0, APIClient_1.initializeModel)(client, name, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context);
78
+ return { data: initialized, errors };
79
+ }
80
+ }
81
+ else {
82
+ // was `data: { getPost: null }`)
83
+ return (0, utils_1.handleSingularGraphQlError)(error);
84
+ }
55
85
  }
56
86
  else {
57
- // non-graphql errors re re-thrown
58
- throw error;
87
+ // `data` is `null`:
88
+ return (0, utils_1.handleSingularGraphQlError)(error);
59
89
  }
60
90
  }
61
91
  }
@@ -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\");\nfunction 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}\nexports.getFactory = getFactory;\nasync function _get(client, modelIntrospection, model, arg, options, operation, getInternals, context) {\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 try {\n const auth = (0, APIClient_1.authModeParams)(client, getInternals, options);\n const headers = (0, APIClient_1.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 = (0, APIClient_1.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] = (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 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":[],"mapp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EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;AACtK,gBAAgB,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,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.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 = 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}\nexports.getFactory = getFactory;\nasync function _get(client, modelIntrospection, model, arg, options, operation, getInternals, context) {\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 { data, extensions } = context\n ? (await client.graphql(context, {\n ...auth,\n query,\n variables,\n }, headers))\n : (await client.graphql({\n ...auth,\n query,\n variables,\n }, headers));\n // flatten response\n if (data) {\n const [key] = Object.keys(data);\n const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];\n 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)(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"],"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,SAAS,UAAU,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,GAAG,K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I,EAAE,MAAM,EAAE,GAAG,KAAK,CAAC;AACvC;AACA;AACA;AACA,QAAQ,IAAI,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,MAAM,EAAE;AAC9D,YAAY,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC5C,YAAY,MAAM,eAAe,GAAG,IAAI,WAAW,CAAC,YAAY,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;AAC7E;AACA;AACA;AACA;AACA,YAAY,IAAI,eAAe,EAAE;AACjC,gBAAgB,IAAI,OAAO,EAAE,YAAY,EAAE;AAC3C,oBAAoB,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,EAAE,CAAC;AAC7D,iBAAiB;AACjB,qBAAqB;AACrB;AACA,oBAAoB,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;AAC1K,oBAAoB,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AACzD,iBAAiB;AACjB,aAAa;AACb,iBAAiB;AACjB;AACA,gBAAgB,OAAO,IAAI,OAAO,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC;AACtE,aAAa;AACb,SAAS;AACT,aAAa;AACb;AACA,YAAY,OAAO,IAAI,OAAO,CAAC,0BAA0B,EAAE,KAAK,CAAC,CAAC;AAClE,SAAS;AACT,KAAK;AACL;;"}
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.indexQueryFactory = void 0;
5
5
  const APIClient_1 = require("../APIClient");
6
+ const utils_1 = require("./utils");
6
7
  function indexQueryFactory(client, modelIntrospection, model, indexMeta, getInternals, context = false) {
7
8
  const indexQueryWithContext = async (contextSpec, args, options) => {
8
9
  return _indexQuery(client, modelIntrospection, model, indexMeta, getInternals, {
@@ -36,16 +37,6 @@ function processGraphQlResponse(result, selectionSet, modelInitializer) {
36
37
  extensions,
37
38
  };
38
39
  }
39
- function handleGraphQlError(error) {
40
- if (error.errors) {
41
- // graphql errors pass through
42
- return error;
43
- }
44
- else {
45
- // non-graphql errors re re-thrown
46
- throw error;
47
- }
48
- }
49
40
  async function _indexQuery(client, modelIntrospection, model, indexMeta, getInternals, args, contextSpec) {
50
41
  const { name } = model;
51
42
  const query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection, name, 'INDEX_QUERY', args, indexMeta);
@@ -69,7 +60,44 @@ async function _indexQuery(client, modelIntrospection, model, indexMeta, getInte
69
60
  }
70
61
  }
71
62
  catch (error) {
72
- return handleGraphQlError(error);
63
+ /**
64
+ * The `data` type returned by `error` here could be:
65
+ * 1) `null`
66
+ * 2) an empty object
67
+ * 3) "populated" but with a `null` value:
68
+ * `data: { listByExampleId: null }`
69
+ * 4) an actual record:
70
+ * `data: { listByExampleId: 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 && Object.keys(data).length !== 0 && errors) {
75
+ const [key] = Object.keys(data);
76
+ if (data[key]?.items) {
77
+ const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];
78
+ /**
79
+ * Check exists since `flattenedResult` could be `null`.
80
+ * if `flattenedResult` exists, result is an actual record.
81
+ */
82
+ if (flattenedResult) {
83
+ return {
84
+ data: args?.selectionSet
85
+ ? flattenedResult
86
+ : modelInitializer(flattenedResult),
87
+ nextToken: data[key]?.nextToken,
88
+ };
89
+ }
90
+ }
91
+ // response is of type `data: { listByExampleId: null }`
92
+ return {
93
+ data: data[key],
94
+ nextToken: data[key]?.nextToken,
95
+ };
96
+ }
97
+ else {
98
+ // `data` is `null` or an empty object:
99
+ return (0, utils_1.handleListGraphQlError)(error);
100
+ }
73
101
  }
74
102
  }
75
103
  //# 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\");\nfunction 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}\nexports.indexQueryFactory = indexQueryFactory;\nfunction processGraphQlResponse(result, selectionSet, modelInitializer) {\n const { data, extensions } = result;\n const [key] = Object.keys(data);\n if (data[key].items) {\n const flattenedResult = (0, APIClient_1.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 = (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 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":";;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,SAAS,iBAAiB,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,GAAG,KAAK,EAAE;AACxG,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,OAAO,CAAC,iBAAiB,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AAC,KAAK,CAAC,CAAC;AACzC,KAAK;AACL;;"}
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 = 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}\nexports.indexQueryFactory = indexQueryFactory;\nfunction processGraphQlResponse(result, selectionSet, modelInitializer) {\n const { data, extensions } = result;\n const [key] = Object.keys(data);\n if (data[key].items) {\n const flattenedResult = (0, APIClient_1.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 = (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 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 = (0, APIClient_1.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 (0, utils_1.handleListGraphQlError)(error);\n }\n }\n}\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,iBAAiB,GAAG,KAAK,CAAC,CAAC;AACnC,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AACnC,SAAS,iBAAiB,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,GAAG,KAAK,EAAE;AACxG,IAAI,MAAM,qBAAqB,GAAG,OAAO,WAAW,EAAE,IAAI,EAAE,OAAO,KAAK;AACxE,QAAQ,OAAO,WAAW,CAAC,MAAM,EAAE,kBAAkB,E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AAO,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;AAC9D,SAAS;AACT,KAAK;AACL;;"}
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.listFactory = void 0;
5
5
  const APIClient_1 = require("../APIClient");
6
+ const utils_1 = require("./utils");
6
7
  function listFactory(client, modelIntrospection, model, getInternals, context = false) {
7
8
  const listWithContext = async (contextSpec, args) => {
8
9
  return _list(client, modelIntrospection, model, getInternals, args, contextSpec);
@@ -17,8 +18,8 @@ async function _list(client, modelIntrospection, model, getInternals, args, cont
17
18
  const { name } = model;
18
19
  const query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection, name, 'LIST', args);
19
20
  const variables = (0, APIClient_1.buildGraphQLVariables)(model, 'LIST', args, modelIntrospection);
21
+ const auth = (0, APIClient_1.authModeParams)(client, getInternals, args);
20
22
  try {
21
- const auth = (0, APIClient_1.authModeParams)(client, getInternals, args);
22
23
  const headers = (0, APIClient_1.getCustomHeaders)(client, getInternals, args?.headers);
23
24
  const { data, extensions } = contextSpec
24
25
  ? (await client.graphql(contextSpec, {
@@ -61,13 +62,56 @@ async function _list(client, modelIntrospection, model, getInternals, args, cont
61
62
  }
62
63
  }
63
64
  catch (error) {
64
- if (error.errors) {
65
- // graphql errors pass through
66
- return 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 && Object.keys(data).length !== 0 && errors) {
75
+ const [key] = Object.keys(data);
76
+ if (data[key]?.items) {
77
+ const flattenedResult = (0, APIClient_1.flattenItems)(data)[key];
78
+ /**
79
+ * Check exists since `flattenedResult` could be `null`.
80
+ * if `flattenedResult` exists, result is an actual record.
81
+ */
82
+ if (flattenedResult) {
83
+ // don't init if custom selection set
84
+ if (args?.selectionSet) {
85
+ return {
86
+ data: flattenedResult,
87
+ nextToken: data[key]?.nextToken,
88
+ errors,
89
+ };
90
+ }
91
+ else {
92
+ const initialized = (0, APIClient_1.initializeModel)(client, name, flattenedResult, modelIntrospection, auth.authMode, auth.authToken, !!contextSpec);
93
+ // data is full record w/out selection set:
94
+ return {
95
+ data: initialized,
96
+ nextToken: data[key]?.nextToken,
97
+ errors,
98
+ };
99
+ }
100
+ }
101
+ return {
102
+ data: data[key],
103
+ nextToken: data[key]?.nextToken,
104
+ errors,
105
+ };
106
+ }
107
+ else {
108
+ // response is of type `data: { getPost: null }`)
109
+ return (0, utils_1.handleListGraphQlError)(error);
110
+ }
67
111
  }
68
112
  else {
69
- // non-graphql errors re re-thrown
70
- throw error;
113
+ // `data` is `null` or an empty object:
114
+ return (0, utils_1.handleListGraphQlError)(error);
71
115
  }
72
116
  }
73
117
  }
@@ -1 +1 @@
1
- {"version":3,"file":"list.js","sources":["../../../../../src/runtime/internals/operations/list.ts"],"sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.listFactory = void 0;\nconst APIClient_1 = require(\"../APIClient\");\nfunction 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}\nexports.listFactory = listFactory;\nasync function _list(client, modelIntrospection, model, getInternals, args, contextSpec) {\n const { name } = model;\n const query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection, name, 'LIST', args);\n const variables = (0, APIClient_1.buildGraphQLVariables)(model, 'LIST', args, modelIntrospection);\n try {\n const auth = (0, APIClient_1.authModeParams)(client, getInternals, args);\n const headers = (0, APIClient_1.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 = (0, APIClient_1.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 = (0, APIClient_1.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":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,WAAW,GAAG,KAAK,CAAC,CAAC;AAC7B,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAC5C,SAAS,WAAW,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,GAAG,KAAK,EAAE;AACvF,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,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sourcesContent":["\"use strict\";\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.listFactory = void 0;\nconst APIClient_1 = require(\"../APIClient\");\nconst utils_1 = require(\"./utils\");\nfunction 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}\nexports.listFactory = listFactory;\nasync function _list(client, modelIntrospection, model, getInternals, args, contextSpec) {\n const { name } = model;\n const query = (0, APIClient_1.generateGraphQLDocument)(modelIntrospection, name, 'LIST', args);\n const variables = (0, APIClient_1.buildGraphQLVariables)(model, 'LIST', args, modelIntrospection);\n const auth = (0, APIClient_1.authModeParams)(client, getInternals, args);\n try {\n const headers = (0, APIClient_1.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 = (0, APIClient_1.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 = (0, APIClient_1.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 = (0, APIClient_1.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 = (0, APIClient_1.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 (0, utils_1.handleListGraphQlError)(error);\n }\n }\n else {\n // `data` is `null` or an empty object:\n return (0, utils_1.handleListGraphQlError)(error);\n }\n }\n}\n"],"names":[],"mappings":";;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,WAAW,GAAG,KAAK,CAAC,CAAC;AAC7B,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,CAAC,CAAC;AAC5C,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AACnC,SAAS,WAAW,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,YAAY,EAAE,OAAO,GAAG,KAAK,EAAE;AACvF,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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iB;AACjB;AACA,gBAAgB,OAAO,IAAI,OAAO,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;AAClE,aAAa;AACb,SAAS;AACT,aAAa;AACb;AACA,YAAY,OAAO,IAAI,OAAO,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;AAC9D,SAAS;AACT,KAAK;AACL;;"}
@@ -0,0 +1,42 @@
1
+ 'use strict';
2
+
3
+ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4
+ // SPDX-License-Identifier: Apache-2.0
5
+ // import { GraphQLFormattedError } from '@aws-amplify/data-schema-types';
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.handleSingularGraphQlError = exports.handleListGraphQlError = void 0;
8
+ /**
9
+ * Handle errors for list return types (list and index query operations)
10
+ */
11
+ function handleListGraphQlError(error) {
12
+ if (error?.errors) {
13
+ // graphql errors pass through
14
+ return {
15
+ ...error,
16
+ data: [],
17
+ };
18
+ }
19
+ else {
20
+ // non-graphql errors are re-thrown
21
+ throw error;
22
+ }
23
+ }
24
+ exports.handleListGraphQlError = handleListGraphQlError;
25
+ /**
26
+ * Handle errors for singular return types (create, get, update, delete operations)
27
+ */
28
+ function handleSingularGraphQlError(error) {
29
+ if (error.errors) {
30
+ // graphql errors pass through
31
+ return {
32
+ ...error,
33
+ data: null,
34
+ };
35
+ }
36
+ else {
37
+ // non-graphql errors are re-thrown
38
+ throw error;
39
+ }
40
+ }
41
+ exports.handleSingularGraphQlError = handleSingularGraphQlError;
42
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sources":["../../../../../src/runtime/internals/operations/utils.ts"],"sourcesContent":["\"use strict\";\n// 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';\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.handleSingularGraphQlError = exports.handleListGraphQlError = void 0;\n/**\n * Handle errors for list return types (list and index query operations)\n */\nfunction 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}\nexports.handleListGraphQlError = handleListGraphQlError;\n/**\n * Handle errors for singular return types (create, get, update, delete operations)\n */\nfunction 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}\nexports.handleSingularGraphQlError = handleSingularGraphQlError;\n"],"names":[],"mappings":";;AACA;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,0BAA0B,GAAG,OAAO,CAAC,sBAAsB,GAAG,KAAK,CAAC,CAAC;AAC7E;AACA;AACA;AACA,SAAS,sBAAsB,CAAC,KAAK,EAAE;AACvC,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,OAAO,CAAC,sBAAsB,GAAG,sBAAsB,CAAC;AACxD;AACA;AACA;AACA,SAAS,0BAA0B,CAAC,KAAK,EAAE;AAC3C,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,CAAC;AACD,OAAO,CAAC,0BAA0B,GAAG,0BAA0B;;"}
@@ -347,8 +347,8 @@ export type ImpliedAuthField<T extends Authorization<any, any, any>> = T extends
347
347
  export type ImpliedAuthFields<T extends Authorization<any, any, any>> = ImpliedAuthField<T> extends never ? never : UnionToIntersection<ImpliedAuthField<T>>;
348
348
  export declare const accessData: <T extends Authorization<any, any, any>>(authorization: T) => {
349
349
  strategy?: any;
350
- provider?: "function" | "apiKey" | "iam" | "userPools" | "oidc" | undefined;
351
- operations?: ("create" | "update" | "delete" | "read" | "get" | "list" | "sync" | "listen" | "search")[] | undefined;
350
+ provider?: "function" | "apiKey" | "iam" | "oidc" | "userPools" | undefined;
351
+ operations?: ("create" | "get" | "update" | "delete" | "list" | "search" | "read" | "sync" | "listen")[] | undefined;
352
352
  groupOrOwnerField?: any;
353
353
  groups?: string[] | undefined;
354
354
  multiOwner: any;
@@ -93,5 +93,5 @@ export declare function hasMany<RM extends string>(relatedModel: RM, references:
93
93
  * @param relatedModel name of the related `.hasOne()` or `.hasMany()` model
94
94
  * @returns a belong-to relationship definition
95
95
  */
96
- export declare function belongsTo<RM extends string>(relatedModel: RM, references: string | string[]): ModelRelationalField<ModelRelationalTypeArgFactory<RM, ModelRelationshipTypes.belongsTo, false>, RM, "valueRequired" | "arrayRequired" | "required", undefined>;
96
+ export declare function belongsTo<RM extends string>(relatedModel: RM, references: string | string[]): ModelRelationalField<ModelRelationalTypeArgFactory<RM, ModelRelationshipTypes.belongsTo, false>, RM, "required" | "valueRequired" | "arrayRequired", undefined>;
97
97
  export {};
@@ -1,5 +1,6 @@
1
1
  import { map } from 'rxjs';
2
2
  import { authModeParams, getCustomHeaders, flattenItems, initializeModel, selectionSetIRToString, getDefaultSelectionSetForNonModelWithIR, generateSelectionSet } from '../APIClient.mjs';
3
+ import { handleSingularGraphQlError } from './utils.mjs';
3
4
 
4
5
  /**
5
6
  * Type guard for checking whether a Custom Operation argument is a contextSpec object
@@ -297,13 +298,40 @@ async function _op(client, modelIntrospection, operationType, operation, getInte
297
298
  }
298
299
  }
299
300
  catch (error) {
300
- if (error.errors) {
301
- // graphql errors pass through
302
- return error;
301
+ /**
302
+ * The `data` type returned by `error` here could be:
303
+ * 1) `null`
304
+ * 2) an empty object
305
+ * 3) "populated" but with a `null` value `{ getPost: null }`
306
+ * 4) an actual record `{ getPost: { id: '1', title: 'Hello, World!' } }`
307
+ */
308
+ const { data, errors } = error;
309
+ /**
310
+ * `data` is not `null`, and is not an empty object:
311
+ */
312
+ if (data && Object.keys(data).length !== 0 && errors) {
313
+ const [key] = Object.keys(data);
314
+ const flattenedResult = flattenItems(data)[key];
315
+ /**
316
+ * `flattenedResult` could be `null` here (e.g. `data: { getPost: null }`)
317
+ * if `flattenedResult`, result is an actual record:
318
+ */
319
+ if (flattenedResult) {
320
+ // TODO: custom selection set. current selection set is default selection set only
321
+ // custom selection set requires data-schema-type + runtime updates above.
322
+ const [initialized] = returnTypeModelName
323
+ ? initializeModel(client, returnTypeModelName, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context)
324
+ : [flattenedResult];
325
+ return { data: initialized, errors };
326
+ }
327
+ else {
328
+ // was `data: { getPost: null }`)
329
+ return handleSingularGraphQlError(error);
330
+ }
303
331
  }
304
332
  else {
305
- // non-graphql errors re re-thrown
306
- throw error;
333
+ // `data` is `null`:
334
+ return handleSingularGraphQlError(error);
307
335
  }
308
336
  }
309
337
  }