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