@aws-amplify/api-graphql 4.0.19 → 4.0.20-api-graphql-eslint.dd94c10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js +40 -31
- package/dist/cjs/Providers/AWSAppSyncRealTimeProvider/index.js.map +1 -1
- package/dist/cjs/internals/APIClient.js +36 -20
- 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 +5 -5
- package/dist/cjs/internals/generateClient.js.map +1 -1
- package/dist/cjs/internals/operations/custom.js +4 -20
- 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 +3 -3
- 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/utils/clientProperties/generateEnumsProperty.js.map +1 -0
- package/dist/cjs/internals/utils/{generateModelsProperty.js → clientProperties/generateModelsProperty.js} +7 -7
- package/dist/cjs/internals/utils/clientProperties/generateModelsProperty.js.map +1 -0
- package/dist/cjs/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.js.map +1 -0
- package/dist/cjs/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.js.map +1 -0
- 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/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 +6 -5
- package/dist/esm/internals/APIClient.mjs +35 -20
- 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 -5
- package/dist/esm/internals/generateClient.mjs.map +1 -1
- package/dist/esm/internals/generateCustomOperationsProperty.d.ts +2 -2
- package/dist/esm/internals/operations/custom.d.ts +1 -1
- package/dist/esm/internals/operations/custom.mjs +5 -21
- 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 +3 -3
- package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs.map +1 -1
- package/dist/esm/internals/server/generateModelsProperty.d.ts +1 -2
- 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/generateEnumsProperty.mjs.map +1 -0
- package/dist/esm/internals/utils/{generateModelsProperty.d.ts → clientProperties/generateModelsProperty.d.ts} +1 -1
- package/dist/esm/internals/utils/{generateModelsProperty.mjs → clientProperties/generateModelsProperty.mjs} +7 -7
- package/dist/esm/internals/utils/clientProperties/generateModelsProperty.mjs.map +1 -0
- package/dist/esm/internals/utils/runtimeTypeGuards/isApiGraphQLProviderConfig.mjs.map +1 -0
- package/dist/esm/internals/utils/runtimeTypeGuards/isConfigureEventWithResourceConfig.mjs.map +1 -0
- 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 +33 -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/package.json +8 -7
- package/src/GraphQLAPI.ts +4 -3
- package/src/Providers/AWSAppSyncRealTimeProvider/index.ts +84 -64
- package/src/internals/APIClient.ts +60 -28
- package/src/internals/InternalGraphQLAPI.ts +26 -30
- package/src/internals/clientUtils.ts +1 -1
- package/src/internals/generateClient.ts +13 -11
- package/src/internals/generateCustomOperationsProperty.ts +7 -6
- package/src/internals/operations/custom.ts +21 -35
- 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 +9 -9
- package/src/internals/server/generateModelsProperty.ts +7 -4
- package/src/internals/types.ts +2 -2
- package/src/internals/utils/{generateEnumsProperty.ts → clientProperties/generateEnumsProperty.ts} +7 -6
- package/src/internals/utils/{generateModelsProperty.ts → clientProperties/generateModelsProperty.ts} +10 -9
- 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 +7 -5
- package/src/utils/resolvePKFields.ts +1 -0
- package/dist/cjs/internals/utils/generateEnumsProperty.js.map +0 -1
- package/dist/cjs/internals/utils/generateModelsProperty.js.map +0 -1
- package/dist/cjs/internals/utils/isApiGraphQLProviderConfig.js.map +0 -1
- package/dist/cjs/internals/utils/isConfigureEventWithResourceConfig.js.map +0 -1
- package/dist/esm/internals/utils/generateEnumsProperty.mjs.map +0 -1
- package/dist/esm/internals/utils/generateModelsProperty.mjs.map +0 -1
- package/dist/esm/internals/utils/isApiGraphQLProviderConfig.mjs.map +0 -1
- package/dist/esm/internals/utils/isConfigureEventWithResourceConfig.mjs.map +0 -1
- /package/dist/cjs/internals/utils/{generateEnumsProperty.js → clientProperties/generateEnumsProperty.js} +0 -0
- /package/dist/cjs/internals/utils/{isApiGraphQLProviderConfig.js → runtimeTypeGuards/isApiGraphQLProviderConfig.js} +0 -0
- /package/dist/cjs/internals/utils/{isConfigureEventWithResourceConfig.js → runtimeTypeGuards/isConfigureEventWithResourceConfig.js} +0 -0
- /package/dist/esm/internals/utils/{generateEnumsProperty.d.ts → clientProperties/generateEnumsProperty.d.ts} +0 -0
- /package/dist/esm/internals/utils/{generateEnumsProperty.mjs → clientProperties/generateEnumsProperty.mjs} +0 -0
- /package/dist/esm/internals/utils/{isApiGraphQLProviderConfig.d.ts → runtimeTypeGuards/isApiGraphQLProviderConfig.d.ts} +0 -0
- /package/dist/esm/internals/utils/{isApiGraphQLProviderConfig.mjs → runtimeTypeGuards/isApiGraphQLProviderConfig.mjs} +0 -0
- /package/dist/esm/internals/utils/{isConfigureEventWithResourceConfig.d.ts → runtimeTypeGuards/isConfigureEventWithResourceConfig.d.ts} +0 -0
- /package/dist/esm/internals/utils/{isConfigureEventWithResourceConfig.mjs → runtimeTypeGuards/isConfigureEventWithResourceConfig.mjs} +0 -0
- /package/src/internals/utils/{isApiGraphQLProviderConfig.ts → runtimeTypeGuards/isApiGraphQLProviderConfig.ts} +0 -0
- /package/src/internals/utils/{isConfigureEventWithResourceConfig.ts → runtimeTypeGuards/isConfigureEventWithResourceConfig.ts} +0 -0
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import { resolveOwnerFields } from '../utils/resolveOwnerFields';
|
|
4
3
|
import {
|
|
4
|
+
AssociationBelongsTo,
|
|
5
|
+
AssociationHasOne,
|
|
5
6
|
GraphQLAuthMode,
|
|
6
|
-
ModelIntrospectionSchema,
|
|
7
7
|
ModelFieldType,
|
|
8
|
+
ModelIntrospectionSchema,
|
|
8
9
|
NonModelFieldType,
|
|
9
10
|
SchemaModel,
|
|
10
|
-
|
|
11
|
-
AssociationBelongsTo,
|
|
11
|
+
SchemaNonModel,
|
|
12
12
|
} from '@aws-amplify/core/internals/utils';
|
|
13
|
+
import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
|
|
14
|
+
import { CustomHeaders } from '@aws-amplify/data-schema-types';
|
|
15
|
+
|
|
13
16
|
import {
|
|
14
17
|
AuthModeParams,
|
|
15
18
|
ClientWithModels,
|
|
@@ -21,18 +24,17 @@ import {
|
|
|
21
24
|
__authToken,
|
|
22
25
|
__headers,
|
|
23
26
|
} from '../types';
|
|
24
|
-
import {
|
|
25
|
-
|
|
26
|
-
import { SchemaNonModel } from '@aws-amplify/core/dist/esm/singleton/API/types';
|
|
27
|
+
import { resolveOwnerFields } from '../utils/resolveOwnerFields';
|
|
28
|
+
|
|
27
29
|
import type { IndexMeta } from './operations/indexQuery';
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
interface LazyLoadOptions {
|
|
30
32
|
authMode?: GraphQLAuthMode;
|
|
31
33
|
authToken?: string | undefined;
|
|
32
34
|
limit?: number | undefined;
|
|
33
35
|
nextToken?: string | undefined | null;
|
|
34
36
|
headers?: CustomHeaders | undefined;
|
|
35
|
-
}
|
|
37
|
+
}
|
|
36
38
|
|
|
37
39
|
const connectionType = {
|
|
38
40
|
HAS_ONE: 'HAS_ONE',
|
|
@@ -54,9 +56,11 @@ export const flattenItems = (obj: Record<string, any>): Record<string, any> => {
|
|
|
54
56
|
res[prop] = value.items.map((item: Record<string, any>) =>
|
|
55
57
|
flattenItems(item),
|
|
56
58
|
);
|
|
59
|
+
|
|
57
60
|
return;
|
|
58
61
|
}
|
|
59
62
|
res[prop] = flattenItems(value);
|
|
63
|
+
|
|
60
64
|
return;
|
|
61
65
|
}
|
|
62
66
|
|
|
@@ -109,15 +113,17 @@ export function initializeModel(
|
|
|
109
113
|
connectionFields = modelField.association.associatedWith;
|
|
110
114
|
}
|
|
111
115
|
|
|
112
|
-
|
|
116
|
+
const targetNames: string[] = [];
|
|
113
117
|
if (modelField.association && 'targetNames' in modelField.association) {
|
|
114
|
-
targetNames
|
|
118
|
+
targetNames.push(...modelField.association.targetNames);
|
|
115
119
|
}
|
|
116
120
|
|
|
117
121
|
switch (relationType) {
|
|
118
122
|
case connectionType.HAS_ONE:
|
|
119
|
-
case connectionType.BELONGS_TO:
|
|
123
|
+
case connectionType.BELONGS_TO: {
|
|
120
124
|
const sortKeyValues = relatedModelSKFieldNames.reduce(
|
|
125
|
+
// TODO(Eslint): is this implementation correct?
|
|
126
|
+
// eslint-disable-next-line array-callback-return
|
|
121
127
|
(acc: Record<string, any>, curVal) => {
|
|
122
128
|
if (record[curVal]) {
|
|
123
129
|
return (acc[curVal] = record[curVal]);
|
|
@@ -146,6 +152,7 @@ export function initializeModel(
|
|
|
146
152
|
},
|
|
147
153
|
);
|
|
148
154
|
}
|
|
155
|
+
|
|
149
156
|
return undefined;
|
|
150
157
|
};
|
|
151
158
|
} else {
|
|
@@ -166,12 +173,14 @@ export function initializeModel(
|
|
|
166
173
|
},
|
|
167
174
|
);
|
|
168
175
|
}
|
|
176
|
+
|
|
169
177
|
return undefined;
|
|
170
178
|
};
|
|
171
179
|
}
|
|
172
180
|
|
|
173
181
|
break;
|
|
174
|
-
|
|
182
|
+
}
|
|
183
|
+
case connectionType.HAS_MANY: {
|
|
175
184
|
const parentPk = introModel.primaryKeyInfo.primaryKeyFieldName;
|
|
176
185
|
const parentSK = introModel.primaryKeyInfo.sortKeyFieldNames;
|
|
177
186
|
|
|
@@ -214,6 +223,7 @@ export function initializeModel(
|
|
|
214
223
|
authToken: options?.authToken || authToken,
|
|
215
224
|
});
|
|
216
225
|
}
|
|
226
|
+
|
|
217
227
|
return [];
|
|
218
228
|
};
|
|
219
229
|
} else {
|
|
@@ -231,6 +241,7 @@ export function initializeModel(
|
|
|
231
241
|
authToken: options?.authToken || authToken,
|
|
232
242
|
});
|
|
233
243
|
}
|
|
244
|
+
|
|
234
245
|
return [];
|
|
235
246
|
};
|
|
236
247
|
}
|
|
@@ -264,6 +275,7 @@ export function initializeModel(
|
|
|
264
275
|
authToken: options?.authToken || authToken,
|
|
265
276
|
});
|
|
266
277
|
}
|
|
278
|
+
|
|
267
279
|
return [];
|
|
268
280
|
};
|
|
269
281
|
} else {
|
|
@@ -281,11 +293,13 @@ export function initializeModel(
|
|
|
281
293
|
authToken: options?.authToken || authToken,
|
|
282
294
|
});
|
|
283
295
|
}
|
|
296
|
+
|
|
284
297
|
return [];
|
|
285
298
|
};
|
|
286
299
|
}
|
|
287
300
|
|
|
288
301
|
break;
|
|
302
|
+
}
|
|
289
303
|
default:
|
|
290
304
|
break;
|
|
291
305
|
}
|
|
@@ -309,12 +323,9 @@ export const graphQLOperationsInfo = {
|
|
|
309
323
|
} as const;
|
|
310
324
|
export type ModelOperation = keyof typeof graphQLOperationsInfo;
|
|
311
325
|
|
|
312
|
-
type OperationPrefix =
|
|
313
|
-
(typeof graphQLOperationsInfo)[ModelOperation]['operationPrefix'];
|
|
314
|
-
|
|
315
326
|
const SELECTION_SET_WILDCARD = '*';
|
|
316
327
|
|
|
317
|
-
function defaultSelectionSetForNonModelWithIR(
|
|
328
|
+
export function defaultSelectionSetForNonModelWithIR(
|
|
318
329
|
nonModelDefinition: SchemaNonModel,
|
|
319
330
|
modelIntrospection: ModelIntrospectionSchema,
|
|
320
331
|
): Record<string, unknown> {
|
|
@@ -346,6 +357,7 @@ function defaultSelectionSetForNonModelWithIR(
|
|
|
346
357
|
pair: (string | Record<string, unknown>)[] | undefined,
|
|
347
358
|
): pair is (string | Record<string, unknown>)[] => pair !== undefined,
|
|
348
359
|
);
|
|
360
|
+
|
|
349
361
|
return Object.fromEntries(mappedFields);
|
|
350
362
|
}
|
|
351
363
|
|
|
@@ -365,6 +377,8 @@ function defaultSelectionSetForModel(modelDefinition: SchemaModel): string[] {
|
|
|
365
377
|
return `${name}.${SELECTION_SET_WILDCARD}`;
|
|
366
378
|
}
|
|
367
379
|
}
|
|
380
|
+
|
|
381
|
+
return undefined;
|
|
368
382
|
})
|
|
369
383
|
.filter(Boolean);
|
|
370
384
|
|
|
@@ -460,10 +474,13 @@ export function customSelectionSetToIR(
|
|
|
460
474
|
}
|
|
461
475
|
|
|
462
476
|
if (nested === SELECTION_SET_WILDCARD) {
|
|
463
|
-
const
|
|
477
|
+
const nestedRelatedModelDefinition =
|
|
478
|
+
modelIntrospection.models[relatedModel];
|
|
464
479
|
|
|
465
480
|
result = {
|
|
466
|
-
[fieldName]: modelsDefaultSelectionSetIR(
|
|
481
|
+
[fieldName]: modelsDefaultSelectionSetIR(
|
|
482
|
+
nestedRelatedModelDefinition,
|
|
483
|
+
),
|
|
467
484
|
};
|
|
468
485
|
} else {
|
|
469
486
|
result = {
|
|
@@ -527,6 +544,7 @@ const modelsDefaultSelectionSetIR = (relatedModelDefinition: SchemaModel) => {
|
|
|
527
544
|
const reduced = defaultSelectionSet.reduce(
|
|
528
545
|
(acc: Record<string, any>, curVal) => {
|
|
529
546
|
acc[curVal] = FIELD_IR;
|
|
547
|
+
|
|
530
548
|
return acc;
|
|
531
549
|
},
|
|
532
550
|
{},
|
|
@@ -594,9 +612,12 @@ function deepMergeSelectionSetObjects<T extends Record<string, any>>(
|
|
|
594
612
|
|
|
595
613
|
for (const key in source) {
|
|
596
614
|
// This verification avoids 'Prototype Pollution' issue
|
|
597
|
-
if (!
|
|
615
|
+
if (!Object.prototype.hasOwnProperty.call(source, key)) continue;
|
|
598
616
|
|
|
599
|
-
if (
|
|
617
|
+
if (
|
|
618
|
+
Object.prototype.hasOwnProperty.call(target, key) &&
|
|
619
|
+
isObject(target[key])
|
|
620
|
+
) {
|
|
600
621
|
deepMergeSelectionSetObjects(source[key], target[key]);
|
|
601
622
|
} else {
|
|
602
623
|
target[key] = source[key];
|
|
@@ -659,6 +680,7 @@ export function generateGraphQLDocument(
|
|
|
659
680
|
const skQueryArgs = sk.reduce((acc: Record<string, any>, fieldName) => {
|
|
660
681
|
const fieldType = fields[fieldName].type;
|
|
661
682
|
acc[fieldName] = `Model${fieldType}KeyConditionInput`;
|
|
683
|
+
|
|
662
684
|
return acc;
|
|
663
685
|
}, {});
|
|
664
686
|
|
|
@@ -694,6 +716,8 @@ export function generateGraphQLDocument(
|
|
|
694
716
|
}${name}Input!`,
|
|
695
717
|
});
|
|
696
718
|
graphQLOperationType ?? (graphQLOperationType = 'mutation');
|
|
719
|
+
// TODO(Eslint): this this case clause correct without the break statement?
|
|
720
|
+
// eslint-disable-next-line no-fallthrough
|
|
697
721
|
case 'READ':
|
|
698
722
|
graphQLArguments ??
|
|
699
723
|
(graphQLArguments = isCustomPrimaryKey
|
|
@@ -709,6 +733,8 @@ export function generateGraphQLDocument(
|
|
|
709
733
|
[primaryKeyFieldName]: `${fields[primaryKeyFieldName].type}!`,
|
|
710
734
|
});
|
|
711
735
|
graphQLSelectionSet ?? (graphQLSelectionSet = selectionSetFields);
|
|
736
|
+
// TODO(Eslint): this this case clause correct without the break statement?
|
|
737
|
+
// eslint-disable-next-line no-fallthrough
|
|
712
738
|
case 'LIST':
|
|
713
739
|
graphQLArguments ??
|
|
714
740
|
(graphQLArguments = {
|
|
@@ -719,6 +745,8 @@ export function generateGraphQLDocument(
|
|
|
719
745
|
graphQLOperationType ?? (graphQLOperationType = 'query');
|
|
720
746
|
graphQLSelectionSet ??
|
|
721
747
|
(graphQLSelectionSet = `items { ${selectionSetFields} } nextToken __typename`);
|
|
748
|
+
// TODO(Eslint): this this case clause correct without the break statement?
|
|
749
|
+
// eslint-disable-next-line no-fallthrough
|
|
722
750
|
case 'INDEX_QUERY':
|
|
723
751
|
graphQLArguments ??
|
|
724
752
|
(graphQLArguments = {
|
|
@@ -730,6 +758,8 @@ export function generateGraphQLDocument(
|
|
|
730
758
|
graphQLOperationType ?? (graphQLOperationType = 'query');
|
|
731
759
|
graphQLSelectionSet ??
|
|
732
760
|
(graphQLSelectionSet = `items { ${selectionSetFields} } nextToken __typename`);
|
|
761
|
+
// TODO(Eslint): this this case clause correct without the break statement?
|
|
762
|
+
// eslint-disable-next-line no-fallthrough
|
|
733
763
|
case 'ONCREATE':
|
|
734
764
|
case 'ONUPDATE':
|
|
735
765
|
case 'ONDELETE':
|
|
@@ -750,13 +780,13 @@ export function generateGraphQLDocument(
|
|
|
750
780
|
const graphQLDocument = `${graphQLOperationType}${
|
|
751
781
|
graphQLArguments
|
|
752
782
|
? `(${Object.entries(graphQLArguments).map(
|
|
753
|
-
([fieldName, type]) =>
|
|
783
|
+
([fieldName, type]) => `$${fieldName}: ${type}`,
|
|
754
784
|
)})`
|
|
755
785
|
: ''
|
|
756
786
|
} { ${graphQLFieldName}${
|
|
757
787
|
graphQLArguments
|
|
758
788
|
? `(${Object.keys(graphQLArguments).map(
|
|
759
|
-
fieldName => `${fieldName}:
|
|
789
|
+
fieldName => `${fieldName}: $${fieldName}`,
|
|
760
790
|
)})`
|
|
761
791
|
: ''
|
|
762
792
|
} { ${graphQLSelectionSet} } }`;
|
|
@@ -842,7 +872,7 @@ export function buildGraphQLVariables(
|
|
|
842
872
|
variables.limit = arg.limit;
|
|
843
873
|
}
|
|
844
874
|
break;
|
|
845
|
-
case 'INDEX_QUERY':
|
|
875
|
+
case 'INDEX_QUERY': {
|
|
846
876
|
const { pk, sk = [] } = indexMeta!;
|
|
847
877
|
|
|
848
878
|
variables[pk] = arg![pk];
|
|
@@ -861,6 +891,7 @@ export function buildGraphQLVariables(
|
|
|
861
891
|
variables.limit = arg.limit;
|
|
862
892
|
}
|
|
863
893
|
break;
|
|
894
|
+
}
|
|
864
895
|
case 'ONCREATE':
|
|
865
896
|
case 'ONUPDATE':
|
|
866
897
|
case 'ONDELETE':
|
|
@@ -873,9 +904,10 @@ export function buildGraphQLVariables(
|
|
|
873
904
|
'Internal error: Attempted to build variables for observeQuery. Please report this error.',
|
|
874
905
|
);
|
|
875
906
|
break;
|
|
876
|
-
default:
|
|
907
|
+
default: {
|
|
877
908
|
const exhaustiveCheck: never = operation;
|
|
878
909
|
throw new Error(`Unhandled operation case: ${exhaustiveCheck}`);
|
|
910
|
+
}
|
|
879
911
|
}
|
|
880
912
|
|
|
881
913
|
return variables;
|
|
@@ -969,9 +1001,9 @@ export function authModeParams(
|
|
|
969
1001
|
|
|
970
1002
|
/**
|
|
971
1003
|
* Retrieves custom headers from either the client or request options.
|
|
972
|
-
* @param
|
|
973
|
-
* @param
|
|
974
|
-
* @returns {CustomHeaders}
|
|
1004
|
+
* @param client V6Client | V6ClientSSRRequest | V6ClientSSRCookies - for extracting client headers
|
|
1005
|
+
* @param requestHeaders {@link CustomHeaders} - request headers
|
|
1006
|
+
* @returns custom headers as {@link CustomHeaders}
|
|
975
1007
|
*/
|
|
976
1008
|
export function getCustomHeaders(
|
|
977
1009
|
client: V6Client | ClientWithModels,
|
|
@@ -2,41 +2,40 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import {
|
|
4
4
|
DocumentNode,
|
|
5
|
-
OperationDefinitionNode,
|
|
6
|
-
print,
|
|
7
|
-
parse,
|
|
8
5
|
GraphQLError,
|
|
6
|
+
OperationDefinitionNode,
|
|
9
7
|
OperationTypeNode,
|
|
8
|
+
parse,
|
|
9
|
+
print,
|
|
10
10
|
} from 'graphql';
|
|
11
11
|
import { Observable, catchError } from 'rxjs';
|
|
12
|
-
import { AmplifyClassV6
|
|
12
|
+
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
13
13
|
import {
|
|
14
|
-
|
|
14
|
+
AmplifyUrl,
|
|
15
15
|
CustomUserAgentDetails,
|
|
16
|
+
GraphQLAuthMode,
|
|
16
17
|
getAmplifyUserAgent,
|
|
17
|
-
AmplifyUrl,
|
|
18
18
|
} from '@aws-amplify/core/internals/utils';
|
|
19
|
-
import {
|
|
20
|
-
GraphQLAuthError,
|
|
21
|
-
GraphQLResult,
|
|
22
|
-
GraphQLOperation,
|
|
23
|
-
GraphQLOptions,
|
|
24
|
-
} from '../types';
|
|
25
19
|
import { isCancelError as isCancelErrorREST } from '@aws-amplify/api-rest';
|
|
26
20
|
import {
|
|
27
|
-
post,
|
|
28
21
|
cancel as cancelREST,
|
|
22
|
+
post,
|
|
29
23
|
updateRequestToBeCancellable,
|
|
30
24
|
} from '@aws-amplify/api-rest/internals';
|
|
31
|
-
import { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvider';
|
|
32
25
|
import { CustomHeaders, RequestOptions } from '@aws-amplify/data-schema-types';
|
|
26
|
+
|
|
27
|
+
import { AWSAppSyncRealTimeProvider } from '../Providers/AWSAppSyncRealTimeProvider';
|
|
28
|
+
import {
|
|
29
|
+
GraphQLAuthError,
|
|
30
|
+
GraphQLOperation,
|
|
31
|
+
GraphQLOptions,
|
|
32
|
+
GraphQLResult,
|
|
33
|
+
} from '../types';
|
|
33
34
|
import { resolveConfig, resolveLibraryOptions } from '../utils';
|
|
34
35
|
import { repackageUnauthError } from '../utils/errors/repackageAuthError';
|
|
35
36
|
|
|
36
37
|
const USER_AGENT_HEADER = 'x-amz-user-agent';
|
|
37
38
|
|
|
38
|
-
const logger = new ConsoleLogger('GraphQLAPI');
|
|
39
|
-
|
|
40
39
|
const isAmplifyInstance = (
|
|
41
40
|
amplify:
|
|
42
41
|
| AmplifyClassV6
|
|
@@ -70,11 +69,7 @@ export class InternalGraphQLAPIClass {
|
|
|
70
69
|
authMode: GraphQLAuthMode,
|
|
71
70
|
additionalHeaders: Record<string, string> = {},
|
|
72
71
|
) {
|
|
73
|
-
const {
|
|
74
|
-
region: region,
|
|
75
|
-
endpoint: appSyncGraphqlEndpoint,
|
|
76
|
-
apiKey,
|
|
77
|
-
} = resolveConfig(amplify);
|
|
72
|
+
const { apiKey } = resolveConfig(amplify);
|
|
78
73
|
|
|
79
74
|
let headers = {};
|
|
80
75
|
|
|
@@ -87,18 +82,17 @@ export class InternalGraphQLAPIClass {
|
|
|
87
82
|
'X-Api-Key': apiKey,
|
|
88
83
|
};
|
|
89
84
|
break;
|
|
90
|
-
case 'iam':
|
|
85
|
+
case 'iam': {
|
|
91
86
|
const session = await amplify.Auth.fetchAuthSession();
|
|
92
87
|
if (session.credentials === undefined) {
|
|
93
88
|
throw new Error(GraphQLAuthError.NO_CREDENTIALS);
|
|
94
89
|
}
|
|
95
90
|
break;
|
|
91
|
+
}
|
|
96
92
|
case 'oidc':
|
|
97
93
|
case 'userPool':
|
|
98
94
|
try {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
token = (
|
|
95
|
+
const token = (
|
|
102
96
|
await amplify.Auth.fetchAuthSession()
|
|
103
97
|
).tokens?.accessToken.toString();
|
|
104
98
|
|
|
@@ -139,8 +133,7 @@ export class InternalGraphQLAPIClass {
|
|
|
139
133
|
*/
|
|
140
134
|
getGraphqlOperationType(operation: GraphQLOperation): OperationTypeNode {
|
|
141
135
|
const doc = parse(operation);
|
|
142
|
-
const definitions =
|
|
143
|
-
doc.definitions as ReadonlyArray<OperationDefinitionNode>;
|
|
136
|
+
const definitions = doc.definitions as readonly OperationDefinitionNode[];
|
|
144
137
|
const [{ operation: operationType }] = definitions;
|
|
145
138
|
|
|
146
139
|
return operationType;
|
|
@@ -176,7 +169,7 @@ export class InternalGraphQLAPIClass {
|
|
|
176
169
|
|
|
177
170
|
switch (operationType) {
|
|
178
171
|
case 'query':
|
|
179
|
-
case 'mutation':
|
|
172
|
+
case 'mutation': {
|
|
180
173
|
const abortController = new AbortController();
|
|
181
174
|
|
|
182
175
|
let responsePromise: Promise<GraphQLResult<T>>;
|
|
@@ -215,7 +208,9 @@ export class InternalGraphQLAPIClass {
|
|
|
215
208
|
responsePromise,
|
|
216
209
|
abortController,
|
|
217
210
|
);
|
|
211
|
+
|
|
218
212
|
return responsePromise;
|
|
213
|
+
}
|
|
219
214
|
case 'subscription':
|
|
220
215
|
return this._graphqlSubscribe(
|
|
221
216
|
amplify as AmplifyClassV6,
|
|
@@ -238,7 +233,7 @@ export class InternalGraphQLAPIClass {
|
|
|
238
233
|
authToken?: string,
|
|
239
234
|
): Promise<GraphQLResult<T>> {
|
|
240
235
|
const {
|
|
241
|
-
region
|
|
236
|
+
region,
|
|
242
237
|
endpoint: appSyncGraphqlEndpoint,
|
|
243
238
|
customEndpoint,
|
|
244
239
|
customEndpointRegion,
|
|
@@ -356,7 +351,8 @@ export class InternalGraphQLAPIClass {
|
|
|
356
351
|
|
|
357
352
|
if (!endpoint) {
|
|
358
353
|
const error = new GraphQLError('No graphql endpoint provided.');
|
|
359
|
-
|
|
354
|
+
// TODO(Eslint): refactor this to throw an Error instead of a plain object
|
|
355
|
+
// eslint-disable-next-line no-throw-literal
|
|
360
356
|
throw {
|
|
361
357
|
data: {},
|
|
362
358
|
errors: [error],
|
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { Hub } from '@aws-amplify/core';
|
|
4
|
-
import { graphql, cancel, isCancelError } from './v6';
|
|
5
4
|
import {
|
|
5
|
+
CustomMutations,
|
|
6
|
+
CustomQueries,
|
|
6
7
|
EnumTypes,
|
|
7
8
|
ModelTypes,
|
|
8
|
-
CustomQueries,
|
|
9
|
-
CustomMutations,
|
|
10
9
|
} from '@aws-amplify/data-schema-types';
|
|
11
|
-
|
|
12
|
-
import { generateModelsProperty } from './utils/generateModelsProperty';
|
|
13
|
-
import { isApiGraphQLConfig } from './utils/isApiGraphQLProviderConfig';
|
|
14
|
-
import {
|
|
15
|
-
generateCustomQueriesProperty,
|
|
16
|
-
generateCustomMutationsProperty,
|
|
17
|
-
} from './generateCustomOperationsProperty';
|
|
10
|
+
|
|
18
11
|
import {
|
|
19
12
|
V6Client,
|
|
20
13
|
__amplify,
|
|
@@ -22,8 +15,17 @@ import {
|
|
|
22
15
|
__authToken,
|
|
23
16
|
__headers,
|
|
24
17
|
} from '../types';
|
|
18
|
+
|
|
19
|
+
import { cancel, graphql, isCancelError } from './v6';
|
|
20
|
+
import { generateEnumsProperty } from './utils/clientProperties/generateEnumsProperty';
|
|
21
|
+
import { generateModelsProperty } from './utils/clientProperties/generateModelsProperty';
|
|
22
|
+
import { isApiGraphQLConfig } from './utils/runtimeTypeGuards/isApiGraphQLProviderConfig';
|
|
23
|
+
import {
|
|
24
|
+
generateCustomMutationsProperty,
|
|
25
|
+
generateCustomQueriesProperty,
|
|
26
|
+
} from './generateCustomOperationsProperty';
|
|
25
27
|
import { ClientGenerationParams } from './types';
|
|
26
|
-
import { isConfigureEventWithResourceConfig } from './utils/isConfigureEventWithResourceConfig';
|
|
28
|
+
import { isConfigureEventWithResourceConfig } from './utils/runtimeTypeGuards/isConfigureEventWithResourceConfig';
|
|
27
29
|
|
|
28
30
|
/**
|
|
29
31
|
* @private
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
-
import {
|
|
4
|
-
import { V6Client, __authMode, __authToken, __amplify } from '../types';
|
|
5
|
-
|
|
6
|
-
import { customOpFactory } from './operations/custom';
|
|
3
|
+
import { CustomMutations, CustomQueries } from '@aws-amplify/data-schema-types';
|
|
7
4
|
import {
|
|
8
|
-
ModelIntrospectionSchema,
|
|
9
5
|
GraphQLProviderConfig,
|
|
6
|
+
ModelIntrospectionSchema,
|
|
10
7
|
} from '@aws-amplify/core/internals/utils';
|
|
11
8
|
|
|
9
|
+
import { V6Client, __amplify } from '../types';
|
|
10
|
+
|
|
11
|
+
import { customOpFactory } from './operations/custom';
|
|
12
|
+
|
|
12
13
|
type OpTypes = 'queries' | 'mutations';
|
|
13
14
|
|
|
14
15
|
type CustomOpsProperty<
|
|
@@ -59,7 +60,7 @@ export function generateCustomOperationsProperty<
|
|
|
59
60
|
modelIntrospection,
|
|
60
61
|
operationTypeMap[operationsType],
|
|
61
62
|
operation,
|
|
62
|
-
useContext
|
|
63
|
+
useContext,
|
|
63
64
|
);
|
|
64
65
|
}
|
|
65
66
|
|
|
@@ -2,10 +2,18 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
CustomOperation,
|
|
6
|
+
ModelIntrospectionSchema,
|
|
7
|
+
} from '@aws-amplify/core/internals/utils';
|
|
8
|
+
|
|
9
|
+
import {
|
|
7
10
|
authModeParams,
|
|
11
|
+
defaultSelectionSetForNonModelWithIR,
|
|
12
|
+
flattenItems,
|
|
13
|
+
generateSelectionSet,
|
|
8
14
|
getCustomHeaders,
|
|
15
|
+
initializeModel,
|
|
16
|
+
selectionSetIRToString,
|
|
9
17
|
} from '../APIClient';
|
|
10
18
|
import {
|
|
11
19
|
AuthModeParams,
|
|
@@ -17,13 +25,6 @@ import {
|
|
|
17
25
|
V6Client,
|
|
18
26
|
V6ClientSSRRequest,
|
|
19
27
|
} from '../../types';
|
|
20
|
-
import {
|
|
21
|
-
ModelIntrospectionSchema,
|
|
22
|
-
SchemaModel,
|
|
23
|
-
SchemaNonModel,
|
|
24
|
-
CustomOperation,
|
|
25
|
-
CustomOperationArgument,
|
|
26
|
-
} from '@aws-amplify/core/internals/utils';
|
|
27
28
|
|
|
28
29
|
/**
|
|
29
30
|
* Builds an operation function, embedded with all client and context data, that
|
|
@@ -165,9 +166,11 @@ function outerArguments(operation: CustomOperation): string {
|
|
|
165
166
|
const finalType = v.isArray
|
|
166
167
|
? `[${baseType}]${v.isArrayNullable ? '' : '!'}`
|
|
167
168
|
: baseType;
|
|
169
|
+
|
|
168
170
|
return `$${k}: ${finalType}`;
|
|
169
171
|
})
|
|
170
172
|
.join(', ');
|
|
173
|
+
|
|
171
174
|
return args.length > 0 ? `(${args})` : '';
|
|
172
175
|
}
|
|
173
176
|
|
|
@@ -192,30 +195,10 @@ function outerArguments(operation: CustomOperation): string {
|
|
|
192
195
|
*/
|
|
193
196
|
function innerArguments(operation: CustomOperation): string {
|
|
194
197
|
const args = Object.entries(operation.arguments)
|
|
195
|
-
.map(([k,
|
|
198
|
+
.map(([k, _]) => `${k}: $${k}`)
|
|
196
199
|
.join(', ');
|
|
197
|
-
return args.length > 0 ? `(${args})` : '';
|
|
198
|
-
}
|
|
199
200
|
|
|
200
|
-
|
|
201
|
-
* Accepts a Model or NonModel from generated introspection schema and
|
|
202
|
-
* generates the selection set string.
|
|
203
|
-
*
|
|
204
|
-
* @param nonModel Model or nonModel object from introspection schema.
|
|
205
|
-
* @returns String selection set.
|
|
206
|
-
*/
|
|
207
|
-
function modelishTypeSelectionSet(
|
|
208
|
-
nonModel: SchemaModel | SchemaNonModel,
|
|
209
|
-
): string {
|
|
210
|
-
return Object.values(nonModel.fields)
|
|
211
|
-
.filter(
|
|
212
|
-
field =>
|
|
213
|
-
hasStringField(field, 'type') ||
|
|
214
|
-
hasStringField(field.type, 'nonModel') ||
|
|
215
|
-
hasStringField(field.type, 'enum'),
|
|
216
|
-
)
|
|
217
|
-
.map(field => field.name)
|
|
218
|
-
.join(' ');
|
|
201
|
+
return args.length > 0 ? `(${args})` : '';
|
|
219
202
|
}
|
|
220
203
|
|
|
221
204
|
/**
|
|
@@ -251,11 +234,13 @@ function operationSelectionSet(
|
|
|
251
234
|
) {
|
|
252
235
|
return '';
|
|
253
236
|
} else if (hasStringField(operation.type, 'nonModel')) {
|
|
254
|
-
const
|
|
255
|
-
|
|
237
|
+
const nonModel = modelIntrospection.nonModels[operation.type.nonModel];
|
|
238
|
+
|
|
239
|
+
return `{${selectionSetIRToString(
|
|
240
|
+
defaultSelectionSetForNonModelWithIR(nonModel, modelIntrospection),
|
|
241
|
+
)}}`;
|
|
256
242
|
} else if (hasStringField(operation.type, 'model')) {
|
|
257
|
-
|
|
258
|
-
return `{${modelishTypeSelectionSet(nonModel)}}`;
|
|
243
|
+
return `{${generateSelectionSet(modelIntrospection, operation.type.model)}}`;
|
|
259
244
|
} else {
|
|
260
245
|
return '';
|
|
261
246
|
}
|
|
@@ -283,6 +268,7 @@ function operationVariables(
|
|
|
283
268
|
throw new Error(`${operation.name} requires arguments '${argDef.name}'`);
|
|
284
269
|
}
|
|
285
270
|
}
|
|
271
|
+
|
|
286
272
|
return variables;
|
|
287
273
|
}
|
|
288
274
|
|
|
@@ -2,13 +2,18 @@
|
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
|
|
4
4
|
import {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
ModelIntrospectionSchema,
|
|
6
|
+
SchemaModel,
|
|
7
|
+
} from '@aws-amplify/core/internals/utils';
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
ModelOperation,
|
|
11
|
+
authModeParams,
|
|
7
12
|
buildGraphQLVariables,
|
|
8
13
|
flattenItems,
|
|
9
|
-
|
|
10
|
-
ModelOperation,
|
|
14
|
+
generateGraphQLDocument,
|
|
11
15
|
getCustomHeaders,
|
|
16
|
+
initializeModel,
|
|
12
17
|
} from '../APIClient';
|
|
13
18
|
import {
|
|
14
19
|
AuthModeParams,
|
|
@@ -20,10 +25,6 @@ import {
|
|
|
20
25
|
V6Client,
|
|
21
26
|
V6ClientSSRRequest,
|
|
22
27
|
} from '../../types';
|
|
23
|
-
import {
|
|
24
|
-
ModelIntrospectionSchema,
|
|
25
|
-
SchemaModel,
|
|
26
|
-
} from '@aws-amplify/core/internals/utils';
|
|
27
28
|
|
|
28
29
|
export function getFactory(
|
|
29
30
|
client: ClientWithModels,
|