@aws-amplify/api-graphql 4.6.7-graphql-multi-client.27123f5.0 → 4.6.7-unstable.29b6c3f.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/internals/InternalGraphQLAPI.js +15 -23
- package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -1
- package/dist/cjs/internals/generateClient.js +16 -28
- package/dist/cjs/internals/generateClient.js.map +1 -1
- package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js +1 -11
- package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js.map +1 -1
- package/dist/cjs/internals/v6.js +2 -32
- package/dist/cjs/internals/v6.js.map +1 -1
- package/dist/cjs/server/generateClient.js +6 -4
- package/dist/cjs/server/generateClient.js.map +1 -1
- package/dist/cjs/types/index.js +1 -5
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/internals/InternalGraphQLAPI.d.ts +1 -1
- package/dist/esm/internals/InternalGraphQLAPI.mjs +15 -23
- package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
- package/dist/esm/internals/generateClient.d.ts +1 -1
- package/dist/esm/internals/generateClient.mjs +17 -29
- package/dist/esm/internals/generateClient.mjs.map +1 -1
- package/dist/esm/internals/index.d.ts +0 -1
- package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs +3 -25
- package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs.map +1 -1
- package/dist/esm/internals/types.d.ts +3 -18
- package/dist/esm/internals/v6.d.ts +2 -2
- package/dist/esm/internals/v6.mjs +2 -32
- package/dist/esm/internals/v6.mjs.map +1 -1
- package/dist/esm/server/generateClient.d.ts +1 -4
- package/dist/esm/server/generateClient.mjs +6 -4
- package/dist/esm/server/generateClient.mjs.map +1 -1
- package/dist/esm/types/index.d.ts +15 -59
- package/dist/esm/types/index.mjs +1 -5
- package/dist/esm/types/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/internals/InternalGraphQLAPI.ts +15 -46
- package/src/internals/generateClient.ts +19 -39
- package/src/internals/index.ts +0 -1
- package/src/internals/server/generateClientWithAmplifyInstance.ts +1 -18
- package/src/internals/types.ts +4 -23
- package/src/internals/v6.ts +5 -43
- package/src/server/generateClient.ts +12 -10
- package/src/types/index.ts +26 -90
|
@@ -4,21 +4,18 @@ import { DocumentNode, GraphQLError, Source } from 'graphql';
|
|
|
4
4
|
import { Observable } from 'rxjs';
|
|
5
5
|
import { DocumentType, GraphQLAuthMode } from '@aws-amplify/core/internals/utils';
|
|
6
6
|
import { AmplifyServer } from '@aws-amplify/core/internals/adapter-core';
|
|
7
|
-
import { CommonPublicClientOptions } from '../internals/types';
|
|
8
7
|
export { OperationTypeNode } from 'graphql';
|
|
9
8
|
export { CONTROL_MSG, ConnectionState } from './PubSub';
|
|
10
9
|
export { SelectionSet } from '@aws-amplify/data-schema/runtime';
|
|
11
|
-
export
|
|
10
|
+
export { CommonPublicClientOptions } from '../internals/types';
|
|
12
11
|
/**
|
|
13
12
|
* Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
|
|
14
13
|
*/
|
|
15
14
|
export interface GraphQLOptions {
|
|
16
15
|
query: string | DocumentNode;
|
|
17
|
-
endpoint?: string;
|
|
18
16
|
variables?: Record<string, DocumentType>;
|
|
19
17
|
authMode?: GraphQLAuthMode;
|
|
20
18
|
authToken?: string;
|
|
21
|
-
apiKey?: string;
|
|
22
19
|
/**
|
|
23
20
|
* @deprecated This property should not be used
|
|
24
21
|
*/
|
|
@@ -165,57 +162,16 @@ export type GraphQLOperation = Source | string;
|
|
|
165
162
|
* API V6 `graphql({options})` type that can leverage branded graphql `query`
|
|
166
163
|
* objects and fallback types.
|
|
167
164
|
*/
|
|
168
|
-
export
|
|
165
|
+
export interface GraphQLOptionsV6<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string> extends Record<string, unknown> {
|
|
169
166
|
query: TYPED_GQL_STRING | DocumentNode;
|
|
170
167
|
variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
171
168
|
authMode?: GraphQLAuthMode;
|
|
172
|
-
apiKey?: string;
|
|
173
|
-
authToken?: string;
|
|
174
|
-
/**
|
|
175
|
-
* @deprecated This property should not be used
|
|
176
|
-
*/
|
|
177
|
-
userAgentSuffix?: string;
|
|
178
|
-
} : {
|
|
179
|
-
query: TYPED_GQL_STRING | DocumentNode;
|
|
180
|
-
variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
181
|
-
authMode?: never;
|
|
182
|
-
apiKey?: never;
|
|
183
169
|
authToken?: string;
|
|
184
170
|
/**
|
|
185
171
|
* @deprecated This property should not be used
|
|
186
172
|
*/
|
|
187
173
|
userAgentSuffix?: string;
|
|
188
|
-
}
|
|
189
|
-
query: TYPED_GQL_STRING | DocumentNode;
|
|
190
|
-
variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
191
|
-
authMode: 'apiKey';
|
|
192
|
-
apiKey: string;
|
|
193
|
-
authToken?: string;
|
|
194
|
-
/**
|
|
195
|
-
* @deprecated This property should not be used
|
|
196
|
-
*/
|
|
197
|
-
userAgentSuffix?: string;
|
|
198
|
-
} | {
|
|
199
|
-
query: TYPED_GQL_STRING | DocumentNode;
|
|
200
|
-
variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
201
|
-
authMode: Exclude<GraphQLAuthMode, 'apiKey'>;
|
|
202
|
-
apiKey?: never;
|
|
203
|
-
authToken?: string;
|
|
204
|
-
/**
|
|
205
|
-
* @deprecated This property should not be used
|
|
206
|
-
*/
|
|
207
|
-
userAgentSuffix?: string;
|
|
208
|
-
} : {
|
|
209
|
-
query: TYPED_GQL_STRING | DocumentNode;
|
|
210
|
-
variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
211
|
-
authMode?: GraphQLAuthMode;
|
|
212
|
-
apiKey?: string;
|
|
213
|
-
authToken?: string;
|
|
214
|
-
/**
|
|
215
|
-
* @deprecated This property should not be used
|
|
216
|
-
*/
|
|
217
|
-
userAgentSuffix?: string;
|
|
218
|
-
};
|
|
174
|
+
}
|
|
219
175
|
/**
|
|
220
176
|
* Result type for `graphql()` operations that don't include any specific
|
|
221
177
|
* type information. The result could be either a `Promise` or `Subscription`.
|
|
@@ -319,28 +275,26 @@ export type GeneratedSubscription<InputType, OutputType> = string & {
|
|
|
319
275
|
export declare const __amplify: unique symbol;
|
|
320
276
|
export declare const __authMode: unique symbol;
|
|
321
277
|
export declare const __authToken: unique symbol;
|
|
322
|
-
export declare const __apiKey: unique symbol;
|
|
323
278
|
export declare const __headers: unique symbol;
|
|
324
|
-
export declare const __endpoint: unique symbol;
|
|
325
279
|
export declare function getInternals(client: BaseClient): ClientInternals;
|
|
326
280
|
export type ClientWithModels = V6Client | V6ClientSSRRequest | V6ClientSSRCookies;
|
|
327
|
-
export type V6Client<T extends Record<any, any> = never
|
|
328
|
-
graphql: GraphQLMethod
|
|
281
|
+
export type V6Client<T extends Record<any, any> = never> = {
|
|
282
|
+
graphql: GraphQLMethod;
|
|
329
283
|
cancel(promise: Promise<any>, message?: string): boolean;
|
|
330
284
|
isCancelError(error: any): boolean;
|
|
331
285
|
} & ClientExtensions<T>;
|
|
332
|
-
export type V6ClientSSRRequest<T extends Record<any, any> = never
|
|
333
|
-
graphql: GraphQLMethodSSR
|
|
286
|
+
export type V6ClientSSRRequest<T extends Record<any, any> = never> = {
|
|
287
|
+
graphql: GraphQLMethodSSR;
|
|
334
288
|
cancel(promise: Promise<any>, message?: string): boolean;
|
|
335
289
|
isCancelError(error: any): boolean;
|
|
336
290
|
} & ClientExtensionsSSRRequest<T>;
|
|
337
|
-
export type V6ClientSSRCookies<T extends Record<any, any> = never
|
|
338
|
-
graphql: GraphQLMethod
|
|
291
|
+
export type V6ClientSSRCookies<T extends Record<any, any> = never> = {
|
|
292
|
+
graphql: GraphQLMethod;
|
|
339
293
|
cancel(promise: Promise<any>, message?: string): boolean;
|
|
340
294
|
isCancelError(error: any): boolean;
|
|
341
295
|
} & ClientExtensionsSSRCookies<T>;
|
|
342
|
-
export type GraphQLMethod
|
|
343
|
-
export type GraphQLMethodSSR
|
|
296
|
+
export type GraphQLMethod = <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: CustomHeaders | undefined) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
297
|
+
export type GraphQLMethodSSR = <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(contextSpec: AmplifyServer.ContextSpec, options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>, additionalHeaders?: CustomHeaders | undefined) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
344
298
|
/**
|
|
345
299
|
* @private
|
|
346
300
|
*
|
|
@@ -361,6 +315,8 @@ export interface AuthModeParams extends Record<string, unknown> {
|
|
|
361
315
|
authMode?: GraphQLAuthMode;
|
|
362
316
|
authToken?: string;
|
|
363
317
|
}
|
|
364
|
-
export
|
|
318
|
+
export interface GenerateServerClientParams {
|
|
365
319
|
config: ResourcesConfig;
|
|
366
|
-
|
|
320
|
+
authMode?: GraphQLAuthMode;
|
|
321
|
+
authToken?: string;
|
|
322
|
+
}
|
package/dist/esm/types/index.mjs
CHANGED
|
@@ -11,20 +11,16 @@ var GraphQLAuthError;
|
|
|
11
11
|
const __amplify = Symbol('amplify');
|
|
12
12
|
const __authMode = Symbol('authMode');
|
|
13
13
|
const __authToken = Symbol('authToken');
|
|
14
|
-
const __apiKey = Symbol('apiKey');
|
|
15
14
|
const __headers = Symbol('headers');
|
|
16
|
-
const __endpoint = Symbol('endpoint');
|
|
17
15
|
function getInternals(client) {
|
|
18
16
|
const c = client;
|
|
19
17
|
return {
|
|
20
18
|
amplify: c[__amplify],
|
|
21
|
-
apiKey: c[__apiKey],
|
|
22
19
|
authMode: c[__authMode],
|
|
23
20
|
authToken: c[__authToken],
|
|
24
|
-
endpoint: c[__endpoint],
|
|
25
21
|
headers: c[__headers],
|
|
26
22
|
};
|
|
27
23
|
}
|
|
28
24
|
|
|
29
|
-
export { GraphQLAuthError, __amplify,
|
|
25
|
+
export { GraphQLAuthError, __amplify, __authMode, __authToken, __headers, getInternals };
|
|
30
26
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sources":["../../../src/types/index.ts"],"sourcesContent":["export { CONTROL_MSG, ConnectionState } from './PubSub';\nexport var GraphQLAuthError;\n(function (GraphQLAuthError) {\n GraphQLAuthError[\"NO_API_KEY\"] = \"No api-key configured\";\n GraphQLAuthError[\"NO_CURRENT_USER\"] = \"No current user\";\n GraphQLAuthError[\"NO_CREDENTIALS\"] = \"No credentials\";\n GraphQLAuthError[\"NO_FEDERATED_JWT\"] = \"No federated jwt\";\n GraphQLAuthError[\"NO_AUTH_TOKEN\"] = \"No auth token specified\";\n})(GraphQLAuthError || (GraphQLAuthError = {}));\nexport const __amplify = Symbol('amplify');\nexport const __authMode = Symbol('authMode');\nexport const __authToken = Symbol('authToken');\nexport const
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":["../../../src/types/index.ts"],"sourcesContent":["export { CONTROL_MSG, ConnectionState } from './PubSub';\nexport var GraphQLAuthError;\n(function (GraphQLAuthError) {\n GraphQLAuthError[\"NO_API_KEY\"] = \"No api-key configured\";\n GraphQLAuthError[\"NO_CURRENT_USER\"] = \"No current user\";\n GraphQLAuthError[\"NO_CREDENTIALS\"] = \"No credentials\";\n GraphQLAuthError[\"NO_FEDERATED_JWT\"] = \"No federated jwt\";\n GraphQLAuthError[\"NO_AUTH_TOKEN\"] = \"No auth token specified\";\n})(GraphQLAuthError || (GraphQLAuthError = {}));\nexport const __amplify = Symbol('amplify');\nexport const __authMode = Symbol('authMode');\nexport const __authToken = Symbol('authToken');\nexport const __headers = Symbol('headers');\nexport function getInternals(client) {\n const c = client;\n return {\n amplify: c[__amplify],\n authMode: c[__authMode],\n authToken: c[__authToken],\n headers: c[__headers],\n };\n}\n"],"names":[],"mappings":";;AACU,IAAC,iBAAiB;AAC5B,CAAC,UAAU,gBAAgB,EAAE;AAC7B,IAAI,gBAAgB,CAAC,YAAY,CAAC,GAAG,uBAAuB,CAAC;AAC7D,IAAI,gBAAgB,CAAC,iBAAiB,CAAC,GAAG,iBAAiB,CAAC;AAC5D,IAAI,gBAAgB,CAAC,gBAAgB,CAAC,GAAG,gBAAgB,CAAC;AAC1D,IAAI,gBAAgB,CAAC,kBAAkB,CAAC,GAAG,kBAAkB,CAAC;AAC9D,IAAI,gBAAgB,CAAC,eAAe,CAAC,GAAG,yBAAyB,CAAC;AAClE,CAAC,EAAE,gBAAgB,KAAK,gBAAgB,GAAG,EAAE,CAAC,CAAC,CAAC;AACpC,MAAC,SAAS,GAAG,MAAM,CAAC,SAAS,EAAE;AAC/B,MAAC,UAAU,GAAG,MAAM,CAAC,UAAU,EAAE;AACjC,MAAC,WAAW,GAAG,MAAM,CAAC,WAAW,EAAE;AACnC,MAAC,SAAS,GAAG,MAAM,CAAC,SAAS,EAAE;AACpC,SAAS,YAAY,CAAC,MAAM,EAAE;AACrC,IAAI,MAAM,CAAC,GAAG,MAAM,CAAC;AACrB,IAAI,OAAO;AACX,QAAQ,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC;AAC7B,QAAQ,QAAQ,EAAE,CAAC,CAAC,UAAU,CAAC;AAC/B,QAAQ,SAAS,EAAE,CAAC,CAAC,WAAW,CAAC;AACjC,QAAQ,OAAO,EAAE,CAAC,CAAC,SAAS,CAAC;AAC7B,KAAK,CAAC;AACN;;;;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/api-graphql",
|
|
3
|
-
"version": "4.6.7-
|
|
3
|
+
"version": "4.6.7-unstable.29b6c3f.0+29b6c3f",
|
|
4
4
|
"description": "Api-graphql category of aws-amplify",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.mjs",
|
|
@@ -84,8 +84,8 @@
|
|
|
84
84
|
"server"
|
|
85
85
|
],
|
|
86
86
|
"dependencies": {
|
|
87
|
-
"@aws-amplify/api-rest": "4.0.64-
|
|
88
|
-
"@aws-amplify/core": "6.7.4-
|
|
87
|
+
"@aws-amplify/api-rest": "4.0.64-unstable.29b6c3f.0+29b6c3f",
|
|
88
|
+
"@aws-amplify/core": "6.7.4-unstable.29b6c3f.0+29b6c3f",
|
|
89
89
|
"@aws-amplify/data-schema": "^1.7.0",
|
|
90
90
|
"@aws-sdk/types": "3.387.0",
|
|
91
91
|
"graphql": "15.8.0",
|
|
@@ -101,5 +101,5 @@
|
|
|
101
101
|
"limit": "91.7 kB"
|
|
102
102
|
}
|
|
103
103
|
],
|
|
104
|
-
"gitHead": "
|
|
104
|
+
"gitHead": "29b6c3fd373e394d30950b9f238fcb9c6bd48a03"
|
|
105
105
|
}
|
|
@@ -52,7 +52,7 @@ export class InternalGraphQLAPIClass {
|
|
|
52
52
|
/**
|
|
53
53
|
* @private
|
|
54
54
|
*/
|
|
55
|
-
private appSyncRealTime = new
|
|
55
|
+
private appSyncRealTime = new AWSAppSyncRealTimeProvider();
|
|
56
56
|
|
|
57
57
|
private _api = {
|
|
58
58
|
post,
|
|
@@ -88,14 +88,7 @@ export class InternalGraphQLAPIClass {
|
|
|
88
88
|
amplify:
|
|
89
89
|
| AmplifyClassV6
|
|
90
90
|
| ((fn: (amplify: any) => Promise<any>) => Promise<AmplifyClassV6>),
|
|
91
|
-
{
|
|
92
|
-
query: paramQuery,
|
|
93
|
-
variables = {},
|
|
94
|
-
authMode,
|
|
95
|
-
authToken,
|
|
96
|
-
endpoint,
|
|
97
|
-
apiKey,
|
|
98
|
-
}: GraphQLOptions,
|
|
91
|
+
{ query: paramQuery, variables = {}, authMode, authToken }: GraphQLOptions,
|
|
99
92
|
additionalHeaders?: CustomHeaders,
|
|
100
93
|
customUserAgentDetails?: CustomUserAgentDetails,
|
|
101
94
|
): Observable<GraphQLResult<T>> | Promise<GraphQLResult<T>> {
|
|
@@ -122,7 +115,7 @@ export class InternalGraphQLAPIClass {
|
|
|
122
115
|
if (isAmplifyInstance(amplify)) {
|
|
123
116
|
responsePromise = this._graphql<T>(
|
|
124
117
|
amplify,
|
|
125
|
-
{ query, variables, authMode
|
|
118
|
+
{ query, variables, authMode },
|
|
126
119
|
headers,
|
|
127
120
|
abortController,
|
|
128
121
|
customUserAgentDetails,
|
|
@@ -134,7 +127,7 @@ export class InternalGraphQLAPIClass {
|
|
|
134
127
|
const wrapper = async (amplifyInstance: AmplifyClassV6) => {
|
|
135
128
|
const result = await this._graphql<T>(
|
|
136
129
|
amplifyInstance,
|
|
137
|
-
{ query, variables, authMode
|
|
130
|
+
{ query, variables, authMode },
|
|
138
131
|
headers,
|
|
139
132
|
abortController,
|
|
140
133
|
customUserAgentDetails,
|
|
@@ -159,7 +152,7 @@ export class InternalGraphQLAPIClass {
|
|
|
159
152
|
case 'subscription':
|
|
160
153
|
return this._graphqlSubscribe(
|
|
161
154
|
amplify as AmplifyClassV6,
|
|
162
|
-
{ query, variables, authMode
|
|
155
|
+
{ query, variables, authMode },
|
|
163
156
|
headers,
|
|
164
157
|
customUserAgentDetails,
|
|
165
158
|
authToken,
|
|
@@ -171,13 +164,7 @@ export class InternalGraphQLAPIClass {
|
|
|
171
164
|
|
|
172
165
|
private async _graphql<T = any>(
|
|
173
166
|
amplify: AmplifyClassV6,
|
|
174
|
-
{
|
|
175
|
-
query,
|
|
176
|
-
variables,
|
|
177
|
-
authMode: authModeOverride,
|
|
178
|
-
endpoint: endpointOverride,
|
|
179
|
-
apiKey: apiKeyOverride,
|
|
180
|
-
}: GraphQLOptions,
|
|
167
|
+
{ query, variables, authMode: explicitAuthMode }: GraphQLOptions,
|
|
181
168
|
additionalHeaders: CustomHeaders = {},
|
|
182
169
|
abortController: AbortController,
|
|
183
170
|
customUserAgentDetails?: CustomUserAgentDetails,
|
|
@@ -192,7 +179,7 @@ export class InternalGraphQLAPIClass {
|
|
|
192
179
|
defaultAuthMode,
|
|
193
180
|
} = resolveConfig(amplify);
|
|
194
181
|
|
|
195
|
-
const initialAuthMode =
|
|
182
|
+
const initialAuthMode = explicitAuthMode || defaultAuthMode || 'iam';
|
|
196
183
|
// identityPool is an alias for iam. TODO: remove 'iam' in v7
|
|
197
184
|
const authMode =
|
|
198
185
|
initialAuthMode === 'identityPool' ? 'iam' : initialAuthMode;
|
|
@@ -218,7 +205,7 @@ export class InternalGraphQLAPIClass {
|
|
|
218
205
|
const requestOptions: RequestOptions = {
|
|
219
206
|
method: 'POST',
|
|
220
207
|
url: new AmplifyUrl(
|
|
221
|
-
|
|
208
|
+
customEndpoint || appSyncGraphqlEndpoint || '',
|
|
222
209
|
).toString(),
|
|
223
210
|
queryString: print(query as DocumentNode),
|
|
224
211
|
};
|
|
@@ -239,7 +226,7 @@ export class InternalGraphQLAPIClass {
|
|
|
239
226
|
const authHeaders = await headerBasedAuth(
|
|
240
227
|
amplify,
|
|
241
228
|
authMode,
|
|
242
|
-
|
|
229
|
+
apiKey,
|
|
243
230
|
additionalCustomHeaders,
|
|
244
231
|
);
|
|
245
232
|
|
|
@@ -295,8 +282,7 @@ export class InternalGraphQLAPIClass {
|
|
|
295
282
|
};
|
|
296
283
|
}
|
|
297
284
|
|
|
298
|
-
const endpoint =
|
|
299
|
-
endpointOverride || customEndpoint || appSyncGraphqlEndpoint;
|
|
285
|
+
const endpoint = customEndpoint || appSyncGraphqlEndpoint;
|
|
300
286
|
|
|
301
287
|
if (!endpoint) {
|
|
302
288
|
throw createGraphQLResultWithError<T>(new GraphQLApiError(NO_ENDPOINT));
|
|
@@ -355,13 +341,7 @@ export class InternalGraphQLAPIClass {
|
|
|
355
341
|
|
|
356
342
|
private _graphqlSubscribe(
|
|
357
343
|
amplify: AmplifyClassV6,
|
|
358
|
-
{
|
|
359
|
-
query,
|
|
360
|
-
variables,
|
|
361
|
-
authMode: authModeOverride,
|
|
362
|
-
apiKey: apiKeyOverride,
|
|
363
|
-
endpoint,
|
|
364
|
-
}: GraphQLOptions,
|
|
344
|
+
{ query, variables, authMode: explicitAuthMode }: GraphQLOptions,
|
|
365
345
|
additionalHeaders: CustomHeaders = {},
|
|
366
346
|
customUserAgentDetails?: CustomUserAgentDetails,
|
|
367
347
|
authToken?: string,
|
|
@@ -369,7 +349,7 @@ export class InternalGraphQLAPIClass {
|
|
|
369
349
|
const config = resolveConfig(amplify);
|
|
370
350
|
|
|
371
351
|
const initialAuthMode =
|
|
372
|
-
|
|
352
|
+
explicitAuthMode || config?.defaultAuthMode || 'iam';
|
|
373
353
|
// identityPool is an alias for iam. TODO: remove 'iam' in v7
|
|
374
354
|
const authMode =
|
|
375
355
|
initialAuthMode === 'identityPool' ? 'iam' : initialAuthMode;
|
|
@@ -384,26 +364,15 @@ export class InternalGraphQLAPIClass {
|
|
|
384
364
|
*/
|
|
385
365
|
const { headers: libraryConfigHeaders } = resolveLibraryOptions(amplify);
|
|
386
366
|
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
// TODO: This could probably be an exception. But, lots of tests rely on
|
|
390
|
-
// attempting to connect to nowhere. So, I'm treating as the opposite of
|
|
391
|
-
// a Chesterton's fence for now. (A fence I shouldn't build, because I don't
|
|
392
|
-
// know why somethings depends on its absence!)
|
|
393
|
-
const memoKey = appSyncGraphqlEndpoint ?? 'none';
|
|
394
|
-
const realtimeProvider =
|
|
395
|
-
this.appSyncRealTime.get(memoKey) ?? new AWSAppSyncRealTimeProvider();
|
|
396
|
-
this.appSyncRealTime.set(memoKey, realtimeProvider);
|
|
397
|
-
|
|
398
|
-
return realtimeProvider
|
|
367
|
+
return this.appSyncRealTime
|
|
399
368
|
.subscribe(
|
|
400
369
|
{
|
|
401
370
|
query: print(query as DocumentNode),
|
|
402
371
|
variables,
|
|
403
|
-
appSyncGraphqlEndpoint,
|
|
372
|
+
appSyncGraphqlEndpoint: config?.endpoint,
|
|
404
373
|
region: config?.region,
|
|
405
374
|
authenticationType: authMode,
|
|
406
|
-
apiKey:
|
|
375
|
+
apiKey: config?.apiKey,
|
|
407
376
|
additionalHeaders,
|
|
408
377
|
authToken,
|
|
409
378
|
libraryConfigHeaders,
|
|
@@ -13,10 +13,8 @@ import {
|
|
|
13
13
|
import {
|
|
14
14
|
V6Client,
|
|
15
15
|
__amplify,
|
|
16
|
-
__apiKey,
|
|
17
16
|
__authMode,
|
|
18
17
|
__authToken,
|
|
19
|
-
__endpoint,
|
|
20
18
|
__headers,
|
|
21
19
|
getInternals,
|
|
22
20
|
} from '../types';
|
|
@@ -35,16 +33,13 @@ import { ClientGenerationParams } from './types';
|
|
|
35
33
|
* @param params
|
|
36
34
|
* @returns
|
|
37
35
|
*/
|
|
38
|
-
export function generateClient<
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
>(params: Options): V6Client<T, Options> {
|
|
36
|
+
export function generateClient<T extends Record<any, any> = never>(
|
|
37
|
+
params: ClientGenerationParams,
|
|
38
|
+
): V6Client<T> {
|
|
42
39
|
const client = {
|
|
43
40
|
[__amplify]: params.amplify,
|
|
44
41
|
[__authMode]: params.authMode,
|
|
45
42
|
[__authToken]: params.authToken,
|
|
46
|
-
[__apiKey]: 'apiKey' in params ? params.apiKey : undefined,
|
|
47
|
-
[__endpoint]: 'endpoint' in params ? params.endpoint : undefined,
|
|
48
43
|
[__headers]: params.headers,
|
|
49
44
|
graphql,
|
|
50
45
|
cancel,
|
|
@@ -58,37 +53,22 @@ export function generateClient<
|
|
|
58
53
|
|
|
59
54
|
const apiGraphqlConfig = params.amplify.getConfig().API?.GraphQL;
|
|
60
55
|
|
|
61
|
-
if (
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
} else {
|
|
78
|
-
// This happens when the `Amplify.configure()` call gets evaluated after the `generateClient()` call.
|
|
79
|
-
//
|
|
80
|
-
// Cause: when the `generateClient()` and the `Amplify.configure()` calls are located in
|
|
81
|
-
// different source files, script bundlers may randomly arrange their orders in the production
|
|
82
|
-
// bundle.
|
|
83
|
-
//
|
|
84
|
-
// With the current implementation, the `client.models` instance created by `generateClient()`
|
|
85
|
-
// will be rebuilt on every `Amplify.configure()` call that's provided with a valid GraphQL
|
|
86
|
-
// provider configuration.
|
|
87
|
-
//
|
|
88
|
-
// TODO: revisit, and reverify this approach when enabling multiple clients for multi-endpoints
|
|
89
|
-
// configuration.
|
|
90
|
-
generateModelsPropertyOnAmplifyConfigure(client);
|
|
91
|
-
}
|
|
56
|
+
if (isApiGraphQLConfig(apiGraphqlConfig)) {
|
|
57
|
+
addSchemaToClient(client, apiGraphqlConfig, getInternals);
|
|
58
|
+
} else {
|
|
59
|
+
// This happens when the `Amplify.configure()` call gets evaluated after the `generateClient()` call.
|
|
60
|
+
//
|
|
61
|
+
// Cause: when the `generateClient()` and the `Amplify.configure()` calls are located in
|
|
62
|
+
// different source files, script bundlers may randomly arrange their orders in the production
|
|
63
|
+
// bundle.
|
|
64
|
+
//
|
|
65
|
+
// With the current implementation, the `client.models` instance created by `generateClient()`
|
|
66
|
+
// will be rebuilt on every `Amplify.configure()` call that's provided with a valid GraphQL
|
|
67
|
+
// provider configuration.
|
|
68
|
+
//
|
|
69
|
+
// TODO: revisit, and reverify this approach when enabling multiple clients for multi-endpoints
|
|
70
|
+
// configuration.
|
|
71
|
+
generateModelsPropertyOnAmplifyConfigure(client);
|
|
92
72
|
}
|
|
93
73
|
|
|
94
74
|
return client as any;
|
package/src/internals/index.ts
CHANGED
|
@@ -9,10 +9,8 @@ import {
|
|
|
9
9
|
V6ClientSSRCookies,
|
|
10
10
|
V6ClientSSRRequest,
|
|
11
11
|
__amplify,
|
|
12
|
-
__apiKey,
|
|
13
12
|
__authMode,
|
|
14
13
|
__authToken,
|
|
15
|
-
__endpoint,
|
|
16
14
|
__headers,
|
|
17
15
|
getInternals,
|
|
18
16
|
} from '../../types';
|
|
@@ -42,8 +40,6 @@ export function generateClientWithAmplifyInstance<
|
|
|
42
40
|
[__amplify]: params.amplify,
|
|
43
41
|
[__authMode]: params.authMode,
|
|
44
42
|
[__authToken]: params.authToken,
|
|
45
|
-
[__apiKey]: 'apiKey' in params ? params.apiKey : undefined,
|
|
46
|
-
[__endpoint]: 'endpoint' in params ? params.endpoint : undefined,
|
|
47
43
|
[__headers]: params.headers,
|
|
48
44
|
graphql,
|
|
49
45
|
cancel,
|
|
@@ -52,20 +48,7 @@ export function generateClientWithAmplifyInstance<
|
|
|
52
48
|
|
|
53
49
|
const apiGraphqlConfig = params.config?.API?.GraphQL;
|
|
54
50
|
|
|
55
|
-
if (
|
|
56
|
-
if (!client[__authMode]) {
|
|
57
|
-
throw new Error(
|
|
58
|
-
'generateClient() requires an explicit `authMode` when `endpoint` is provided.',
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
if (client[__authMode] === 'apiKey' && !client[__apiKey]) {
|
|
62
|
-
throw new Error(
|
|
63
|
-
"generateClient() requires an explicit `apiKey` when `endpoint` is provided and `authMode = 'apiKey'`.",
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (!client[__endpoint] && isApiGraphQLConfig(apiGraphqlConfig)) {
|
|
51
|
+
if (isApiGraphQLConfig(apiGraphqlConfig)) {
|
|
69
52
|
addSchemaToClientWithInstance<T>(client, params, getInternals);
|
|
70
53
|
}
|
|
71
54
|
|
package/src/internals/types.ts
CHANGED
|
@@ -13,30 +13,11 @@ export type ClientGenerationParams = {
|
|
|
13
13
|
amplify: AmplifyClassV6;
|
|
14
14
|
} & CommonPublicClientOptions;
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
/**
|
|
17
|
+
* Common options that can be used on public `generateClient()` interfaces.
|
|
18
|
+
*/
|
|
19
|
+
export interface CommonPublicClientOptions {
|
|
18
20
|
authMode?: GraphQLAuthMode;
|
|
19
|
-
apiKey?: string;
|
|
20
21
|
authToken?: string;
|
|
21
22
|
headers?: CustomHeaders;
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Common options that can be used on public `generateClient()` interfaces.
|
|
26
|
-
*/
|
|
27
|
-
export type CommonPublicClientOptions =
|
|
28
|
-
| DefaultCommonClientOptions
|
|
29
|
-
| {
|
|
30
|
-
endpoint: string;
|
|
31
|
-
authMode: 'apiKey';
|
|
32
|
-
apiKey: string;
|
|
33
|
-
authToken?: string;
|
|
34
|
-
headers?: CustomHeaders;
|
|
35
|
-
}
|
|
36
|
-
| {
|
|
37
|
-
endpoint: string;
|
|
38
|
-
authMode: Exclude<GraphQLAuthMode, 'apiKey'>;
|
|
39
|
-
apiKey?: string;
|
|
40
|
-
authToken?: string;
|
|
41
|
-
headers?: CustomHeaders;
|
|
42
|
-
};
|
package/src/internals/v6.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { CustomHeaders } from '@aws-amplify/data-schema/runtime';
|
|
|
4
4
|
|
|
5
5
|
import { GraphQLAPI } from '../GraphQLAPI';
|
|
6
6
|
import {
|
|
7
|
-
|
|
7
|
+
GraphQLOptions,
|
|
8
8
|
GraphQLOptionsV6,
|
|
9
9
|
GraphQLResponseV6,
|
|
10
10
|
V6Client,
|
|
@@ -98,51 +98,15 @@ import {
|
|
|
98
98
|
export function graphql<
|
|
99
99
|
FALLBACK_TYPES = unknown,
|
|
100
100
|
TYPED_GQL_STRING extends string = string,
|
|
101
|
-
Options extends CommonPublicClientOptions = object,
|
|
102
101
|
>(
|
|
103
102
|
this: V6Client,
|
|
104
|
-
options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING
|
|
103
|
+
options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>,
|
|
105
104
|
additionalHeaders?: CustomHeaders,
|
|
106
105
|
): GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING> {
|
|
107
106
|
// inject client-level auth
|
|
108
107
|
const internals = getInternals(this as any);
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* The custom `endpoint` specific to the client
|
|
112
|
-
*/
|
|
113
|
-
const clientEndpoint: string = (internals as any).endpoint;
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* The `authMode` specific to the client.
|
|
117
|
-
*/
|
|
118
|
-
const clientAuthMode = internals.authMode;
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* The `apiKey` specific to the client.
|
|
122
|
-
*/
|
|
123
|
-
const clientApiKey = (internals as any).apiKey;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* The most specific `authMode` wins. Setting an `endpoint` value without also
|
|
127
|
-
* setting an `authMode` value is invalid. This helps to prevent customers apps
|
|
128
|
-
* from unexpectedly sending auth details to endpoints the auth details do not
|
|
129
|
-
* belong to.
|
|
130
|
-
*
|
|
131
|
-
* This is especially pronounced for `apiKey`. When both an `endpoint` *and*
|
|
132
|
-
* `authMode: 'apiKey'` are provided, an explicit `apiKey` override is required
|
|
133
|
-
* to prevent inadvertent sending of an API's `apiKey` to an endpoint is does
|
|
134
|
-
* not belong to.
|
|
135
|
-
*/
|
|
136
|
-
options.authMode = options.authMode || clientAuthMode;
|
|
137
|
-
options.apiKey = options.apiKey ?? clientApiKey;
|
|
108
|
+
options.authMode = options.authMode || internals.authMode;
|
|
138
109
|
options.authToken = options.authToken || internals.authToken;
|
|
139
|
-
|
|
140
|
-
if (clientEndpoint && options.authMode === 'apiKey' && !options.apiKey) {
|
|
141
|
-
throw new Error(
|
|
142
|
-
"graphql() requires an explicit `apiKey` for a custom `endpoint` when `authMode = 'apiKey'`.",
|
|
143
|
-
);
|
|
144
|
-
}
|
|
145
|
-
|
|
146
110
|
const headers = additionalHeaders || internals.headers;
|
|
147
111
|
|
|
148
112
|
/**
|
|
@@ -150,13 +114,11 @@ export function graphql<
|
|
|
150
114
|
* Neither of these can actually be validated at runtime. Hence, we don't perform
|
|
151
115
|
* any validation or type-guarding here.
|
|
152
116
|
*/
|
|
117
|
+
|
|
153
118
|
const result = GraphQLAPI.graphql(
|
|
154
119
|
// TODO: move V6Client back into this package?
|
|
155
120
|
internals.amplify as any,
|
|
156
|
-
|
|
157
|
-
...options,
|
|
158
|
-
endpoint: clientEndpoint,
|
|
159
|
-
} as any,
|
|
121
|
+
options as GraphQLOptions,
|
|
160
122
|
headers,
|
|
161
123
|
);
|
|
162
124
|
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
AmplifyServer,
|
|
6
6
|
getAmplifyServerContext,
|
|
7
7
|
} from '@aws-amplify/core/internals/adapter-core';
|
|
8
|
-
import { ResourcesConfig } from '@aws-amplify/core';
|
|
9
8
|
import { CustomHeaders } from '@aws-amplify/data-schema/runtime';
|
|
10
9
|
|
|
11
10
|
import { generateClientWithAmplifyInstance } from '../internals/server';
|
|
@@ -34,35 +33,38 @@ import {
|
|
|
34
33
|
* }),
|
|
35
34
|
* });
|
|
36
35
|
*/
|
|
37
|
-
export function generateClient<
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
export function generateClient<T extends Record<any, any> = never>({
|
|
37
|
+
config,
|
|
38
|
+
authMode,
|
|
39
|
+
authToken,
|
|
40
|
+
}: GenerateServerClientParams): V6ClientSSRRequest<T> {
|
|
41
41
|
// passing `null` instance because each (future model) method must retrieve a valid instance
|
|
42
42
|
// from server context
|
|
43
43
|
const client = generateClientWithAmplifyInstance<T, V6ClientSSRRequest<T>>({
|
|
44
44
|
amplify: null,
|
|
45
|
-
|
|
45
|
+
config,
|
|
46
|
+
authMode,
|
|
47
|
+
authToken,
|
|
46
48
|
});
|
|
47
49
|
|
|
48
50
|
// TODO: improve this and the next type
|
|
49
|
-
const prevGraphql = client.graphql as unknown as GraphQLMethod
|
|
51
|
+
const prevGraphql = client.graphql as unknown as GraphQLMethod;
|
|
50
52
|
|
|
51
53
|
const wrappedGraphql = (
|
|
52
54
|
contextSpec: AmplifyServer.ContextSpec,
|
|
53
|
-
|
|
55
|
+
options: GraphQLOptionsV6,
|
|
54
56
|
additionalHeaders?: CustomHeaders,
|
|
55
57
|
) => {
|
|
56
58
|
const amplifyInstance = getAmplifyServerContext(contextSpec).amplify;
|
|
57
59
|
|
|
58
60
|
return prevGraphql.call(
|
|
59
61
|
{ [__amplify]: amplifyInstance },
|
|
60
|
-
|
|
62
|
+
options,
|
|
61
63
|
additionalHeaders as any,
|
|
62
64
|
);
|
|
63
65
|
};
|
|
64
66
|
|
|
65
|
-
client.graphql = wrappedGraphql as unknown as GraphQLMethodSSR
|
|
67
|
+
client.graphql = wrappedGraphql as unknown as GraphQLMethodSSR;
|
|
66
68
|
|
|
67
69
|
return client;
|
|
68
70
|
}
|