@aws-amplify/api-graphql 4.0.1-api-v6-models.01b2bb8.0 → 4.0.1-api-v6-models.c1977f8.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/lib/internals/APIClient.d.ts +2 -1
- package/lib/internals/APIClient.js +12 -5
- package/lib/internals/InternalGraphQLAPI.js +1 -1
- package/lib/internals/generateModelsProperty.js +25 -29
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/internals/APIClient.d.ts +2 -1
- package/lib-esm/internals/APIClient.js +12 -5
- package/lib-esm/internals/InternalGraphQLAPI.js +1 -1
- package/lib-esm/internals/generateModelsProperty.js +25 -29
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
- package/src/internals/APIClient.ts +28 -8
- package/src/internals/InternalGraphQLAPI.ts +1 -1
- package/src/internals/generateModelsProperty.ts +54 -37
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/api-graphql",
|
|
3
|
-
"version": "4.0.1-api-v6-models.
|
|
3
|
+
"version": "4.0.1-api-v6-models.c1977f8.0+c1977f8",
|
|
4
4
|
"description": "Api-graphql category of aws-amplify",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib-esm/index.js",
|
|
@@ -52,9 +52,9 @@
|
|
|
52
52
|
],
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@aws-amplify/amplify-api-next-types-alpha": "^0.2.0",
|
|
55
|
-
"@aws-amplify/api-rest": "4.0.1-api-v6-models.
|
|
56
|
-
"@aws-amplify/auth": "6.0.1-api-v6-models.
|
|
57
|
-
"@aws-amplify/core": "6.0.1-api-v6-models.
|
|
55
|
+
"@aws-amplify/api-rest": "4.0.1-api-v6-models.c1977f8.0+c1977f8",
|
|
56
|
+
"@aws-amplify/auth": "6.0.1-api-v6-models.c1977f8.0+c1977f8",
|
|
57
|
+
"@aws-amplify/core": "6.0.1-api-v6-models.c1977f8.0+c1977f8",
|
|
58
58
|
"@aws-sdk/types": "3.387.0",
|
|
59
59
|
"graphql": "15.8.0",
|
|
60
60
|
"rxjs": "^7.8.1",
|
|
@@ -126,5 +126,5 @@
|
|
|
126
126
|
"<rootDir>/__tests__"
|
|
127
127
|
]
|
|
128
128
|
},
|
|
129
|
-
"gitHead": "
|
|
129
|
+
"gitHead": "c1977f8efaae41b693495a2d6c53c503d0038e95"
|
|
130
130
|
}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { resolveOwnerFields } from '../utils/resolveOwnerFields';
|
|
4
|
+
import { GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
|
|
4
5
|
|
|
5
6
|
type ListArgs = { selectionSet?: string[]; filter?: {} };
|
|
6
7
|
|
|
8
|
+
type LazyLoadOptions = {
|
|
9
|
+
authMode?: GraphQLAuthMode;
|
|
10
|
+
authToken?: string | undefined;
|
|
11
|
+
};
|
|
12
|
+
|
|
7
13
|
const connectionType = {
|
|
8
14
|
HAS_ONE: 'HAS_ONE',
|
|
9
15
|
HAS_MANY: 'HAS_MANY',
|
|
@@ -41,7 +47,9 @@ export function initializeModel(
|
|
|
41
47
|
client: any,
|
|
42
48
|
modelName: string,
|
|
43
49
|
result: any[],
|
|
44
|
-
modelIntrospection: any
|
|
50
|
+
modelIntrospection: any,
|
|
51
|
+
authMode: GraphQLAuthMode,
|
|
52
|
+
authToken: string | undefined
|
|
45
53
|
): any[] {
|
|
46
54
|
const introModel = modelIntrospection.models[modelName];
|
|
47
55
|
const introModelFields = introModel.fields;
|
|
@@ -83,12 +91,18 @@ export function initializeModel(
|
|
|
83
91
|
{}
|
|
84
92
|
);
|
|
85
93
|
|
|
86
|
-
initializedRelationalFields[field] = () => {
|
|
94
|
+
initializedRelationalFields[field] = (options?: LazyLoadOptions) => {
|
|
87
95
|
if (record[targetNames[0]]) {
|
|
88
|
-
return client.models[relatedModelName].get(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
96
|
+
return client.models[relatedModelName].get(
|
|
97
|
+
{
|
|
98
|
+
[relatedModelPKFieldName]: record[targetNames[0]],
|
|
99
|
+
...sortKeyValues,
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
authMode: options?.authMode || authMode,
|
|
103
|
+
authToken: options?.authToken || authToken,
|
|
104
|
+
}
|
|
105
|
+
);
|
|
92
106
|
}
|
|
93
107
|
return undefined;
|
|
94
108
|
};
|
|
@@ -111,10 +125,14 @@ export function initializeModel(
|
|
|
111
125
|
return { [field]: { eq: record[parentSK[idx - 1]] } };
|
|
112
126
|
});
|
|
113
127
|
|
|
114
|
-
initializedRelationalFields[field] = (
|
|
128
|
+
initializedRelationalFields[field] = (
|
|
129
|
+
options?: LazyLoadOptions
|
|
130
|
+
) => {
|
|
115
131
|
if (record[parentPk]) {
|
|
116
132
|
return client.models[relatedModelName].list({
|
|
117
133
|
filter: { and: hasManyFilter },
|
|
134
|
+
authMode: options?.authMode || authMode,
|
|
135
|
+
authToken: options?.authToken || authToken,
|
|
118
136
|
});
|
|
119
137
|
}
|
|
120
138
|
return [];
|
|
@@ -130,10 +148,12 @@ export function initializeModel(
|
|
|
130
148
|
return { [field]: { eq: record[parentSK[idx - 1]] } };
|
|
131
149
|
});
|
|
132
150
|
|
|
133
|
-
initializedRelationalFields[field] = () => {
|
|
151
|
+
initializedRelationalFields[field] = (options?: LazyLoadOptions) => {
|
|
134
152
|
if (record[parentPk]) {
|
|
135
153
|
return client.models[relatedModelName].list({
|
|
136
154
|
filter: { and: hasManyFilter },
|
|
155
|
+
authMode: options?.authMode || authMode,
|
|
156
|
+
authToken: options?.authToken || authToken,
|
|
137
157
|
});
|
|
138
158
|
}
|
|
139
159
|
return [];
|
|
@@ -375,7 +375,7 @@ export class InternalGraphQLAPIClass {
|
|
|
375
375
|
variables,
|
|
376
376
|
appSyncGraphqlEndpoint: config?.endpoint,
|
|
377
377
|
region: config?.region,
|
|
378
|
-
authenticationType: config?.defaultAuthMode,
|
|
378
|
+
authenticationType: authMode || config?.defaultAuthMode,
|
|
379
379
|
apiKey: config?.apiKey,
|
|
380
380
|
additionalHeaders,
|
|
381
381
|
},
|
|
@@ -53,7 +53,12 @@ export function generateModelsProperty<T extends Record<any, any> = never>(
|
|
|
53
53
|
);
|
|
54
54
|
|
|
55
55
|
try {
|
|
56
|
+
const options: Record<string, any> = {};
|
|
57
|
+
if (args?.authMode) options.authMode = args?.authMode;
|
|
58
|
+
if (args?.authToken) options.authToken = args?.authToken;
|
|
59
|
+
|
|
56
60
|
const { data, extensions } = (await client.graphql({
|
|
61
|
+
...options,
|
|
57
62
|
query,
|
|
58
63
|
variables,
|
|
59
64
|
})) as any;
|
|
@@ -77,7 +82,9 @@ export function generateModelsProperty<T extends Record<any, any> = never>(
|
|
|
77
82
|
client,
|
|
78
83
|
name,
|
|
79
84
|
flattenedResult,
|
|
80
|
-
modelIntrospection
|
|
85
|
+
modelIntrospection,
|
|
86
|
+
options.authMode,
|
|
87
|
+
options.authToken
|
|
81
88
|
);
|
|
82
89
|
|
|
83
90
|
return {
|
|
@@ -105,7 +112,7 @@ export function generateModelsProperty<T extends Record<any, any> = never>(
|
|
|
105
112
|
}
|
|
106
113
|
};
|
|
107
114
|
} else if (['ONCREATE', 'ONUPDATE', 'ONDELETE'].includes(operation)) {
|
|
108
|
-
models[name][operationPrefix] = (
|
|
115
|
+
models[name][operationPrefix] = (args?: any) => {
|
|
109
116
|
const query = generateGraphQLDocument(
|
|
110
117
|
modelIntrospection.models,
|
|
111
118
|
name,
|
|
@@ -114,11 +121,16 @@ export function generateModelsProperty<T extends Record<any, any> = never>(
|
|
|
114
121
|
const variables = buildGraphQLVariables(
|
|
115
122
|
model,
|
|
116
123
|
operation,
|
|
117
|
-
|
|
124
|
+
args,
|
|
118
125
|
modelIntrospection
|
|
119
126
|
);
|
|
120
127
|
|
|
128
|
+
const options: Record<string, any> = {};
|
|
129
|
+
if (args?.authMode) options.authMode = args?.authMode;
|
|
130
|
+
if (args?.authToken) options.authToken = args?.authToken;
|
|
131
|
+
|
|
121
132
|
const observable = client.graphql({
|
|
133
|
+
...options,
|
|
122
134
|
query,
|
|
123
135
|
variables,
|
|
124
136
|
}) as GraphqlSubscriptionResult<object>;
|
|
@@ -126,12 +138,20 @@ export function generateModelsProperty<T extends Record<any, any> = never>(
|
|
|
126
138
|
return observable.pipe(
|
|
127
139
|
map(value => {
|
|
128
140
|
const [key] = Object.keys(value.data);
|
|
129
|
-
|
|
141
|
+
const [initialized] = initializeModel(
|
|
142
|
+
client,
|
|
143
|
+
name,
|
|
144
|
+
[value.data[key]],
|
|
145
|
+
modelIntrospection,
|
|
146
|
+
options?.authMode,
|
|
147
|
+
options?.authToken
|
|
148
|
+
);
|
|
149
|
+
return initialized;
|
|
130
150
|
})
|
|
131
151
|
);
|
|
132
152
|
};
|
|
133
153
|
} else if (operation === 'OBSERVE_QUERY') {
|
|
134
|
-
models[name][operationPrefix] = (arg?: any
|
|
154
|
+
models[name][operationPrefix] = (arg?: any) =>
|
|
135
155
|
new Observable(subscriber => {
|
|
136
156
|
// what we'll be sending to our subscribers
|
|
137
157
|
const items: object[] = [];
|
|
@@ -151,36 +171,30 @@ export function generateModelsProperty<T extends Record<any, any> = never>(
|
|
|
151
171
|
};
|
|
152
172
|
|
|
153
173
|
// start subscriptions
|
|
154
|
-
const onCreateSub = models[name]
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
receiveMessages({ item, type: 'delete' });
|
|
179
|
-
},
|
|
180
|
-
error(error) {
|
|
181
|
-
subscriber.error({ type: 'onDelete', error });
|
|
182
|
-
},
|
|
183
|
-
});
|
|
174
|
+
const onCreateSub = models[name].onCreate(arg).subscribe({
|
|
175
|
+
next(item) {
|
|
176
|
+
receiveMessages({ item, type: 'create' });
|
|
177
|
+
},
|
|
178
|
+
error(error) {
|
|
179
|
+
subscriber.error({ type: 'onCreate', error });
|
|
180
|
+
},
|
|
181
|
+
});
|
|
182
|
+
const onUpdateSub = models[name].onUpdate(arg).subscribe({
|
|
183
|
+
next(item) {
|
|
184
|
+
receiveMessages({ item, type: 'update' });
|
|
185
|
+
},
|
|
186
|
+
error(error) {
|
|
187
|
+
subscriber.error({ type: 'onUpdate', error });
|
|
188
|
+
},
|
|
189
|
+
});
|
|
190
|
+
const onDeleteSub = models[name].onDelete(arg).subscribe({
|
|
191
|
+
next(item) {
|
|
192
|
+
receiveMessages({ item, type: 'delete' });
|
|
193
|
+
},
|
|
194
|
+
error(error) {
|
|
195
|
+
subscriber.error({ type: 'onDelete', error });
|
|
196
|
+
},
|
|
197
|
+
});
|
|
184
198
|
|
|
185
199
|
// consumes a list of messages and sends a snapshot
|
|
186
200
|
function ingestMessages(messages: typeof messageQueue) {
|
|
@@ -226,7 +240,7 @@ export function generateModelsProperty<T extends Record<any, any> = never>(
|
|
|
226
240
|
data: page,
|
|
227
241
|
errors,
|
|
228
242
|
nextToken: _nextToken,
|
|
229
|
-
} = await models[name].list({ ...arg, nextToken }
|
|
243
|
+
} = await models[name].list({ ...arg, nextToken });
|
|
230
244
|
nextToken = _nextToken;
|
|
231
245
|
|
|
232
246
|
items.push(...page);
|
|
@@ -289,6 +303,7 @@ export function generateModelsProperty<T extends Record<any, any> = never>(
|
|
|
289
303
|
|
|
290
304
|
try {
|
|
291
305
|
const { data, extensions } = (await client.graphql({
|
|
306
|
+
...options,
|
|
292
307
|
query,
|
|
293
308
|
variables,
|
|
294
309
|
})) as any;
|
|
@@ -306,7 +321,9 @@ export function generateModelsProperty<T extends Record<any, any> = never>(
|
|
|
306
321
|
client,
|
|
307
322
|
name,
|
|
308
323
|
[flattenedResult],
|
|
309
|
-
modelIntrospection
|
|
324
|
+
modelIntrospection,
|
|
325
|
+
options?.authMode,
|
|
326
|
+
options?.authToken
|
|
310
327
|
);
|
|
311
328
|
|
|
312
329
|
return { data: initialized, extensions };
|