@aws-amplify/api-graphql 4.0.1-api-v6-models.c1977f8.0 → 4.0.1-api-v6-models.9351bcf.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 +1 -1
- package/lib/internals/generateClient.js +2 -0
- package/lib/internals/generateModelsProperty.js +28 -18
- package/lib/internals/types.d.ts +8 -0
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/index.d.ts +5 -0
- package/lib/types/index.js +3 -1
- package/lib-esm/internals/APIClient.d.ts +1 -1
- package/lib-esm/internals/generateClient.js +3 -1
- package/lib-esm/internals/generateModelsProperty.js +28 -18
- package/lib-esm/internals/types.d.ts +8 -0
- package/lib-esm/tsconfig.tsbuildinfo +1 -1
- package/lib-esm/types/index.d.ts +5 -0
- package/lib-esm/types/index.js +2 -0
- package/package.json +6 -6
- package/src/internals/APIClient.ts +1 -1
- package/src/internals/generateClient.ts +3 -1
- package/src/internals/generateModelsProperty.ts +43 -16
- package/src/internals/types.ts +9 -0
- package/src/types/index.ts +6 -0
package/lib-esm/types/index.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ import { Observable } from 'rxjs';
|
|
|
6
6
|
import { GraphQLAuthMode, DocumentType } from '@aws-amplify/core/internals/utils';
|
|
7
7
|
export { CONTROL_MSG, ConnectionState } from './PubSub';
|
|
8
8
|
export { SelectionSet } from '@aws-amplify/amplify-api-next-types-alpha';
|
|
9
|
+
export { CommonPublicClientOptions } from '../internals/types';
|
|
9
10
|
/**
|
|
10
11
|
* Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
|
|
11
12
|
*/
|
|
@@ -281,8 +282,12 @@ type ExcludeNeverFields<O> = {
|
|
|
281
282
|
[K in FilteredKeys<O>]: O[K];
|
|
282
283
|
};
|
|
283
284
|
export declare const __amplify: unique symbol;
|
|
285
|
+
export declare const __authMode: unique symbol;
|
|
286
|
+
export declare const __authToken: unique symbol;
|
|
284
287
|
export type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
|
|
285
288
|
[__amplify]: AmplifyClassV6;
|
|
289
|
+
[__authMode]?: GraphQLAuthMode;
|
|
290
|
+
[__authToken]?: string;
|
|
286
291
|
graphql: <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: {
|
|
287
292
|
[key: string]: string;
|
|
288
293
|
} | undefined) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
package/lib-esm/types/index.js
CHANGED
|
@@ -8,3 +8,5 @@ export var GraphQLAuthError;
|
|
|
8
8
|
GraphQLAuthError["NO_AUTH_TOKEN"] = "No auth token specified";
|
|
9
9
|
})(GraphQLAuthError || (GraphQLAuthError = {}));
|
|
10
10
|
export var __amplify = Symbol('amplify');
|
|
11
|
+
export var __authMode = Symbol('authMode');
|
|
12
|
+
export var __authToken = Symbol('authToken');
|
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.9351bcf.0+9351bcf",
|
|
4
4
|
"description": "Api-graphql category of aws-amplify",
|
|
5
5
|
"main": "./lib/index.js",
|
|
6
6
|
"module": "./lib-esm/index.js",
|
|
@@ -51,10 +51,10 @@
|
|
|
51
51
|
"internals"
|
|
52
52
|
],
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@aws-amplify/amplify-api-next-types-alpha": "^0.2.
|
|
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.
|
|
54
|
+
"@aws-amplify/amplify-api-next-types-alpha": "^0.2.4",
|
|
55
|
+
"@aws-amplify/api-rest": "4.0.1-api-v6-models.9351bcf.0+9351bcf",
|
|
56
|
+
"@aws-amplify/auth": "6.0.1-api-v6-models.9351bcf.0+9351bcf",
|
|
57
|
+
"@aws-amplify/core": "6.0.1-api-v6-models.9351bcf.0+9351bcf",
|
|
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": "9351bcfbeb9ec15f67fc6404ca192689a398d260"
|
|
130
130
|
}
|
|
@@ -48,7 +48,7 @@ export function initializeModel(
|
|
|
48
48
|
modelName: string,
|
|
49
49
|
result: any[],
|
|
50
50
|
modelIntrospection: any,
|
|
51
|
-
authMode: GraphQLAuthMode,
|
|
51
|
+
authMode: GraphQLAuthMode | undefined,
|
|
52
52
|
authToken: string | undefined
|
|
53
53
|
): any[] {
|
|
54
54
|
const introModel = modelIntrospection.models[modelName];
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
4
4
|
import { graphql, cancel, isCancelError } from './v6';
|
|
5
5
|
import { generateModelsProperty } from './generateModelsProperty';
|
|
6
|
-
import { V6Client, __amplify } from '../types';
|
|
6
|
+
import { V6Client, __amplify, __authMode, __authToken } from '../types';
|
|
7
7
|
import { ClientGenerationParams } from './types';
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -20,6 +20,8 @@ export function generateClient<T extends Record<any, any> = never>(
|
|
|
20
20
|
): V6Client<T> {
|
|
21
21
|
const client = {
|
|
22
22
|
[__amplify]: params.amplify,
|
|
23
|
+
[__authMode]: params.authMode,
|
|
24
|
+
[__authToken]: params.authToken,
|
|
23
25
|
graphql,
|
|
24
26
|
cancel,
|
|
25
27
|
isCancelError,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { ModelTypes } from '@aws-amplify/amplify-api-next-types-alpha';
|
|
4
|
+
import { GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
|
|
4
5
|
import {
|
|
5
6
|
initializeModel,
|
|
6
7
|
generateGraphQLDocument,
|
|
@@ -10,10 +11,39 @@ import {
|
|
|
10
11
|
flattenItems,
|
|
11
12
|
} from './APIClient';
|
|
12
13
|
import { ClientGenerationParams } from './types';
|
|
13
|
-
import {
|
|
14
|
+
import {
|
|
15
|
+
V6Client,
|
|
16
|
+
GraphqlSubscriptionResult,
|
|
17
|
+
__authMode,
|
|
18
|
+
__authToken,
|
|
19
|
+
} from '../types';
|
|
14
20
|
import { findIndexByFields, resolvePKFields } from '../utils';
|
|
15
21
|
import { Observable, map } from 'rxjs';
|
|
16
22
|
|
|
23
|
+
type AuthModeParams = {
|
|
24
|
+
authMode?: GraphQLAuthMode;
|
|
25
|
+
authToken?: string;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Produces a parameter object that can contains auth mode/token overrides
|
|
30
|
+
* only if present in either `options` (first) or configured on the `client`
|
|
31
|
+
* as a fallback.
|
|
32
|
+
*
|
|
33
|
+
* @param client Configured client from `generateClient`
|
|
34
|
+
* @param options Args/Options obect from call site.
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
function authModeParams(
|
|
38
|
+
client: V6Client,
|
|
39
|
+
options: AuthModeParams = {}
|
|
40
|
+
): AuthModeParams {
|
|
41
|
+
return {
|
|
42
|
+
authMode: options.authMode || client[__authMode],
|
|
43
|
+
authToken: options.authToken || client[__authToken],
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
|
|
17
47
|
export function generateModelsProperty<T extends Record<any, any> = never>(
|
|
18
48
|
client: V6Client,
|
|
19
49
|
params: ClientGenerationParams
|
|
@@ -53,12 +83,10 @@ export function generateModelsProperty<T extends Record<any, any> = never>(
|
|
|
53
83
|
);
|
|
54
84
|
|
|
55
85
|
try {
|
|
56
|
-
const
|
|
57
|
-
if (args?.authMode) options.authMode = args?.authMode;
|
|
58
|
-
if (args?.authToken) options.authToken = args?.authToken;
|
|
86
|
+
const auth = authModeParams(client, args);
|
|
59
87
|
|
|
60
88
|
const { data, extensions } = (await client.graphql({
|
|
61
|
-
...
|
|
89
|
+
...auth,
|
|
62
90
|
query,
|
|
63
91
|
variables,
|
|
64
92
|
})) as any;
|
|
@@ -83,8 +111,8 @@ export function generateModelsProperty<T extends Record<any, any> = never>(
|
|
|
83
111
|
name,
|
|
84
112
|
flattenedResult,
|
|
85
113
|
modelIntrospection,
|
|
86
|
-
|
|
87
|
-
|
|
114
|
+
auth.authMode,
|
|
115
|
+
auth.authToken
|
|
88
116
|
);
|
|
89
117
|
|
|
90
118
|
return {
|
|
@@ -125,12 +153,10 @@ export function generateModelsProperty<T extends Record<any, any> = never>(
|
|
|
125
153
|
modelIntrospection
|
|
126
154
|
);
|
|
127
155
|
|
|
128
|
-
const
|
|
129
|
-
if (args?.authMode) options.authMode = args?.authMode;
|
|
130
|
-
if (args?.authToken) options.authToken = args?.authToken;
|
|
156
|
+
const auth = authModeParams(client, args);
|
|
131
157
|
|
|
132
158
|
const observable = client.graphql({
|
|
133
|
-
...
|
|
159
|
+
...auth,
|
|
134
160
|
query,
|
|
135
161
|
variables,
|
|
136
162
|
}) as GraphqlSubscriptionResult<object>;
|
|
@@ -143,8 +169,8 @@ export function generateModelsProperty<T extends Record<any, any> = never>(
|
|
|
143
169
|
name,
|
|
144
170
|
[value.data[key]],
|
|
145
171
|
modelIntrospection,
|
|
146
|
-
|
|
147
|
-
|
|
172
|
+
auth.authMode,
|
|
173
|
+
auth.authToken
|
|
148
174
|
);
|
|
149
175
|
return initialized;
|
|
150
176
|
})
|
|
@@ -302,8 +328,9 @@ export function generateModelsProperty<T extends Record<any, any> = never>(
|
|
|
302
328
|
);
|
|
303
329
|
|
|
304
330
|
try {
|
|
331
|
+
const auth = authModeParams(client, options);
|
|
305
332
|
const { data, extensions } = (await client.graphql({
|
|
306
|
-
...
|
|
333
|
+
...auth,
|
|
307
334
|
query,
|
|
308
335
|
variables,
|
|
309
336
|
})) as any;
|
|
@@ -322,8 +349,8 @@ export function generateModelsProperty<T extends Record<any, any> = never>(
|
|
|
322
349
|
name,
|
|
323
350
|
[flattenedResult],
|
|
324
351
|
modelIntrospection,
|
|
325
|
-
|
|
326
|
-
|
|
352
|
+
auth.authMode,
|
|
353
|
+
auth.authToken
|
|
327
354
|
);
|
|
328
355
|
|
|
329
356
|
return { data: initialized, extensions };
|
package/src/internals/types.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
4
|
+
import { GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* @private
|
|
@@ -9,4 +10,12 @@ import { AmplifyClassV6 } from '@aws-amplify/core';
|
|
|
9
10
|
*/
|
|
10
11
|
export type ClientGenerationParams = {
|
|
11
12
|
amplify: AmplifyClassV6;
|
|
13
|
+
} & CommonPublicClientOptions;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Common options that can be used on public `generateClient()` interfaces.
|
|
17
|
+
*/
|
|
18
|
+
export type CommonPublicClientOptions = {
|
|
19
|
+
authMode?: GraphQLAuthMode;
|
|
20
|
+
authToken?: string;
|
|
12
21
|
};
|
package/src/types/index.ts
CHANGED
|
@@ -14,6 +14,8 @@ export { CONTROL_MSG, ConnectionState } from './PubSub';
|
|
|
14
14
|
|
|
15
15
|
export { SelectionSet } from '@aws-amplify/amplify-api-next-types-alpha';
|
|
16
16
|
|
|
17
|
+
export { CommonPublicClientOptions } from '../internals/types';
|
|
18
|
+
|
|
17
19
|
/**
|
|
18
20
|
* Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
|
|
19
21
|
*/
|
|
@@ -357,9 +359,13 @@ type ExcludeNeverFields<O> = {
|
|
|
357
359
|
};
|
|
358
360
|
|
|
359
361
|
export const __amplify = Symbol('amplify');
|
|
362
|
+
export const __authMode = Symbol('authMode');
|
|
363
|
+
export const __authToken = Symbol('authToken');
|
|
360
364
|
|
|
361
365
|
export type V6Client<T extends Record<any, any> = never> = ExcludeNeverFields<{
|
|
362
366
|
[__amplify]: AmplifyClassV6;
|
|
367
|
+
[__authMode]?: GraphQLAuthMode;
|
|
368
|
+
[__authToken]?: string;
|
|
363
369
|
graphql: <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(
|
|
364
370
|
options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>,
|
|
365
371
|
additionalHeaders?:
|