@aws-amplify/api-graphql 4.0.22 → 4.0.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js +40 -31
- package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -1
- package/dist/cjs/internals/APIClient.js +34 -19
- package/dist/cjs/internals/APIClient.js.map +1 -1
- package/dist/cjs/internals/InternalGraphQLAPI.js +10 -9
- package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -1
- package/dist/cjs/internals/generateClient.js +4 -1
- package/dist/cjs/internals/generateClient.js.map +1 -1
- package/dist/cjs/internals/generateCustomOperationsProperty.js +6 -1
- package/dist/cjs/internals/generateCustomOperationsProperty.js.map +1 -1
- package/dist/cjs/internals/operations/custom.js +90 -7
- package/dist/cjs/internals/operations/custom.js.map +1 -1
- package/dist/cjs/internals/operations/list.js +1 -1
- package/dist/cjs/internals/operations/list.js.map +1 -1
- package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js +1 -1
- package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js.map +1 -1
- package/dist/cjs/internals/server/generateModelsProperty.js +1 -1
- package/dist/cjs/internals/server/generateModelsProperty.js.map +1 -1
- package/dist/cjs/internals/v6.js +0 -2
- package/dist/cjs/internals/v6.js.map +1 -1
- package/dist/cjs/utils/errors/repackageAuthError.js +1 -1
- package/dist/cjs/utils/errors/repackageAuthError.js.map +1 -1
- package/dist/cjs/utils/resolveOwnerFields.js +3 -0
- package/dist/cjs/utils/resolveOwnerFields.js.map +1 -1
- package/dist/esm/GraphQLAPI.d.ts +2 -2
- package/dist/esm/GraphQLAPI.mjs.map +1 -1
- package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.d.ts +8 -8
- package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs +40 -31
- package/dist/esm/Providers/AWSAppSyncRealTimeProvider/index.mjs.map +1 -1
- package/dist/esm/internals/APIClient.d.ts +5 -6
- package/dist/esm/internals/APIClient.mjs +34 -19
- package/dist/esm/internals/APIClient.mjs.map +1 -1
- package/dist/esm/internals/InternalGraphQLAPI.d.ts +1 -1
- package/dist/esm/internals/InternalGraphQLAPI.mjs +10 -9
- package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
- package/dist/esm/internals/generateClient.mjs +5 -2
- package/dist/esm/internals/generateClient.mjs.map +1 -1
- package/dist/esm/internals/generateCustomOperationsProperty.d.ts +4 -3
- package/dist/esm/internals/generateCustomOperationsProperty.mjs +5 -1
- package/dist/esm/internals/generateCustomOperationsProperty.mjs.map +1 -1
- package/dist/esm/internals/operations/custom.d.ts +6 -3
- package/dist/esm/internals/operations/custom.mjs +90 -7
- package/dist/esm/internals/operations/custom.mjs.map +1 -1
- package/dist/esm/internals/operations/get.d.ts +1 -1
- package/dist/esm/internals/operations/get.mjs.map +1 -1
- package/dist/esm/internals/operations/indexQuery.d.ts +3 -3
- package/dist/esm/internals/operations/indexQuery.mjs.map +1 -1
- package/dist/esm/internals/operations/list.d.ts +1 -1
- package/dist/esm/internals/operations/list.mjs +1 -1
- package/dist/esm/internals/operations/list.mjs.map +1 -1
- package/dist/esm/internals/operations/subscription.d.ts +1 -1
- package/dist/esm/internals/operations/subscription.mjs.map +1 -1
- package/dist/esm/internals/server/generateClientWithAmplifyInstance.d.ts +1 -1
- package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs +1 -1
- package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs.map +1 -1
- package/dist/esm/internals/server/generateModelsProperty.d.ts +3 -3
- package/dist/esm/internals/server/generateModelsProperty.mjs +1 -1
- package/dist/esm/internals/server/generateModelsProperty.mjs.map +1 -1
- package/dist/esm/internals/types.d.ts +2 -2
- package/dist/esm/internals/utils/clientProperties/generateModelsProperty.d.ts +2 -2
- package/dist/esm/internals/v6.d.ts +1 -1
- package/dist/esm/internals/v6.mjs +0 -2
- package/dist/esm/internals/v6.mjs.map +1 -1
- package/dist/esm/types/index.d.ts +34 -35
- package/dist/esm/utils/ConnectionStateMonitor.d.ts +2 -2
- package/dist/esm/utils/ConnectionStateMonitor.mjs.map +1 -1
- package/dist/esm/utils/ReachabilityMonitor/index.native.mjs.map +1 -1
- package/dist/esm/utils/errors/repackageAuthError.d.ts +2 -2
- package/dist/esm/utils/errors/repackageAuthError.mjs +1 -1
- package/dist/esm/utils/errors/repackageAuthError.mjs.map +1 -1
- package/dist/esm/utils/findIndexByFields.d.ts +1 -1
- package/dist/esm/utils/resolveOwnerFields.mjs +3 -0
- package/dist/esm/utils/resolveOwnerFields.mjs.map +1 -1
- package/package.json +8 -7
- package/src/GraphQLAPI.ts +4 -3
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +84 -64
- package/src/internals/APIClient.ts +83 -58
- package/src/internals/InternalGraphQLAPI.ts +26 -30
- package/src/internals/clientUtils.ts +1 -1
- package/src/internals/generateClient.ts +23 -10
- package/src/internals/generateCustomOperationsProperty.ts +31 -8
- package/src/internals/operations/custom.ts +159 -32
- package/src/internals/operations/get.ts +9 -8
- package/src/internals/operations/indexQuery.ts +12 -11
- package/src/internals/operations/list.ts +11 -15
- package/src/internals/operations/observeQuery.ts +3 -1
- package/src/internals/operations/subscription.ts +12 -10
- package/src/internals/server/generateClientWithAmplifyInstance.ts +7 -7
- package/src/internals/server/generateModelsProperty.ts +12 -6
- package/src/internals/types.ts +2 -2
- package/src/internals/utils/clientProperties/generateEnumsProperty.ts +7 -6
- package/src/internals/utils/clientProperties/generateModelsProperty.ts +8 -7
- package/src/internals/v6.ts +6 -4
- package/src/server/generateClient.ts +4 -1
- package/src/types/PubSub.ts +1 -0
- package/src/types/index.ts +51 -47
- package/src/utils/ConnectionStateMonitor.ts +8 -3
- package/src/utils/ReachabilityMonitor/index.native.ts +1 -1
- package/src/utils/ReachabilityMonitor/index.ts +1 -0
- package/src/utils/ReconnectionMonitor.ts +1 -0
- package/src/utils/errors/repackageAuthError.ts +6 -7
- package/src/utils/findIndexByFields.ts +1 -1
- package/src/utils/resolveConfig.ts +1 -0
- package/src/utils/resolveLibraryOptions.ts +1 -0
- package/src/utils/resolveOwnerFields.ts +16 -7
- package/src/utils/resolvePKFields.ts +1 -0
|
@@ -1,5 +1,12 @@
|
|
|
1
|
+
import { map } from 'rxjs';
|
|
1
2
|
import { authModeParams, getCustomHeaders, flattenItems, initializeModel, selectionSetIRToString, defaultSelectionSetForNonModelWithIR, generateSelectionSet } from '../APIClient.mjs';
|
|
2
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Type guard for checking whether a Custom Operation argument is a contextSpec object
|
|
6
|
+
*/
|
|
7
|
+
const argIsContextSpec = (arg) => {
|
|
8
|
+
return typeof arg?.token?.value === 'symbol';
|
|
9
|
+
};
|
|
3
10
|
/**
|
|
4
11
|
* Builds an operation function, embedded with all client and context data, that
|
|
5
12
|
* can be attached to a client as a custom query or mutation.
|
|
@@ -57,13 +64,38 @@ import { authModeParams, getCustomHeaders, flattenItems, initializeModel, select
|
|
|
57
64
|
* @returns The operation function to attach to query, mutations, etc.
|
|
58
65
|
*/
|
|
59
66
|
function customOpFactory(client, modelIntrospection, operationType, operation, useContext) {
|
|
60
|
-
|
|
67
|
+
// .arguments() are defined for the custom operation in the schema builder
|
|
68
|
+
// and are present in the model introspection schema
|
|
69
|
+
const argsDefined = operation.arguments !== undefined;
|
|
70
|
+
const op = (...args) => {
|
|
71
|
+
// options is always the last argument
|
|
72
|
+
const options = args[args.length - 1];
|
|
73
|
+
let contextSpec;
|
|
74
|
+
let arg;
|
|
75
|
+
if (useContext) {
|
|
76
|
+
if (argIsContextSpec(args[0])) {
|
|
77
|
+
contextSpec = args[0];
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
throw new Error(`Invalid first argument passed to ${operation.name}. Expected contextSpec`);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
if (argsDefined) {
|
|
84
|
+
if (useContext) {
|
|
85
|
+
arg = args[1];
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
arg = args[0];
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (operationType === 'subscription') {
|
|
92
|
+
return _opSubscription(
|
|
93
|
+
// subscriptions are only enabled on the clientside
|
|
94
|
+
client, modelIntrospection, operation, arg, options);
|
|
95
|
+
}
|
|
61
96
|
return _op(client, modelIntrospection, operationType, operation, arg, options, contextSpec);
|
|
62
97
|
};
|
|
63
|
-
|
|
64
|
-
return _op(client, modelIntrospection, operationType, operation, arg, options);
|
|
65
|
-
};
|
|
66
|
-
return useContext ? opWithContext : op;
|
|
98
|
+
return op;
|
|
67
99
|
}
|
|
68
100
|
/**
|
|
69
101
|
* Runtime test and type guard to check whether `o[field]` is a `String`.
|
|
@@ -102,6 +134,9 @@ function hasStringField(o, field) {
|
|
|
102
134
|
* @returns "outer" arguments string
|
|
103
135
|
*/
|
|
104
136
|
function outerArguments(operation) {
|
|
137
|
+
if (operation.arguments === undefined) {
|
|
138
|
+
return '';
|
|
139
|
+
}
|
|
105
140
|
const args = Object.entries(operation.arguments)
|
|
106
141
|
.map(([k, v]) => {
|
|
107
142
|
const baseType = v.type + (v.isRequired ? '!' : '');
|
|
@@ -133,8 +168,11 @@ function outerArguments(operation) {
|
|
|
133
168
|
* @returns "outer" arguments string
|
|
134
169
|
*/
|
|
135
170
|
function innerArguments(operation) {
|
|
136
|
-
|
|
137
|
-
|
|
171
|
+
if (operation.arguments === undefined) {
|
|
172
|
+
return '';
|
|
173
|
+
}
|
|
174
|
+
const args = Object.keys(operation.arguments)
|
|
175
|
+
.map(k => `${k}: $${k}`)
|
|
138
176
|
.join(', ');
|
|
139
177
|
return args.length > 0 ? `(${args})` : '';
|
|
140
178
|
}
|
|
@@ -187,6 +225,9 @@ function operationSelectionSet(modelIntrospection, operation) {
|
|
|
187
225
|
*/
|
|
188
226
|
function operationVariables(operation, args = {}) {
|
|
189
227
|
const variables = {};
|
|
228
|
+
if (operation.arguments === undefined) {
|
|
229
|
+
return variables;
|
|
230
|
+
}
|
|
190
231
|
for (const argDef of Object.values(operation.arguments)) {
|
|
191
232
|
if (typeof args[argDef.name] !== 'undefined') {
|
|
192
233
|
variables[argDef.name] = args[argDef.name];
|
|
@@ -266,6 +307,48 @@ async function _op(client, modelIntrospection, operationType, operation, args, o
|
|
|
266
307
|
}
|
|
267
308
|
}
|
|
268
309
|
}
|
|
310
|
+
/**
|
|
311
|
+
* Executes an operation from the given model intro schema against a client, returning
|
|
312
|
+
* a fully instantiated model when relevant.
|
|
313
|
+
*
|
|
314
|
+
* @param client The client to operate `graphql()` calls through.
|
|
315
|
+
* @param modelIntrospection The model intro schema to construct requests from.
|
|
316
|
+
* @param operation The specific operation name, args, return type details.
|
|
317
|
+
* @param args The arguments to provide to the operation as variables.
|
|
318
|
+
* @param options Request options like headers, etc.
|
|
319
|
+
* @returns Result from the graphql request, model-instantiated when relevant.
|
|
320
|
+
*/
|
|
321
|
+
function _opSubscription(client, modelIntrospection, operation, args, options) {
|
|
322
|
+
const operationType = 'subscription';
|
|
323
|
+
const { name: operationName } = operation;
|
|
324
|
+
const auth = authModeParams(client, options);
|
|
325
|
+
const headers = getCustomHeaders(client, options?.headers);
|
|
326
|
+
const outerArgsString = outerArguments(operation);
|
|
327
|
+
const innerArgsString = innerArguments(operation);
|
|
328
|
+
const selectionSet = operationSelectionSet(modelIntrospection, operation);
|
|
329
|
+
const returnTypeModelName = hasStringField(operation.type, 'model')
|
|
330
|
+
? operation.type.model
|
|
331
|
+
: undefined;
|
|
332
|
+
const query = `
|
|
333
|
+
${operationType.toLocaleLowerCase()}${outerArgsString} {
|
|
334
|
+
${operationName}${innerArgsString} ${selectionSet}
|
|
335
|
+
}
|
|
336
|
+
`;
|
|
337
|
+
const variables = operationVariables(operation, args);
|
|
338
|
+
const observable = client.graphql({
|
|
339
|
+
...auth,
|
|
340
|
+
query,
|
|
341
|
+
variables,
|
|
342
|
+
}, headers);
|
|
343
|
+
return observable.pipe(map(value => {
|
|
344
|
+
const [key] = Object.keys(value.data);
|
|
345
|
+
const data = value.data[key];
|
|
346
|
+
const [initialized] = returnTypeModelName
|
|
347
|
+
? initializeModel(client, returnTypeModelName, [data], modelIntrospection, auth.authMode, auth.authToken)
|
|
348
|
+
: [data];
|
|
349
|
+
return initialized;
|
|
350
|
+
}));
|
|
351
|
+
}
|
|
269
352
|
|
|
270
353
|
export { customOpFactory };
|
|
271
354
|
//# sourceMappingURL=custom.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"custom.mjs","sources":["../../../../src/internals/operations/custom.ts"],"sourcesContent":["import { initializeModel, flattenItems, authModeParams, getCustomHeaders, generateSelectionSet, selectionSetIRToString, defaultSelectionSetForNonModelWithIR, } from '../APIClient';\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) {\n const opWithContext = async (contextSpec, arg, options) => {\n return _op(client, modelIntrospection, operationType, operation, arg, options, contextSpec);\n };\n const op = async (arg, options) => {\n return _op(client, modelIntrospection, operationType, operation, arg, options);\n };\n return useContext ? opWithContext : 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 * 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 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 const args = Object.entries(operation.arguments)\n .map(([k, v]) => `${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 `{${selectionSetIRToString(defaultSelectionSetForNonModelWithIR(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 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, args, options, context) {\n const { name: operationName } = operation;\n const auth = authModeParams(client, options);\n const headers = getCustomHeaders(client, 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\t\t${operationType.toLocaleLowerCase()}${outerArgsString} {\n\t\t\t${operationName}${innerArgsString} ${selectionSet}\n\t\t}\n\t`;\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 = 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 ? 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"],"names":[],"mappings":";;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;AACO,SAAS,eAAe,CAAC,MAAM,EAAE,kBAAkB,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE;AAClG,IAAI,MAAM,aAAa,GAAG,OAAO,WAAW,EAAE,GAAG,EAAE,OAAO,KAAK;AAC/D,QAAQ,OAAO,GAAG,CAAC,MAAM,EAAE,kBAAkB,EAAE,aAAa,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,WAAW,CAAC,CAAC;AACpG,KAAK,CAAC;AACN,IAAI,MAAM,E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AAI,CAAC,CAAC,GAAG,CAAC,CAAC;AAC5D;AACA;AACA,YAAY,MAAM,CAAC,WAAW,CAAC,GAAG,mBAAmB;AACrD,kBAAkB,eAAe,CAAC,MAAM,EAAE,mBAAmB,EAAE,CAAC,eAAe,CAAC,EAAE,kBAAkB,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,OAAO,CAAC;AAC/I,kBAAkB,CAAC,eAAe,CAAC,CAAC;AACpC,YAAY,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC;AACrD,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":"custom.mjs","sources":["../../../../src/internals/operations/custom.ts"],"sourcesContent":["import { map } from 'rxjs';\nimport { authModeParams, defaultSelectionSetForNonModelWithIR, flattenItems, generateSelectionSet, getCustomHeaders, initializeModel, selectionSetIRToString, } from '../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 */\nexport function customOpFactory(client, modelIntrospection, operationType, operation, useContext) {\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, arg, options);\n }\n return _op(client, modelIntrospection, operationType, operation, 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 * 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 `{${selectionSetIRToString(defaultSelectionSetForNonModelWithIR(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, args, options, context) {\n const { name: operationName } = operation;\n const auth = authModeParams(client, options);\n const headers = getCustomHeaders(client, 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\t\t${operationType.toLocaleLowerCase()}${outerArgsString} {\n\t\t\t${operationName}${innerArgsString} ${selectionSet}\n\t\t}\n\t`;\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 = 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 ? 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, args, options) {\n const operationType = 'subscription';\n const { name: operationName } = operation;\n const auth = authModeParams(client, options);\n const headers = getCustomHeaders(client, 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\t\t${operationType.toLocaleLowerCase()}${outerArgsString} {\n\t\t\t${operationName}${innerArgsString} ${selectionSet}\n\t\t}\n\t`;\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":";;;AAEA;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;AAC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AAmB,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,5 +1,5 @@
|
|
|
1
1
|
import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
|
|
2
|
+
import { ModelIntrospectionSchema, SchemaModel } from '@aws-amplify/core/internals/utils';
|
|
2
3
|
import { ModelOperation } from '../APIClient';
|
|
3
4
|
import { ClientWithModels, GraphQLOptionsV6 } from '../../types';
|
|
4
|
-
import { ModelIntrospectionSchema, SchemaModel } from '@aws-amplify/core/internals/utils';
|
|
5
5
|
export declare function getFactory(client: ClientWithModels, modelIntrospection: ModelIntrospectionSchema, model: SchemaModel, operation: ModelOperation, useContext?: boolean): (contextSpec: AmplifyServer.ContextSpec & GraphQLOptionsV6<unknown, string>, arg?: any, options?: any) => Promise<any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get.mjs","sources":["../../../../src/internals/operations/get.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"get.mjs","sources":["../../../../src/internals/operations/get.ts"],"sourcesContent":["import { authModeParams, buildGraphQLVariables, flattenItems, generateGraphQLDocument, getCustomHeaders, initializeModel, } from '../APIClient';\nexport function getFactory(client, modelIntrospection, model, operation, useContext = false) {\n const getWithContext = async (contextSpec, arg, options) => {\n return _get(client, modelIntrospection, model, arg, options, operation, contextSpec);\n };\n const get = async (arg, options) => {\n return _get(client, modelIntrospection, model, arg, options, operation);\n };\n return useContext ? getWithContext : get;\n}\nasync function _get(client, modelIntrospection, model, arg, options, operation, context) {\n const { name } = model;\n const query = generateGraphQLDocument(modelIntrospection, name, operation, options);\n const variables = buildGraphQLVariables(model, operation, arg, modelIntrospection);\n try {\n const auth = authModeParams(client, options);\n const headers = getCustomHeaders(client, options?.headers);\n const { data, extensions } = context\n ? (await client.graphql(context, {\n ...auth,\n query,\n variables,\n }, headers))\n : (await client.graphql({\n ...auth,\n query,\n variables,\n }, headers));\n // flatten response\n if (data) {\n const [key] = Object.keys(data);\n const flattenedResult = flattenItems(data)[key];\n if (options?.selectionSet) {\n return { data: flattenedResult, extensions };\n }\n else {\n // TODO: refactor to avoid destructuring here\n const [initialized] = initializeModel(client, name, [flattenedResult], modelIntrospection, auth.authMode, auth.authToken, !!context);\n return { data: initialized, extensions };\n }\n }\n else {\n return { data: null, extensions };\n }\n }\n catch (error) {\n if (error.errors) {\n // graphql errors pass through\n return error;\n }\n else {\n // non-graphql errors re re-thrown\n throw error;\n }\n }\n}\n"],"names":[],"mappings":";;AACO,SAAS,UAAU,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,GAAG,KAAK,EAAE;AAC7F,IAAI,MAAM,cAAc,GAAG,OAAO,WAAW,EAAE,GAAG,EAAE,OAAO,KAAK;AAChE,QAAQ,OAAO,IAAI,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,CAAC,CAAC;AAC7F,KAAK,CAAC;AACN,IAAI,MAAM,GAAG,GAAG,OAAO,GAAG,EAAE,OAAO,KAAK;AACxC,QAAQ,OAAO,IAAI,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC;AAChF,KAAK,CAAC;AACN,IAAI,OAAO,UAAU,GAAG,cAAc,GAAG,GAAG,CAAC;AAC7C,CAAC;AACD,eAAe,IAAI,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE;AACzF,IAAI,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;AAC3B,IAAI,MAAM,KAAK,G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,CAAC,CAAC,OAAO,CAAC,CAAC;AACrJ,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,9 +1,9 @@
|
|
|
1
1
|
import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
|
|
2
|
-
import { ClientWithModels, ListArgs, QueryArgs } from '../../types';
|
|
3
2
|
import { ModelIntrospectionSchema, SchemaModel } from '@aws-amplify/core/internals/utils';
|
|
4
|
-
|
|
3
|
+
import { ClientWithModels, ListArgs, QueryArgs } from '../../types';
|
|
4
|
+
export interface IndexMeta {
|
|
5
5
|
queryField: string;
|
|
6
6
|
pk: string;
|
|
7
7
|
sk?: string[];
|
|
8
|
-
}
|
|
8
|
+
}
|
|
9
9
|
export declare function indexQueryFactory(client: ClientWithModels, modelIntrospection: ModelIntrospectionSchema, model: SchemaModel, indexMeta: IndexMeta, context?: boolean): ((contextSpec: AmplifyServer.ContextSpec, args: QueryArgs, options?: ListArgs) => Promise<any>) | ((args: QueryArgs, options?: ListArgs) => Promise<any>);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indexQuery.mjs","sources":["../../../../src/internals/operations/indexQuery.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"indexQuery.mjs","sources":["../../../../src/internals/operations/indexQuery.ts"],"sourcesContent":["import { authModeParams, buildGraphQLVariables, flattenItems, generateGraphQLDocument, getCustomHeaders, initializeModel, } from '../APIClient';\nexport function indexQueryFactory(client, modelIntrospection, model, indexMeta, context = false) {\n const indexQueryWithContext = async (contextSpec, args, options) => {\n return _indexQuery(client, modelIntrospection, model, indexMeta, {\n ...args,\n ...options,\n }, contextSpec);\n };\n const indexQuery = async (args, options) => {\n return _indexQuery(client, modelIntrospection, model, indexMeta, {\n ...args,\n ...options,\n });\n };\n return context ? indexQueryWithContext : indexQuery;\n}\nfunction processGraphQlResponse(result, selectionSet, modelInitializer) {\n const { data, extensions } = result;\n const [key] = Object.keys(data);\n if (data[key].items) {\n const flattenedResult = flattenItems(data)[key];\n return {\n data: selectionSet ? flattenedResult : modelInitializer(flattenedResult),\n nextToken: data[key].nextToken,\n extensions,\n };\n }\n return {\n data: data[key],\n nextToken: data[key].nextToken,\n extensions,\n };\n}\nfunction handleGraphQlError(error) {\n if (error.errors) {\n // graphql errors pass through\n return error;\n }\n else {\n // non-graphql errors re re-thrown\n throw error;\n }\n}\nasync function _indexQuery(client, modelIntrospection, model, indexMeta, args, contextSpec) {\n const { name } = model;\n const query = generateGraphQLDocument(modelIntrospection, name, 'INDEX_QUERY', args, indexMeta);\n const variables = buildGraphQLVariables(model, 'INDEX_QUERY', args, modelIntrospection, indexMeta);\n const auth = authModeParams(client, args);\n const modelInitializer = (flattenedResult) => initializeModel(client, name, flattenedResult, modelIntrospection, auth.authMode, auth.authToken, !!contextSpec);\n try {\n const headers = getCustomHeaders(client, args?.headers);\n const graphQlParams = {\n ...auth,\n query,\n variables,\n };\n const requestArgs = [graphQlParams, headers];\n if (contextSpec !== undefined) {\n requestArgs.unshift(contextSpec);\n }\n const response = (await client.graphql(...requestArgs));\n if (response.data !== undefined) {\n return processGraphQlResponse(response, args?.selectionSet, modelInitializer);\n }\n }\n catch (error) {\n return handleGraphQlError(error);\n }\n}\n"],"names":[],"mappings":";;AACO,SAAS,iBAAiB,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,GAAG,KAAK,EAAE;AACjG,IA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AC,OAAO,CAAC,WAAW,CAAC,CAAC;AAC7C,SAAS;AACT,QAAQ,MAAM,QAAQ,IAAI,MAAM,MAAM,CAAC,OAAO,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC;AAChE,QAAQ,IAAI,QAAQ,CAAC,IAAI,KAAK,SAAS,EAAE;AACzC,YAAY,OAAO,sBAAsB,CAAC,QAAQ,EAAE,IAAI,EAAE,YAAY,EAAE,gBAAgB,CAAC,CAAC;AAC1F,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC;AACzC,KAAK;AACL;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
|
|
2
|
-
import { ClientWithModels, ListArgs } from '../../types';
|
|
3
2
|
import { ModelIntrospectionSchema, SchemaModel } from '@aws-amplify/core/internals/utils';
|
|
3
|
+
import { ClientWithModels, ListArgs } from '../../types';
|
|
4
4
|
export declare function listFactory(client: ClientWithModels, modelIntrospection: ModelIntrospectionSchema, model: SchemaModel, context?: boolean): (contextSpec: AmplifyServer.ContextSpec, args?: ListArgs) => Promise<any>;
|
|
@@ -16,7 +16,7 @@ async function _list(client, modelIntrospection, model, args, contextSpec) {
|
|
|
16
16
|
try {
|
|
17
17
|
const auth = authModeParams(client, args);
|
|
18
18
|
const headers = getCustomHeaders(client, args?.headers);
|
|
19
|
-
const { data, extensions } =
|
|
19
|
+
const { data, extensions } = contextSpec
|
|
20
20
|
? (await client.graphql(contextSpec, {
|
|
21
21
|
...auth,
|
|
22
22
|
query,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.mjs","sources":["../../../../src/internals/operations/list.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"list.mjs","sources":["../../../../src/internals/operations/list.ts"],"sourcesContent":["import { authModeParams, buildGraphQLVariables, flattenItems, generateGraphQLDocument, getCustomHeaders, initializeModel, } from '../APIClient';\nexport function listFactory(client, modelIntrospection, model, context = false) {\n const listWithContext = async (contextSpec, args) => {\n return _list(client, modelIntrospection, model, args, contextSpec);\n };\n const list = async (args) => {\n return _list(client, modelIntrospection, model, args);\n };\n return context ? listWithContext : list;\n}\nasync function _list(client, modelIntrospection, model, args, contextSpec) {\n const { name } = model;\n const query = generateGraphQLDocument(modelIntrospection, name, 'LIST', args);\n const variables = buildGraphQLVariables(model, 'LIST', args, modelIntrospection);\n try {\n const auth = authModeParams(client, args);\n const headers = getCustomHeaders(client, args?.headers);\n const { data, extensions } = contextSpec\n ? (await client.graphql(contextSpec, {\n ...auth,\n query,\n variables,\n }, headers))\n : (await client.graphql({\n ...auth,\n query,\n variables,\n }, headers));\n // flatten response\n if (data !== undefined) {\n const [key] = Object.keys(data);\n if (data[key].items) {\n const flattenedResult = flattenItems(data)[key];\n // don't init if custom selection set\n if (args?.selectionSet) {\n return {\n data: flattenedResult,\n nextToken: data[key].nextToken,\n extensions,\n };\n }\n else {\n const initialized = initializeModel(client, name, flattenedResult, modelIntrospection, auth.authMode, auth.authToken, !!contextSpec);\n return {\n data: initialized,\n nextToken: data[key].nextToken,\n extensions,\n };\n }\n }\n return {\n data: data[key],\n nextToken: data[key].nextToken,\n extensions,\n };\n }\n }\n catch (error) {\n if (error.errors) {\n // graphql errors pass through\n return error;\n }\n else {\n // non-graphql errors re re-thrown\n throw error;\n }\n }\n}\n"],"names":[],"mappings":";;AACO,SAAS,WAAW,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,OAAO,GAAG,KAAK,EAAE;AAChF,IAAI,MAAM,eAAe,GAAG,OAAO,WAAW,EAAE,IAAI,KAAK;AACzD,QAAQ,OAAO,KAAK,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC;AAC3E,KAAK,CAAC;AACN,IAAI,MAAM,IAAI,GAAG,OAAO,IAAI,KAAK;AACjC,QA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,KAAK,EAAE;AACjC,gBAAgB,MAAM,eAAe,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC;AAChE;AACA,gBAAgB,IAAI,IAAI,EAAE,YAAY,EAAE;AACxC,oBAAoB,OAAO;AAC3B,wBAAwB,IAAI,EAAE,eAAe;AAC7C,wBAAwB,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS;AACtD,wBAAwB,UAAU;AAClC,qBAAqB,CAAC;AACtB,iBAAiB;AACjB,qBAAqB;AACrB,oBAAoB,MAAM,WAAW,GAAG,eAAe,CAAC,MAAM,EAAE,IAAI,EAAE,eAAe,EAAE,kBAAkB,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,WAAW,CAAC,CAAC;AACzJ,oBAAoB,OAAO;AAC3B,wBAAwB,IAAI,EAAE,WAAW;AACzC,wBAAwB,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS;AACtD,wBAAwB,UAAU;AAClC,qBAAqB,CAAC;AACtB,iBAAiB;AACjB,aAAa;AACb,YAAY,OAAO;AACnB,gBAAgB,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC;AAC/B,gBAAgB,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,SAAS;AAC9C,gBAAgB,UAAU;AAC1B,aAAa,CAAC;AACd,SAAS;AACT,KAAK;AACL,IAAI,OAAO,KAAK,EAAE;AAClB,QAAQ,IAAI,KAAK,CAAC,MAAM,EAAE;AAC1B;AACA,YAAY,OAAO,KAAK,CAAC;AACzB,SAAS;AACT,aAAa;AACb;AACA,YAAY,MAAM,KAAK,CAAC;AACxB,SAAS;AACT,KAAK;AACL;;;;"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { ModelOperation } from '../APIClient';
|
|
2
1
|
import { ModelIntrospectionSchema, SchemaModel } from '@aws-amplify/core/internals/utils';
|
|
2
|
+
import { ModelOperation } from '../APIClient';
|
|
3
3
|
export declare function subscriptionFactory(client: any, modelIntrospection: ModelIntrospectionSchema, model: SchemaModel, operation: ModelOperation): (args?: any) => import("rxjs").Observable<any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscription.mjs","sources":["../../../../src/internals/operations/subscription.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { map } from 'rxjs';\nimport {
|
|
1
|
+
{"version":3,"file":"subscription.mjs","sources":["../../../../src/internals/operations/subscription.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { map } from 'rxjs';\nimport { authModeParams, buildGraphQLVariables, generateGraphQLDocument, getCustomHeaders, initializeModel, } from '../APIClient';\nexport function subscriptionFactory(client, modelIntrospection, model, operation) {\n const { name } = model;\n const subscription = (args) => {\n const query = generateGraphQLDocument(modelIntrospection, name, operation, args);\n const variables = buildGraphQLVariables(model, operation, args, modelIntrospection);\n const auth = authModeParams(client, args);\n const headers = getCustomHeaders(client, args?.headers);\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] = initializeModel(client, name, [data], modelIntrospection, auth.authMode, auth.authToken);\n return initialized;\n }));\n };\n return subscription;\n}\n"],"names":[],"mappings":";;;AAAA;AACA;AAGO,SAAS,mBAAmB,CAAC,MAAM,EAAE,kBAAkB,EAAE,KAAK,EAAE,SAAS,EAAE;AAClF,IAAI,MAAM,EAAE,IAAI,EAAE,GAAG,KAAK,CAAC;AAC3B,IAAI,MAAM,YAAY,GAAG,CAAC,IAAI,KAAK;AACnC,QAAQ,MAAM,KAAK,GAAG,uBAAuB,CAAC,kBAAkB,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;AACzF,QAAQ,MAAM,SAAS,GAAG,qBAAqB,CAAC,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,kBAAkB,CAAC,CAAC;AAC5F,QAAQ,MAAM,IAAI,GAAG,cAAc,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;AAClD,QAAQ,MAAM,OAAO,GAAG,gBAAgB,CAAC,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;AAChE,QAAQ,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC;AAC1C,YAAY,GAAG,IAAI;AACnB,YAAY,KAAK;AACjB,YAAY,SAAS;AACrB,SAAS,EAAE,OAAO,CAAC,CAAC;AACpB,QAAQ,OAAO,UAAU,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,IAAI;AAC5C,YAAY,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AAClD,YAAY,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACzC,YAAY,MAAM,CAAC,WAAW,CAAC,GAAG,eAAe,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,IAAI,CAAC,EAAE,kBAAkB,EAAE,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;AAC3H,YAAY,OAAO,WAAW,CAAC;AAC/B,SAAS,CAAC,CAAC,CAAC;AACZ,KAAK,CAAC;AACN,IAAI,OAAO,YAAY,CAAC;AACxB;;;;"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CommonPublicClientOptions, ServerClientGenerationParams, V6ClientSSRCookies, V6ClientSSRRequest } from '../../types';
|
|
2
2
|
/**
|
|
3
3
|
* @private
|
|
4
4
|
*
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import '../InternalGraphQLAPI.mjs';
|
|
2
2
|
import { graphql, cancel, isCancelError } from '../v6.mjs';
|
|
3
3
|
import '../generateClient.mjs';
|
|
4
|
-
import { generateModelsProperty } from './generateModelsProperty.mjs';
|
|
5
4
|
import { __amplify, __authMode, __authToken, __headers } from '../../types/index.mjs';
|
|
6
5
|
import { isApiGraphQLConfig } from '../utils/runtimeTypeGuards/isApiGraphQLProviderConfig.mjs';
|
|
7
6
|
import { generateEnumsProperty } from '../utils/clientProperties/generateEnumsProperty.mjs';
|
|
8
7
|
import { generateCustomQueriesProperty, generateCustomMutationsProperty } from '../generateCustomOperationsProperty.mjs';
|
|
8
|
+
import { generateModelsProperty } from './generateModelsProperty.mjs';
|
|
9
9
|
|
|
10
10
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
11
11
|
// SPDX-License-Identifier: Apache-2.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateClientWithAmplifyInstance.mjs","sources":["../../../../src/internals/server/generateClientWithAmplifyInstance.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport {
|
|
1
|
+
{"version":3,"file":"generateClientWithAmplifyInstance.mjs","sources":["../../../../src/internals/server/generateClientWithAmplifyInstance.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { cancel, graphql, isCancelError } from '..';\nimport { __amplify, __authMode, __authToken, __headers, } from '../../types';\nimport { isApiGraphQLConfig } from '../utils/runtimeTypeGuards/isApiGraphQLProviderConfig';\nimport { generateEnumsProperty } from '../utils/clientProperties/generateEnumsProperty';\nimport { generateCustomMutationsProperty, generateCustomQueriesProperty, } from '../generateCustomOperationsProperty';\nimport { generateModelsProperty } from './generateModelsProperty';\n/**\n * @private\n *\n * Used internally by `adapter-nextjs` package.\n *\n * Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`\n * compatible context object for config and auth fetching.\n *\n * @param params\n * @returns\n */\nexport function generateClientWithAmplifyInstance(params) {\n const client = {\n [__amplify]: params.amplify,\n [__authMode]: params.authMode,\n [__authToken]: params.authToken,\n [__headers]: params.headers,\n graphql,\n cancel,\n isCancelError,\n };\n const apiGraphqlConfig = params.config?.API?.GraphQL;\n if (isApiGraphQLConfig(apiGraphqlConfig)) {\n client.models = generateModelsProperty(client, params);\n client.enums = generateEnumsProperty(apiGraphqlConfig);\n client.queries = generateCustomQueriesProperty(client, apiGraphqlConfig);\n client.mutations = generateCustomMutationsProperty(client, apiGraphqlConfig);\n }\n return client;\n}\n"],"names":[],"mappings":";;;;;;;;;AAAA;AACA;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,iCAAiC,CAAC,MAAM,EAAE;AAC1D,IAAI,MAAM,MAAM,GAAG;AACnB,QAAQ,CAAC,SAAS,GAAG,MAAM,CAAC,OAAO;AACnC,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC,QAAQ;AACrC,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,SAAS;AACvC,QAAQ,CAAC,SAAS,GAAG,MAAM,CAAC,OAAO;AACnC,QAAQ,OAAO;AACf,QAAQ,MAAM;AACd,QAAQ,aAAa;AACrB,KAAK,CAAC;AACN,IAAI,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,EAAE,OAAO,CAAC;AACzD,IAAI,IAAI,kBAAkB,CAAC,gBAAgB,CAAC,EAAE;AAC9C,QAAQ,MAAM,CAAC,MAAM,GAAG,sBAAsB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC/D,QAAQ,MAAM,CAAC,KAAK,GAAG,qBAAqB,CAAC,gBAAgB,CAAC,CAAC;AAC/D,QAAQ,MAAM,CAAC,OAAO,GAAG,6BAA6B,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AACjF,QAAQ,MAAM,CAAC,SAAS,GAAG,+BAA+B,CAAC,MAAM,EAAE,gBAAgB,CAAC,CAAC;AACrF,KAAK;AACL,IAAI,OAAO,MAAM,CAAC;AAClB;;;;"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
export declare function generateModelsProperty<
|
|
1
|
+
import { ModelTypes } from '@aws-amplify/data-schema-types';
|
|
2
|
+
import { ServerClientGenerationParams, V6ClientSSRCookies, V6ClientSSRRequest } from '../../types/';
|
|
3
|
+
export declare function generateModelsProperty<T extends Record<any, any> = never, ClientType extends V6ClientSSRRequest<Record<string, any>> | V6ClientSSRCookies<Record<string, any>> = V6ClientSSRCookies<Record<string, any>>>(client: ClientType, params: ServerClientGenerationParams): ModelTypes<T> | ModelTypes<never>;
|
|
@@ -6,7 +6,7 @@ import { getSecondaryIndexesFromSchemaModel } from '../clientUtils.mjs';
|
|
|
6
6
|
|
|
7
7
|
function generateModelsProperty(client, params) {
|
|
8
8
|
const models = {};
|
|
9
|
-
const config = params
|
|
9
|
+
const { config } = params;
|
|
10
10
|
const useContext = params.amplify === null;
|
|
11
11
|
if (!config) {
|
|
12
12
|
throw new Error('generateModelsProperty cannot retrieve Amplify config');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generateModelsProperty.mjs","sources":["../../../../src/internals/server/generateModelsProperty.ts"],"sourcesContent":["import { graphQLOperationsInfo } from '../APIClient';\nimport { listFactory } from '../operations/list';\nimport { indexQueryFactory } from '../operations/indexQuery';\nimport { getFactory } from '../operations/get';\nimport { getSecondaryIndexesFromSchemaModel } from '../clientUtils';\nexport function generateModelsProperty(client, params) {\n const models = {};\n const config = params
|
|
1
|
+
{"version":3,"file":"generateModelsProperty.mjs","sources":["../../../../src/internals/server/generateModelsProperty.ts"],"sourcesContent":["import { graphQLOperationsInfo } from '../APIClient';\nimport { listFactory } from '../operations/list';\nimport { indexQueryFactory } from '../operations/indexQuery';\nimport { getFactory } from '../operations/get';\nimport { getSecondaryIndexesFromSchemaModel } from '../clientUtils';\nexport function generateModelsProperty(client, params) {\n const models = {};\n const { config } = params;\n const useContext = params.amplify === null;\n if (!config) {\n throw new Error('generateModelsProperty cannot retrieve Amplify config');\n }\n if (!config.API?.GraphQL) {\n return {};\n }\n const modelIntrospection = config.API.GraphQL.modelIntrospection;\n if (!modelIntrospection) {\n return {};\n }\n const SSR_UNSUPORTED_OPS = [\n 'ONCREATE',\n 'ONUPDATE',\n 'ONDELETE',\n 'OBSERVE_QUERY',\n ];\n for (const model of Object.values(modelIntrospection.models)) {\n const { name } = model;\n models[name] = {};\n Object.entries(graphQLOperationsInfo).forEach(([key, { operationPrefix }]) => {\n const operation = key;\n // subscriptions are not supported in SSR\n if (SSR_UNSUPORTED_OPS.includes(operation))\n return;\n if (operation === 'LIST') {\n models[name][operationPrefix] = listFactory(client, modelIntrospection, model, useContext);\n }\n else {\n models[name][operationPrefix] = getFactory(client, modelIntrospection, model, operation, useContext);\n }\n });\n const secondaryIdxs = getSecondaryIndexesFromSchemaModel(model);\n for (const idx of secondaryIdxs) {\n models[name][idx.queryField] = indexQueryFactory(client, modelIntrospection, model, idx);\n }\n }\n return models;\n}\n"],"names":[],"mappings":";;;;;;AAKO,SAAS,sBAAsB,CAAC,MAAM,EAAE,MAAM,EAAE;AACvD,IAAI,MAAM,MAAM,GAAG,EAAE,CAAC;AACtB,IAAI,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;AAC9B,IAAI,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,KAAK,IAAI,CAAC;AAC/C,IAAI,IAAI,CAAC,MAAM,EAAE;AACjB,QAAQ,MAAM,IAAI,KAAK,CAAC,uDAAuD,CAAC,CAAC;AACjF,KAAK;AACL,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE;AAC9B,QAAQ,OAAO,EAAE,CAAC;AAClB,KAAK;AACL,IAAI,MAAM,kBAAkB,GAAG,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,kBAAkB,CAAC;AACrE,IAAI,IAAI,CAAC,kBAAkB,EAAE;AAC7B,QAAQ,OAAO,EAAE,CAAC;AA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AS;AACT,KAAK;AACL,IAAI,OAAO,MAAM,CAAC;AAClB;;;;"}
|
|
@@ -12,8 +12,8 @@ export type ClientGenerationParams = {
|
|
|
12
12
|
/**
|
|
13
13
|
* Common options that can be used on public `generateClient()` interfaces.
|
|
14
14
|
*/
|
|
15
|
-
export
|
|
15
|
+
export interface CommonPublicClientOptions {
|
|
16
16
|
authMode?: GraphQLAuthMode;
|
|
17
17
|
authToken?: string;
|
|
18
18
|
headers?: CustomHeaders;
|
|
19
|
-
}
|
|
19
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ModelTypes } from '@aws-amplify/data-schema-types';
|
|
2
|
-
import { V6Client } from '../../../types';
|
|
3
2
|
import { GraphQLProviderConfig } from '@aws-amplify/core/internals/utils';
|
|
4
|
-
|
|
3
|
+
import { V6Client } from '../../../types';
|
|
4
|
+
export declare function generateModelsProperty<T extends Record<any, any> = never>(client: V6Client<Record<string, any>>, apiGraphQLConfig: GraphQLProviderConfig['GraphQL']): ModelTypes<T> | ModelTypes<never>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { V6Client, GraphQLOptionsV6, GraphQLResponseV6 } from '../types';
|
|
2
1
|
import { CustomHeaders } from '@aws-amplify/data-schema-types';
|
|
2
|
+
import { GraphQLOptionsV6, GraphQLResponseV6, V6Client } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Invokes graphql operations against a graphql service, providing correct input and
|
|
5
5
|
* output types if Amplify-generated graphql from a recent version of the CLI/codegen
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { GraphQLAPI } from '../GraphQLAPI.mjs';
|
|
2
2
|
import { __authMode, __authToken, __amplify } from '../types/index.mjs';
|
|
3
3
|
|
|
4
|
-
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
5
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
6
4
|
/**
|
|
7
5
|
* Invokes graphql operations against a graphql service, providing correct input and
|
|
8
6
|
* output types if Amplify-generated graphql from a recent version of the CLI/codegen
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"v6.mjs","sources":["../../../src/internals/v6.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"file":"v6.mjs","sources":["../../../src/internals/v6.ts"],"sourcesContent":["import { GraphQLAPI } from '../GraphQLAPI';\nimport { __amplify, __authMode, __authToken, } from '../types';\n/**\n * Invokes graphql operations against a graphql service, providing correct input and\n * output types if Amplify-generated graphql from a recent version of the CLI/codegen\n * are used *or* correct typing is provided via the type argument.\n *\n * Amplify-generated \"branded\" graphql queries will look similar to this:\n *\n * ```ts\n * //\n * // |-- branding\n * // v\n * export const getModel = `...` as GeneratedQuery<\n * \tGetModelQueryVariables,\n * \tGetModelQuery\n * >;\n * ```\n *\n * If this branding is not in your generated graphql, update to a newer version of\n * CLI/codegen and regenerate your graphql using `amplify codegen`.\n *\n * ## Using Amplify-generated graphql\n *\n * ```ts\n * import * as queries from './graphql/queries';\n *\n * //\n * // |-- correctly typed graphql response containing a Widget\n * // v\n * const queryResult = await graphql({\n * \tquery: queries.getWidget,\n * \tvariables: {\n * \t\tid: \"abc\", // <-- type hinted/enforced\n * \t},\n * });\n *\n * //\n * // |-- a correctly typed Widget\n * // v\n * const fetchedWidget = queryResult.data?.getWidget!;\n * ```\n *\n * ## Custom input + result types\n *\n * To provide input types (`variables`) and result types:\n *\n * ```ts\n * type GetById_NameOnly = {\n * \tvariables: {\n * \t\tid: string\n * \t},\n * \tresult: Promise<{\n * \t\tdata: { getWidget: { name: string } }\n * \t}>\n * }\n *\n * //\n * // |-- type is GetById_NameOnly[\"result\"]\n * // v\n * const result = graphql<GetById_NameOnly>({\n * \tquery: \"...\",\n * \tvariables: { id: \"abc\" } // <-- type of GetById_NameOnly[\"variables\"]\n * });\n * ```\n *\n * ## Custom result type only\n *\n * To specify result types only, use a type that is *not* in the `{variables, result}` shape:\n *\n * ```ts\n * type MyResultType = Promise<{\n * \tdata: {\n * \t\tgetWidget: { name: string }\n * \t}\n * }>\n *\n * //\n * // |-- type is MyResultType\n * // v\n * const result = graphql<MyResultType>({query: \"...\"});\n * ```\n *\n * @param options\n * @param additionalHeaders\n */\nexport function graphql(options, additionalHeaders) {\n // inject client-level auth\n options.authMode = options.authMode || this[__authMode];\n options.authToken = options.authToken || this[__authToken];\n /**\n * The correctness of these typings depends on correct string branding or overrides.\n * Neither of these can actually be validated at runtime. Hence, we don't perform\n * any validation or type-guarding here.\n */\n const result = GraphQLAPI.graphql(this[__amplify], options, additionalHeaders);\n return result;\n}\n/**\n * Cancels an inflight request. Only applicable for graphql queries and mutations\n * @param {any} request - request to cancel\n * @returns - A boolean indicating if the request was cancelled\n */\nexport function cancel(promise, message) {\n return GraphQLAPI.cancel(promise, message);\n}\n/**\n * Checks to see if an error thrown is from an api request cancellation\n * @param {any} error - Any error\n * @returns - A boolean indicating if the error was from an api request cancellation\n */\nexport function isCancelError(error) {\n return GraphQLAPI.isCancelError(error);\n}\n"],"names":[],"mappings":";;;AAEA;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;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,OAAO,CAAC,OAAO,EAAE,iBAAiB,EAAE;AACpD;AACA,IAAI,OAAO,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,IAAI,CAAC,UAAU,CAAC,CAAC;AAC5D,IAAI,OAAO,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,IAAI,CAAC,WAAW,CAAC,CAAC;AAC/D;AACA;AACA;AACA;AACA;AACA,IAAI,MAAM,MAAM,GAAG,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC;AACnF,IAAI,OAAO,MAAM,CAAC;AAClB,CAAC;AACD;AACA;AACA;AACA;AACA;AACO,SAAS,MAAM,CAAC,OAAO,EAAE,OAAO,EAAE;AACzC,IAAI,OAAO,UAAU,CAAC,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAC/C,CAAC;AACD;AACA;AACA;AACA;AACA;AACO,SAAS,aAAa,CAAC,KAAK,EAAE;AACrC,IAAI,OAAO,UAAU,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;AAC3C;;;;"}
|