@aws-amplify/data-schema 1.3.9 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/dist/cjs/ModelType.js +5 -0
  2. package/dist/cjs/ModelType.js.map +1 -1
  3. package/dist/cjs/SchemaProcessor.js +58 -1
  4. package/dist/cjs/SchemaProcessor.js.map +1 -1
  5. package/dist/cjs/runtime/addSchemaToClient.js +1 -0
  6. package/dist/cjs/runtime/addSchemaToClient.js.map +1 -1
  7. package/dist/cjs/runtime/addSchemaToClientWithInstance.js +1 -0
  8. package/dist/cjs/runtime/addSchemaToClientWithInstance.js.map +1 -1
  9. package/dist/cjs/runtime/internals/APIClient.js +63 -42
  10. package/dist/cjs/runtime/internals/APIClient.js.map +1 -1
  11. package/dist/cjs/runtime/internals/cancellation.js +48 -0
  12. package/dist/cjs/runtime/internals/cancellation.js.map +1 -0
  13. package/dist/cjs/runtime/internals/clientUtils.js +45 -3
  14. package/dist/cjs/runtime/internals/clientUtils.js.map +1 -1
  15. package/dist/cjs/runtime/internals/index.js +3 -1
  16. package/dist/cjs/runtime/internals/index.js.map +1 -1
  17. package/dist/cjs/runtime/internals/operations/custom.js +91 -85
  18. package/dist/cjs/runtime/internals/operations/custom.js.map +1 -1
  19. package/dist/cjs/runtime/internals/operations/get.js +71 -65
  20. package/dist/cjs/runtime/internals/operations/get.js.map +1 -1
  21. package/dist/cjs/runtime/internals/operations/indexQuery.js +66 -60
  22. package/dist/cjs/runtime/internals/operations/indexQuery.js.map +1 -1
  23. package/dist/cjs/runtime/internals/operations/list.js +90 -84
  24. package/dist/cjs/runtime/internals/operations/list.js.map +1 -1
  25. package/dist/cjs/runtime/internals/server/generateModelsProperty.js +3 -3
  26. package/dist/cjs/runtime/internals/server/generateModelsProperty.js.map +1 -1
  27. package/dist/cjs/runtime/internals/utils/clientProperties/generateModelsProperty.js +3 -3
  28. package/dist/cjs/runtime/internals/utils/clientProperties/generateModelsProperty.js.map +1 -1
  29. package/dist/cjs/runtime/utils/index.js +3 -1
  30. package/dist/cjs/runtime/utils/index.js.map +1 -1
  31. package/dist/cjs/runtime/utils/selfAwareAsync.js +40 -0
  32. package/dist/cjs/runtime/utils/selfAwareAsync.js.map +1 -0
  33. package/dist/esm/Authorization.d.ts +1 -1
  34. package/dist/esm/ClientSchema/Core/ClientModel.d.ts +20 -1
  35. package/dist/esm/ClientSchema/utilities/ResolveField.d.ts +5 -1
  36. package/dist/esm/ModelType.d.ts +6 -0
  37. package/dist/esm/ModelType.mjs +5 -0
  38. package/dist/esm/ModelType.mjs.map +1 -1
  39. package/dist/esm/SchemaProcessor.mjs +58 -1
  40. package/dist/esm/SchemaProcessor.mjs.map +1 -1
  41. package/dist/esm/runtime/addSchemaToClient.mjs +2 -0
  42. package/dist/esm/runtime/addSchemaToClient.mjs.map +1 -1
  43. package/dist/esm/runtime/addSchemaToClientWithInstance.mjs +2 -0
  44. package/dist/esm/runtime/addSchemaToClientWithInstance.mjs.map +1 -1
  45. package/dist/esm/runtime/bridge-types.d.ts +2 -2
  46. package/dist/esm/runtime/client/index.d.ts +18 -10
  47. package/dist/esm/runtime/internals/APIClient.d.ts +2 -2
  48. package/dist/esm/runtime/internals/APIClient.mjs +64 -42
  49. package/dist/esm/runtime/internals/APIClient.mjs.map +1 -1
  50. package/dist/esm/runtime/internals/cancellation.d.ts +10 -0
  51. package/dist/esm/runtime/internals/cancellation.mjs +44 -0
  52. package/dist/esm/runtime/internals/cancellation.mjs.map +1 -0
  53. package/dist/esm/runtime/internals/clientUtils.d.ts +78 -1
  54. package/dist/esm/runtime/internals/clientUtils.mjs +45 -3
  55. package/dist/esm/runtime/internals/clientUtils.mjs.map +1 -1
  56. package/dist/esm/runtime/internals/index.d.ts +1 -0
  57. package/dist/esm/runtime/internals/index.mjs +1 -0
  58. package/dist/esm/runtime/internals/index.mjs.map +1 -1
  59. package/dist/esm/runtime/internals/operations/custom.d.ts +1 -1
  60. package/dist/esm/runtime/internals/operations/custom.mjs +91 -85
  61. package/dist/esm/runtime/internals/operations/custom.mjs.map +1 -1
  62. package/dist/esm/runtime/internals/operations/get.d.ts +1 -1
  63. package/dist/esm/runtime/internals/operations/get.mjs +71 -65
  64. package/dist/esm/runtime/internals/operations/get.mjs.map +1 -1
  65. package/dist/esm/runtime/internals/operations/indexQuery.d.ts +1 -1
  66. package/dist/esm/runtime/internals/operations/indexQuery.mjs +66 -60
  67. package/dist/esm/runtime/internals/operations/indexQuery.mjs.map +1 -1
  68. package/dist/esm/runtime/internals/operations/list.d.ts +1 -1
  69. package/dist/esm/runtime/internals/operations/list.mjs +90 -84
  70. package/dist/esm/runtime/internals/operations/list.mjs.map +1 -1
  71. package/dist/esm/runtime/internals/server/generateModelsProperty.mjs +4 -4
  72. package/dist/esm/runtime/internals/server/generateModelsProperty.mjs.map +1 -1
  73. package/dist/esm/runtime/internals/utils/clientProperties/generateModelsProperty.mjs +4 -4
  74. package/dist/esm/runtime/internals/utils/clientProperties/generateModelsProperty.mjs.map +1 -1
  75. package/dist/esm/runtime/utils/index.d.ts +1 -0
  76. package/dist/esm/runtime/utils/index.mjs +1 -0
  77. package/dist/esm/runtime/utils/index.mjs.map +1 -1
  78. package/dist/esm/runtime/utils/selfAwareAsync.d.ts +19 -0
  79. package/dist/esm/runtime/utils/selfAwareAsync.mjs +37 -0
  80. package/dist/esm/runtime/utils/selfAwareAsync.mjs.map +1 -0
  81. package/dist/esm/util/Filters.d.ts +42 -3
  82. package/dist/meta/cjs.tsbuildinfo +1 -1
  83. package/package.json +2 -2
  84. package/src/ClientSchema/Core/ClientModel.ts +29 -0
  85. package/src/ClientSchema/utilities/ResolveField.ts +26 -6
  86. package/src/ModelType.ts +31 -0
  87. package/src/SchemaProcessor.ts +77 -2
  88. package/src/runtime/addSchemaToClient.ts +2 -0
  89. package/src/runtime/addSchemaToClientWithInstance.ts +2 -0
  90. package/src/runtime/bridge-types.ts +2 -2
  91. package/src/runtime/client/index.ts +230 -184
  92. package/src/runtime/internals/APIClient.ts +67 -23
  93. package/src/runtime/internals/cancellation.ts +57 -0
  94. package/src/runtime/internals/clientUtils.ts +61 -1
  95. package/src/runtime/internals/index.ts +1 -0
  96. package/src/runtime/internals/operations/custom.ts +117 -109
  97. package/src/runtime/internals/operations/get.ts +111 -95
  98. package/src/runtime/internals/operations/indexQuery.ts +100 -94
  99. package/src/runtime/internals/operations/list.ts +132 -119
  100. package/src/runtime/internals/server/generateModelsProperty.ts +31 -28
  101. package/src/runtime/internals/utils/clientProperties/generateModelsProperty.ts +36 -33
  102. package/src/runtime/utils/index.ts +1 -0
  103. package/src/runtime/utils/selfAwareAsync.ts +39 -0
  104. package/src/util/Filters.ts +47 -3
@@ -1,6 +1,8 @@
1
1
  import { map } from 'rxjs';
2
2
  import { authModeParams, getCustomHeaders, initializeModel, selectionSetIRToString, getDefaultSelectionSetForNonModelWithIR, generateSelectionSet } from '../APIClient.mjs';
3
3
  import { handleSingularGraphQlError } from './utils.mjs';
4
+ import { selfAwareAsync } from '../../utils/selfAwareAsync.mjs';
5
+ import { extendCancellability } from '../cancellation.mjs';
4
6
 
5
7
  /**
6
8
  * Type guard for checking whether a Custom Operation argument is a contextSpec object
@@ -267,88 +269,48 @@ function operationVariables(operation, args = {}) {
267
269
  * @param context SSR context if relevant.
268
270
  * @returns Result from the graphql request, model-instantiated when relevant.
269
271
  */
270
- async function _op(client, modelIntrospection, operationType, operation, getInternals, args, options, context) {
271
- const { name: operationName } = operation;
272
- const auth = authModeParams(client, getInternals, options);
273
- const headers = getCustomHeaders(client, getInternals, options?.headers);
274
- const outerArgsString = outerArguments(operation);
275
- const innerArgsString = innerArguments(operation);
276
- const selectionSet = operationSelectionSet(modelIntrospection, operation);
277
- const returnTypeModelName = hasStringField(operation.type, 'model')
278
- ? operation.type.model
279
- : undefined;
280
- const query = `
272
+ function _op(client, modelIntrospection, operationType, operation, getInternals, args, options, context) {
273
+ return selfAwareAsync(async (resultPromise) => {
274
+ const { name: operationName } = operation;
275
+ const auth = authModeParams(client, getInternals, options);
276
+ const headers = getCustomHeaders(client, getInternals, options?.headers);
277
+ const outerArgsString = outerArguments(operation);
278
+ const innerArgsString = innerArguments(operation);
279
+ const selectionSet = operationSelectionSet(modelIntrospection, operation);
280
+ const returnTypeModelName = hasStringField(operation.type, 'model')
281
+ ? operation.type.model
282
+ : undefined;
283
+ const query = `
281
284
  ${operationType.toLocaleLowerCase()}${outerArgsString} {
282
285
  ${operationName}${innerArgsString} ${selectionSet}
283
286
  }
284
287
  `;
285
- const variables = operationVariables(operation, args);
286
- try {
287
- const { data, extensions } = context
288
- ? (await client.graphql(context, {
289
- ...auth,
290
- query,
291
- variables,
292
- }, headers))
293
- : (await client.graphql({
294
- ...auth,
295
- query,
296
- variables,
297
- }, headers));
298
- // flatten response
299
- if (data) {
300
- const [key] = Object.keys(data);
301
- const isArrayResult = Array.isArray(data[key]);
302
- // TODO: when adding support for custom selection set, flattening will need
303
- // to occur recursively. For now, it's expected that related models are not
304
- // present in the result. Only FK's are present. Any related model properties
305
- // should be replaced with lazy loaders under the current implementation.
306
- const flattenedResult = isArrayResult
307
- ? data[key].filter((x) => x)
308
- : data[key];
309
- // TODO: custom selection set. current selection set is default selection set only
310
- // custom selection set requires data-schema-type + runtime updates above.
311
- const initialized = returnTypeModelName
312
- ? initializeModel(client, returnTypeModelName, isArrayResult ? flattenedResult : [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context)
313
- : flattenedResult;
314
- return {
315
- data: !isArrayResult && Array.isArray(initialized)
316
- ? initialized.shift()
317
- : initialized,
318
- extensions,
319
- };
320
- }
321
- else {
322
- return { data: null, extensions };
323
- }
324
- }
325
- catch (error) {
326
- /**
327
- * The `data` type returned by `error` here could be:
328
- * 1) `null`
329
- * 2) an empty object
330
- * 3) "populated" but with a `null` value `{ getPost: null }`
331
- * 4) an actual record `{ getPost: { id: '1', title: 'Hello, World!' } }`
332
- */
333
- const { data, errors } = error;
334
- /**
335
- * `data` is not `null`, and is not an empty object:
336
- */
337
- if (data && Object.keys(data).length !== 0 && errors) {
338
- const [key] = Object.keys(data);
339
- const isArrayResult = Array.isArray(data[key]);
340
- // TODO: when adding support for custom selection set, flattening will need
341
- // to occur recursively. For now, it's expected that related models are not
342
- // present in the result. Only FK's are present. Any related model properties
343
- // should be replaced with lazy loaders under the current implementation.
344
- const flattenedResult = isArrayResult
345
- ? data[key].filter((x) => x)
346
- : data[key];
347
- /**
348
- * `flattenedResult` could be `null` here (e.g. `data: { getPost: null }`)
349
- * if `flattenedResult`, result is an actual record:
350
- */
351
- if (flattenedResult) {
288
+ const variables = operationVariables(operation, args);
289
+ try {
290
+ const basePromise = context
291
+ ? client.graphql(context, {
292
+ ...auth,
293
+ query,
294
+ variables,
295
+ }, headers)
296
+ : client.graphql({
297
+ ...auth,
298
+ query,
299
+ variables,
300
+ }, headers);
301
+ const extendedPromise = extendCancellability(basePromise, resultPromise);
302
+ const { data, extensions } = await extendedPromise;
303
+ // flatten response
304
+ if (data) {
305
+ const [key] = Object.keys(data);
306
+ const isArrayResult = Array.isArray(data[key]);
307
+ // TODO: when adding support for custom selection set, flattening will need
308
+ // to occur recursively. For now, it's expected that related models are not
309
+ // present in the result. Only FK's are present. Any related model properties
310
+ // should be replaced with lazy loaders under the current implementation.
311
+ const flattenedResult = isArrayResult
312
+ ? data[key].filter((x) => x)
313
+ : data[key];
352
314
  // TODO: custom selection set. current selection set is default selection set only
353
315
  // custom selection set requires data-schema-type + runtime updates above.
354
316
  const initialized = returnTypeModelName
@@ -358,19 +320,63 @@ async function _op(client, modelIntrospection, operationType, operation, getInte
358
320
  data: !isArrayResult && Array.isArray(initialized)
359
321
  ? initialized.shift()
360
322
  : initialized,
361
- errors,
323
+ extensions,
362
324
  };
363
325
  }
364
326
  else {
365
- // was `data: { getPost: null }`)
366
- return handleSingularGraphQlError(error);
327
+ return { data: null, extensions };
367
328
  }
368
329
  }
369
- else {
370
- // `data` is `null`:
371
- return handleSingularGraphQlError(error);
330
+ catch (error) {
331
+ /**
332
+ * The `data` type returned by `error` here could be:
333
+ * 1) `null`
334
+ * 2) an empty object
335
+ * 3) "populated" but with a `null` value `{ getPost: null }`
336
+ * 4) an actual record `{ getPost: { id: '1', title: 'Hello, World!' } }`
337
+ */
338
+ const { data, errors } = error;
339
+ /**
340
+ * `data` is not `null`, and is not an empty object:
341
+ */
342
+ if (data && Object.keys(data).length !== 0 && errors) {
343
+ const [key] = Object.keys(data);
344
+ const isArrayResult = Array.isArray(data[key]);
345
+ // TODO: when adding support for custom selection set, flattening will need
346
+ // to occur recursively. For now, it's expected that related models are not
347
+ // present in the result. Only FK's are present. Any related model properties
348
+ // should be replaced with lazy loaders under the current implementation.
349
+ const flattenedResult = isArrayResult
350
+ ? data[key].filter((x) => x)
351
+ : data[key];
352
+ /**
353
+ * `flattenedResult` could be `null` here (e.g. `data: { getPost: null }`)
354
+ * if `flattenedResult`, result is an actual record:
355
+ */
356
+ if (flattenedResult) {
357
+ // TODO: custom selection set. current selection set is default selection set only
358
+ // custom selection set requires data-schema-type + runtime updates above.
359
+ const initialized = returnTypeModelName
360
+ ? initializeModel(client, returnTypeModelName, isArrayResult ? flattenedResult : [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context)
361
+ : flattenedResult;
362
+ return {
363
+ data: !isArrayResult && Array.isArray(initialized)
364
+ ? initialized.shift()
365
+ : initialized,
366
+ errors,
367
+ };
368
+ }
369
+ else {
370
+ // was `data: { getPost: null }`)
371
+ return handleSingularGraphQlError(error);
372
+ }
373
+ }
374
+ else {
375
+ // `data` is `null`:
376
+ return handleSingularGraphQlError(error);
377
+ }
372
378
  }
373
- }
379
+ });
374
380
  }
375
381
  /**
376
382
  * Executes an operation from the given model intro schema against a client, returning
@@ -1 +1 @@
1
- {"version":3,"file":"custom.mjs","sources":["../../../../../src/runtime/internals/operations/custom.ts"],"sourcesContent":["import { map } from 'rxjs';\nimport { authModeParams, getDefaultSelectionSetForNonModelWithIR, generateSelectionSet, getCustomHeaders, initializeModel, selectionSetIRToString, } from '../APIClient';\nimport { handleSingularGraphQlError } from './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 */\nexport function 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}\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 * @param argDef A single argument definition from a custom operation\n * @returns A string naming the base type including the `!` if the arg is required.\n */\nfunction argumentBaseTypeString(argDef) {\n const requiredFlag = argDef.isRequired ? '!' : '';\n if (argDef.type instanceof Object && 'enum' in argDef.type) {\n return argDef.type.enum + requiredFlag;\n }\n else {\n return argDef.type + requiredFlag;\n }\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 = argumentBaseTypeString(v);\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 doesn'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 `{${selectionSetIRToString(getDefaultSelectionSetForNonModelWithIR(nonModel, modelIntrospection))}}`;\n }\n else if (hasStringField(operation.type, 'model')) {\n return `{${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 = authModeParams(client, getInternals, options);\n const headers = 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 isArrayResult = Array.isArray(data[key]);\n // TODO: when adding support for custom selection set, flattening will need\n // to occur recursively. For now, it's expected that related models are not\n // present in the result. Only FK's are present. Any related model properties\n // should be replaced with lazy loaders under the current implementation.\n const flattenedResult = isArrayResult\n ? data[key].filter((x) => x)\n : 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 ? initializeModel(client, returnTypeModelName, isArrayResult ? flattenedResult : [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context)\n : flattenedResult;\n return {\n data: !isArrayResult && Array.isArray(initialized)\n ? initialized.shift()\n : initialized,\n 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 isArrayResult = Array.isArray(data[key]);\n // TODO: when adding support for custom selection set, flattening will need\n // to occur recursively. For now, it's expected that related models are not\n // present in the result. Only FK's are present. Any related model properties\n // should be replaced with lazy loaders under the current implementation.\n const flattenedResult = isArrayResult\n ? data[key].filter((x) => x)\n : 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 ? initializeModel(client, returnTypeModelName, isArrayResult ? flattenedResult : [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context)\n : flattenedResult;\n return {\n data: !isArrayResult && Array.isArray(initialized)\n ? initialized.shift()\n : initialized,\n 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/**\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 = authModeParams(client, getInternals, options);\n const headers = 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(map((value) => {\n const [key] = Object.keys(value.data);\n const data = value.data[key];\n const [initialized] = returnTypeModelName\n ? initializeModel(client, returnTypeModelName, [data], modelIntrospection, auth.authMode, auth.authToken)\n : [data];\n return initialized;\n }));\n}\n"],"names":[],"mappings":";;;;AAGA;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;AACO,SAAS,eAAe,CAAC,MAAM,EAAE,kBAAkB,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE;AAChH;AACA;AACA,IAAI,MAAM,WAAW,GAAG,SAAS,CAAC,SAAS,KAAK,SAAS,CAAC;AAC1D,IAAI,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,KAAK;AAC5B;AACA,QAAQ,MAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC9C,QAAQ,IAAI,WAAW,CAAC;AACxB,QAAQ,IAAI,GAAG,CAAC;AAChB,QAAQ,IAAI,UAAU,EAAE;AACxB,YAAY,IAAI,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE;AAC3C,gBAAgB,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;AACtC,aAAa;AACb,iBAAiB;AACjB,gBAAgB,MAAM,IAAI,KAAK,CAAC,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rH,cAAc,CAAC,IAAI,CAAC,CAAC;AACrB,QAAQ,OAAO,WAAW,CAAC;AAC3B,KAAK,CAAC,CAAC,CAAC;AACR;;;;"}
1
+ {"version":3,"file":"custom.mjs","sources":["../../../../../src/runtime/internals/operations/custom.ts"],"sourcesContent":["import { map } from 'rxjs';\nimport { authModeParams, getDefaultSelectionSetForNonModelWithIR, generateSelectionSet, getCustomHeaders, initializeModel, selectionSetIRToString, } from '../APIClient';\nimport { handleSingularGraphQlError } from './utils';\nimport { selfAwareAsync } from '../../utils';\nimport { extendCancellability } from '../cancellation';\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 */\nexport function 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}\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 * @param argDef A single argument definition from a custom operation\n * @returns A string naming the base type including the `!` if the arg is required.\n */\nfunction argumentBaseTypeString(argDef) {\n const requiredFlag = argDef.isRequired ? '!' : '';\n if (argDef.type instanceof Object && 'enum' in argDef.type) {\n return argDef.type.enum + requiredFlag;\n }\n else {\n return argDef.type + requiredFlag;\n }\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 = argumentBaseTypeString(v);\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 doesn'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 `{${selectionSetIRToString(getDefaultSelectionSetForNonModelWithIR(nonModel, modelIntrospection))}}`;\n }\n else if (hasStringField(operation.type, 'model')) {\n return `{${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 */\nfunction _op(client, modelIntrospection, operationType, operation, getInternals, args, options, context) {\n return selfAwareAsync(async (resultPromise) => {\n const { name: operationName } = operation;\n const auth = authModeParams(client, getInternals, options);\n const headers = 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 basePromise = context\n ? client.graphql(context, {\n ...auth,\n query,\n variables,\n }, headers)\n : client.graphql({\n ...auth,\n query,\n variables,\n }, headers);\n const extendedPromise = extendCancellability(basePromise, resultPromise);\n const { data, extensions } = await extendedPromise;\n // flatten response\n if (data) {\n const [key] = Object.keys(data);\n const isArrayResult = Array.isArray(data[key]);\n // TODO: when adding support for custom selection set, flattening will need\n // to occur recursively. For now, it's expected that related models are not\n // present in the result. Only FK's are present. Any related model properties\n // should be replaced with lazy loaders under the current implementation.\n const flattenedResult = isArrayResult\n ? data[key].filter((x) => x)\n : 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 ? initializeModel(client, returnTypeModelName, isArrayResult ? flattenedResult : [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context)\n : flattenedResult;\n return {\n data: !isArrayResult && Array.isArray(initialized)\n ? initialized.shift()\n : initialized,\n 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 isArrayResult = Array.isArray(data[key]);\n // TODO: when adding support for custom selection set, flattening will need\n // to occur recursively. For now, it's expected that related models are not\n // present in the result. Only FK's are present. Any related model properties\n // should be replaced with lazy loaders under the current implementation.\n const flattenedResult = isArrayResult\n ? data[key].filter((x) => x)\n : 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 ? initializeModel(client, returnTypeModelName, isArrayResult ? flattenedResult : [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context)\n : flattenedResult;\n return {\n data: !isArrayResult && Array.isArray(initialized)\n ? initialized.shift()\n : initialized,\n 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}\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 = authModeParams(client, getInternals, options);\n const headers = 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(map((value) => {\n const [key] = Object.keys(value.data);\n const data = value.data[key];\n const [initialized] = returnTypeModelName\n ? initializeModel(client, returnTypeModelName, [data], modelIntrospection, auth.authMode, auth.authToken)\n : [data];\n return initialized;\n }));\n}\n"],"names":[],"mappings":";;;;;;AAKA;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;AACO,SAAS,eAAe,CAAC,MAAM,EAAE,kBAAkB,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE;AAChH;AACA;AACA,IAAI,MAAM,WAAW,GAAG,SAAS,CAAC,SAAS,KAAK,SAAS,CAAC;AAC1D,IAAI,MAAM,EAAE,GAAG,CAAC,GAAG,IAAI,KA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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,GAAG,CAAC,CAAC,KAAK,KAAK;AAC1C,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,eAAe,CAAC,MAAM,EAAE,mBAAmB,EAAE,CAAC,IAAI,CAAC,EAAE,kBAAkB,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC;AACrH,cAAc,CAAC,IAAI,CAAC,CAAC;AACrB,QAAQ,OAAO,WAAW,CAAC;AAC3B,KAAK,CAAC,CAAC,CAAC;AACR;;;;"}
@@ -1,3 +1,3 @@
1
1
  import { AmplifyServer, BaseClient, ClientInternalsGetter, GraphQLOptions, ModelIntrospectionSchema, SchemaModel } from '../../bridge-types';
2
2
  import { ModelOperation } from '../APIClient';
3
- export declare function getFactory(client: BaseClient, modelIntrospection: ModelIntrospectionSchema, model: SchemaModel, operation: ModelOperation, getInternals: ClientInternalsGetter, useContext?: boolean): (contextSpec: AmplifyServer.ContextSpec & GraphQLOptions, arg?: any, options?: any) => Promise<any>;
3
+ export declare function getFactory(client: BaseClient, modelIntrospection: ModelIntrospectionSchema, model: SchemaModel, operation: ModelOperation, getInternals: ClientInternalsGetter, useContext?: boolean): (contextSpec: AmplifyServer.ContextSpec & GraphQLOptions, arg?: any, options?: any) => Promise<unknown>;
@@ -1,92 +1,98 @@
1
1
  import { generateGraphQLDocument, buildGraphQLVariables, authModeParams, getCustomHeaders, flattenItems, initializeModel } from '../APIClient.mjs';
2
2
  import { handleSingularGraphQlError } from './utils.mjs';
3
+ import { selfAwareAsync } from '../../utils/selfAwareAsync.mjs';
4
+ import { extendCancellability } from '../cancellation.mjs';
3
5
 
4
6
  function getFactory(client, modelIntrospection, model, operation, getInternals, useContext = false) {
5
- const getWithContext = async (contextSpec, arg, options) => {
7
+ const getWithContext = (contextSpec, arg, options) => {
6
8
  return _get(client, modelIntrospection, model, arg, options, operation, getInternals, contextSpec);
7
9
  };
8
- const get = async (arg, options) => {
10
+ const get = (arg, options) => {
9
11
  return _get(client, modelIntrospection, model, arg, options, operation, getInternals);
10
12
  };
11
13
  return useContext ? getWithContext : get;
12
14
  }
13
- async function _get(client, modelIntrospection, model, arg, options, operation, getInternals, context) {
14
- const { name } = model;
15
- const query = generateGraphQLDocument(modelIntrospection, name, operation, options);
16
- const variables = buildGraphQLVariables(model, operation, arg, modelIntrospection);
17
- const auth = authModeParams(client, getInternals, options);
18
- try {
19
- const headers = getCustomHeaders(client, getInternals, options?.headers);
20
- const { data, extensions } = context
21
- ? (await client.graphql(context, {
22
- ...auth,
23
- query,
24
- variables,
25
- }, headers))
26
- : (await client.graphql({
27
- ...auth,
28
- query,
29
- variables,
30
- }, headers));
31
- // flatten response
32
- if (data) {
33
- const [key] = Object.keys(data);
34
- const flattenedResult = flattenItems(modelIntrospection, name, data[key]);
35
- if (flattenedResult === null) {
36
- return { data: null, extensions };
37
- }
38
- else if (options?.selectionSet) {
39
- return { data: flattenedResult, extensions };
15
+ function _get(client, modelIntrospection, model, arg, options, operation, getInternals, context) {
16
+ return selfAwareAsync(async (resultPromise) => {
17
+ const { name } = model;
18
+ const query = generateGraphQLDocument(modelIntrospection, name, operation, options);
19
+ const variables = buildGraphQLVariables(model, operation, arg, modelIntrospection);
20
+ const auth = authModeParams(client, getInternals, options);
21
+ try {
22
+ const headers = getCustomHeaders(client, getInternals, options?.headers);
23
+ const basePromise = context
24
+ ? client.graphql(context, {
25
+ ...auth,
26
+ query,
27
+ variables,
28
+ }, headers)
29
+ : client.graphql({
30
+ ...auth,
31
+ query,
32
+ variables,
33
+ }, headers);
34
+ const extendedPromise = extendCancellability(basePromise, resultPromise);
35
+ const { data, extensions } = await extendedPromise;
36
+ // flatten response
37
+ if (data) {
38
+ const [key] = Object.keys(data);
39
+ const flattenedResult = flattenItems(modelIntrospection, name, data[key]);
40
+ if (flattenedResult === null) {
41
+ return { data: null, extensions };
42
+ }
43
+ else if (options?.selectionSet) {
44
+ return { data: flattenedResult, extensions };
45
+ }
46
+ else {
47
+ // TODO: refactor to avoid destructuring here
48
+ const [initialized] = initializeModel(client, name, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context);
49
+ return { data: initialized, extensions };
50
+ }
40
51
  }
41
52
  else {
42
- // TODO: refactor to avoid destructuring here
43
- const [initialized] = initializeModel(client, name, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context);
44
- return { data: initialized, extensions };
53
+ return { data: null, extensions };
45
54
  }
46
55
  }
47
- else {
48
- return { data: null, extensions };
49
- }
50
- }
51
- catch (error) {
52
- /**
53
- * The `data` type returned by `error` here could be:
54
- * 1) `null`
55
- * 2) an empty object
56
- * 3) "populated" but with a `null` value `{ getPost: null }`
57
- * 4) an actual record `{ getPost: { id: '1', title: 'Hello, World!' } }`
58
- */
59
- const { data, errors } = error;
60
- /**
61
- * `data` is not `null`, and is not an empty object:
62
- */
63
- if (data && Object.keys(data).length !== 0 && errors) {
64
- const [key] = Object.keys(data);
65
- const flattenedResult = flattenItems(modelIntrospection, name, data[key]);
56
+ catch (error) {
57
+ /**
58
+ * The `data` type returned by `error` here could be:
59
+ * 1) `null`
60
+ * 2) an empty object
61
+ * 3) "populated" but with a `null` value `{ getPost: null }`
62
+ * 4) an actual record `{ getPost: { id: '1', title: 'Hello, World!' } }`
63
+ */
64
+ const { data, errors } = error;
66
65
  /**
67
- * `flattenedResult` could be `null` here (e.g. `data: { getPost: null }`)
68
- * if `flattenedResult`, result is an actual record:
66
+ * `data` is not `null`, and is not an empty object:
69
67
  */
70
- if (flattenedResult) {
71
- if (options?.selectionSet) {
72
- return { data: flattenedResult, errors };
68
+ if (data && Object.keys(data).length !== 0 && errors) {
69
+ const [key] = Object.keys(data);
70
+ const flattenedResult = flattenItems(modelIntrospection, name, data[key]);
71
+ /**
72
+ * `flattenedResult` could be `null` here (e.g. `data: { getPost: null }`)
73
+ * if `flattenedResult`, result is an actual record:
74
+ */
75
+ if (flattenedResult) {
76
+ if (options?.selectionSet) {
77
+ return { data: flattenedResult, errors };
78
+ }
79
+ else {
80
+ // TODO: refactor to avoid destructuring here
81
+ const [initialized] = initializeModel(client, name, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context);
82
+ return { data: initialized, errors };
83
+ }
73
84
  }
74
85
  else {
75
- // TODO: refactor to avoid destructuring here
76
- const [initialized] = initializeModel(client, name, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context);
77
- return { data: initialized, errors };
86
+ // was `data: { getPost: null }`)
87
+ return handleSingularGraphQlError(error);
78
88
  }
79
89
  }
80
90
  else {
81
- // was `data: { getPost: null }`)
91
+ // `data` is `null`:
82
92
  return handleSingularGraphQlError(error);
83
93
  }
84
94
  }
85
- else {
86
- // `data` is `null`:
87
- return handleSingularGraphQlError(error);
88
- }
89
- }
95
+ });
90
96
  }
91
97
 
92
98
  export { getFactory };
@@ -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';\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(modelIntrospection, name, data[key]);\n if (flattenedResult === null) {\n return { data: null, extensions };\n }\n else if (options?.selectionSet) {\n return { data: flattenedResult, extensions };\n }\n else {\n // TODO: refactor to avoid destructuring here\n const [initialized] = 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(modelIntrospection, name, data[key]);\n /**\n * `flattenedResult` could be `null` here (e.g. `data: { getPost: null }`)\n * if `flattenedResult`, result is an actual record:\n */\n if (flattenedResult) {\n if (options?.selectionSet) {\n return { data: flattenedResult, errors };\n }\n else {\n // TODO: refactor to avoid destructuring here\n const [initialized] = 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 handleSingularGraph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AAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAQ,MAAM,EAAE,IAAI,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,YAAY,CAAC,kBAAkB,EAAE,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACtF;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,eAAe,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,eAAe,CAAC,EAAE,kBAAkB,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,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
+ {"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';\nimport { selfAwareAsync } from '../../utils';\nimport { extendCancellability } from '../cancellation';\nexport function getFactory(client, modelIntrospection, model, operation, getInternals, useContext = false) {\n const getWithContext = (contextSpec, arg, options) => {\n return _get(client, modelIntrospection, model, arg, options, operation, getInternals, contextSpec);\n };\n const get = (arg, options) => {\n return _get(client, modelIntrospection, model, arg, options, operation, getInternals);\n };\n return useContext ? getWithContext : get;\n}\nfunction _get(client, modelIntrospection, model, arg, options, operation, getInternals, context) {\n return selfAwareAsync(async (resultPromise) => {\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 basePromise = context\n ? client.graphql(context, {\n ...auth,\n query,\n variables,\n }, headers)\n : client.graphql({\n ...auth,\n query,\n variables,\n }, headers);\n const extendedPromise = extendCancellability(basePromise, resultPromise);\n const { data, extensions } = await extendedPromise;\n // flatten response\n if (data) {\n const [key] = Object.keys(data);\n const flattenedResult = flattenItems(modelIntrospection, name, data[key]);\n if (flattenedResult === null) {\n return { data: null, extensions };\n }\n else if (options?.selectionSet) {\n return { data: flattenedResult, extensions };\n }\n else {\n // TODO: refactor to avoid destructuring here\n const [initialized] = 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(modelIntrospection, name, data[key]);\n /**\n * `flattenedResult` could be `null` here (e.g. `data: { getPost: null }`)\n * if `flattenedResult`, result is an actual record:\n */\n if (flattenedResult) {\n if (options?.selectionSet) {\n return { data: flattenedResult, errors };\n }\n else {\n // TODO: refactor to avoid destructuring here\n const [initialized] = 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}\n"],"names":[],"mappings":";;;;;AAIO,SAAS,UAAU,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,UAAU,GAAG,KAAK,EAAE;AAC3G,IAAI,MAAM,cAAc,GAAG,CAAC,WAAW,EAAE,GAAG,EAAE,OAAO,KAAK;AAC1D,QAAQ,OAAO,IAAI,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,WAAW,CAAC,CAAC;AAC3G,KAAK,CAAC;AACN,IAAI,MAAM,GAAG,GAAG,CAAC,GAAG,EAAE,OAAO,KAAK;AAClC,QAAQ,OAAO,IAAI,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,CAAC,CAAC;AAC9F,KAAK,CAAC;AACN,IAAI,OAAO,UAAU,GAAG,cAAc,GAAG,GAAG,CAAC;AAC7C,CAAC;AACD,SAAS,IAAI,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,OAAO,EAAE;AACjG,IAAI,OAAO,cAAc,CAAC,OAAO,aAAa,KAAK;AACnD,QAAQ,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,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,wBAAwB,MAAM,CAAC,WAAW,CAAC,GAAG,eAAe,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,eAAe,CAAC,EAAE,kBAAkB,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;AAC7J,wBAAwB,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,CAAC;AAC7D,qBAAqB;AACrB,iBAAiB;AACjB,qBAAqB;AACrB;AACA,oBAAoB,OAAO,0BAA0B,CAAC,KAAK,CAAC,CAAC;AAC7D,iBAAiB;AACjB,aAAa;AACb,iBAAiB;AACjB;AACA,gBAAgB,OAAO,0BAA0B,CAAC,KAAK,CAAC,CAAC;AACzD,aAAa;AACb,SAAS;AACT,KAAK,CAAC,CAAC;AACP;;;;"}
@@ -4,4 +4,4 @@ export interface IndexMeta {
4
4
  pk: string;
5
5
  sk?: string[];
6
6
  }
7
- export declare function indexQueryFactory(client: BaseClient, modelIntrospection: ModelIntrospectionSchema, model: SchemaModel, indexMeta: IndexMeta, getInternals: ClientInternalsGetter, context?: boolean): ((contextSpec: AmplifyServer.ContextSpec, args: QueryArgs, options?: ListArgs) => Promise<any>) | ((args: QueryArgs, options?: ListArgs) => Promise<any>);
7
+ export declare function indexQueryFactory(client: BaseClient, modelIntrospection: ModelIntrospectionSchema, model: SchemaModel, indexMeta: IndexMeta, getInternals: ClientInternalsGetter, context?: boolean): ((contextSpec: AmplifyServer.ContextSpec, args: QueryArgs, options?: ListArgs) => Promise<unknown>) | ((args: QueryArgs, options?: ListArgs) => Promise<unknown>);