@aws-amplify/api-graphql 4.6.6 → 4.6.7-graphql-multi-client.93b5136.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 +13 -13
- package/dist/cjs/internals/InternalGraphQLAPI.js.map +1 -1
- package/dist/cjs/internals/generateClient.js +28 -16
- package/dist/cjs/internals/generateClient.js.map +1 -1
- package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js +11 -1
- package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js.map +1 -1
- package/dist/cjs/internals/v6.js +32 -2
- package/dist/cjs/internals/v6.js.map +1 -1
- package/dist/cjs/server/generateClient.js +4 -6
- package/dist/cjs/server/generateClient.js.map +1 -1
- package/dist/cjs/types/index.js +5 -1
- 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 +13 -13
- package/dist/esm/internals/InternalGraphQLAPI.mjs.map +1 -1
- package/dist/esm/internals/generateClient.d.ts +2 -2
- package/dist/esm/internals/generateClient.mjs +29 -17
- package/dist/esm/internals/generateClient.mjs.map +1 -1
- package/dist/esm/internals/index.d.ts +1 -0
- package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs +12 -2
- package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs.map +1 -1
- package/dist/esm/internals/types.d.ts +16 -2
- package/dist/esm/internals/v6.d.ts +2 -2
- package/dist/esm/internals/v6.mjs +32 -2
- package/dist/esm/internals/v6.mjs.map +1 -1
- package/dist/esm/server/generateClient.d.ts +4 -1
- package/dist/esm/server/generateClient.mjs +4 -6
- package/dist/esm/server/generateClient.mjs.map +1 -1
- package/dist/esm/types/index.d.ts +59 -15
- package/dist/esm/types/index.mjs +5 -1
- package/dist/esm/types/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/internals/InternalGraphQLAPI.ts +33 -13
- package/src/internals/generateClient.ts +40 -20
- package/src/internals/index.ts +1 -0
- package/src/internals/server/generateClientWithAmplifyInstance.ts +18 -1
- package/src/internals/types.ts +22 -5
- package/src/internals/v6.ts +43 -5
- package/src/server/generateClient.ts +10 -12
- package/src/types/index.ts +90 -26
|
@@ -4,18 +4,21 @@ 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';
|
|
7
8
|
export { OperationTypeNode } from 'graphql';
|
|
8
9
|
export { CONTROL_MSG, ConnectionState } from './PubSub';
|
|
9
10
|
export { SelectionSet } from '@aws-amplify/data-schema/runtime';
|
|
10
|
-
export { CommonPublicClientOptions }
|
|
11
|
+
export type { CommonPublicClientOptions };
|
|
11
12
|
/**
|
|
12
13
|
* Loose/Unknown options for raw GraphQLAPICategory `graphql()`.
|
|
13
14
|
*/
|
|
14
15
|
export interface GraphQLOptions {
|
|
15
16
|
query: string | DocumentNode;
|
|
17
|
+
endpoint?: string;
|
|
16
18
|
variables?: Record<string, DocumentType>;
|
|
17
19
|
authMode?: GraphQLAuthMode;
|
|
18
20
|
authToken?: string;
|
|
21
|
+
apiKey?: string;
|
|
19
22
|
/**
|
|
20
23
|
* @deprecated This property should not be used
|
|
21
24
|
*/
|
|
@@ -162,16 +165,57 @@ export type GraphQLOperation = Source | string;
|
|
|
162
165
|
* API V6 `graphql({options})` type that can leverage branded graphql `query`
|
|
163
166
|
* objects and fallback types.
|
|
164
167
|
*/
|
|
165
|
-
export
|
|
168
|
+
export type GraphQLOptionsV6<FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string, Options extends CommonPublicClientOptions = object> = Options['endpoint'] extends string ? Options['apiKey'] extends string ? {
|
|
166
169
|
query: TYPED_GQL_STRING | DocumentNode;
|
|
167
170
|
variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
168
171
|
authMode?: GraphQLAuthMode;
|
|
172
|
+
apiKey?: string;
|
|
169
173
|
authToken?: string;
|
|
170
174
|
/**
|
|
171
175
|
* @deprecated This property should not be used
|
|
172
176
|
*/
|
|
173
177
|
userAgentSuffix?: string;
|
|
174
|
-
}
|
|
178
|
+
} : {
|
|
179
|
+
query: TYPED_GQL_STRING | DocumentNode;
|
|
180
|
+
variables?: GraphQLVariablesV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
181
|
+
authMode?: never;
|
|
182
|
+
apiKey?: never;
|
|
183
|
+
authToken?: string;
|
|
184
|
+
/**
|
|
185
|
+
* @deprecated This property should not be used
|
|
186
|
+
*/
|
|
187
|
+
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
|
+
};
|
|
175
219
|
/**
|
|
176
220
|
* Result type for `graphql()` operations that don't include any specific
|
|
177
221
|
* type information. The result could be either a `Promise` or `Subscription`.
|
|
@@ -275,26 +319,28 @@ export type GeneratedSubscription<InputType, OutputType> = string & {
|
|
|
275
319
|
export declare const __amplify: unique symbol;
|
|
276
320
|
export declare const __authMode: unique symbol;
|
|
277
321
|
export declare const __authToken: unique symbol;
|
|
322
|
+
export declare const __apiKey: unique symbol;
|
|
278
323
|
export declare const __headers: unique symbol;
|
|
324
|
+
export declare const __endpoint: unique symbol;
|
|
279
325
|
export declare function getInternals(client: BaseClient): ClientInternals;
|
|
280
326
|
export type ClientWithModels = V6Client | V6ClientSSRRequest | V6ClientSSRCookies;
|
|
281
|
-
export type V6Client<T extends Record<any, any> = never> = {
|
|
282
|
-
graphql: GraphQLMethod
|
|
327
|
+
export type V6Client<T extends Record<any, any> = never, Options extends CommonPublicClientOptions = object> = {
|
|
328
|
+
graphql: GraphQLMethod<Options>;
|
|
283
329
|
cancel(promise: Promise<any>, message?: string): boolean;
|
|
284
330
|
isCancelError(error: any): boolean;
|
|
285
331
|
} & ClientExtensions<T>;
|
|
286
|
-
export type V6ClientSSRRequest<T extends Record<any, any> = never> = {
|
|
287
|
-
graphql: GraphQLMethodSSR
|
|
332
|
+
export type V6ClientSSRRequest<T extends Record<any, any> = never, Options extends CommonPublicClientOptions = object> = {
|
|
333
|
+
graphql: GraphQLMethodSSR<Options>;
|
|
288
334
|
cancel(promise: Promise<any>, message?: string): boolean;
|
|
289
335
|
isCancelError(error: any): boolean;
|
|
290
336
|
} & ClientExtensionsSSRRequest<T>;
|
|
291
|
-
export type V6ClientSSRCookies<T extends Record<any, any> = never> = {
|
|
292
|
-
graphql: GraphQLMethod
|
|
337
|
+
export type V6ClientSSRCookies<T extends Record<any, any> = never, Options extends CommonPublicClientOptions = object> = {
|
|
338
|
+
graphql: GraphQLMethod<Options>;
|
|
293
339
|
cancel(promise: Promise<any>, message?: string): boolean;
|
|
294
340
|
isCancelError(error: any): boolean;
|
|
295
341
|
} & ClientExtensionsSSRCookies<T>;
|
|
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>;
|
|
342
|
+
export type GraphQLMethod<Options extends CommonPublicClientOptions> = <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING, Options>, additionalHeaders?: CustomHeaders | undefined) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
343
|
+
export type GraphQLMethodSSR<Options extends CommonPublicClientOptions> = <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(contextSpec: AmplifyServer.ContextSpec, options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING, Options>, additionalHeaders?: CustomHeaders | undefined) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
298
344
|
/**
|
|
299
345
|
* @private
|
|
300
346
|
*
|
|
@@ -315,8 +361,6 @@ export interface AuthModeParams extends Record<string, unknown> {
|
|
|
315
361
|
authMode?: GraphQLAuthMode;
|
|
316
362
|
authToken?: string;
|
|
317
363
|
}
|
|
318
|
-
export
|
|
364
|
+
export type GenerateServerClientParams = {
|
|
319
365
|
config: ResourcesConfig;
|
|
320
|
-
|
|
321
|
-
authToken?: string;
|
|
322
|
-
}
|
|
366
|
+
} & CommonPublicClientOptions;
|
package/dist/esm/types/index.mjs
CHANGED
|
@@ -11,16 +11,20 @@ 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');
|
|
14
15
|
const __headers = Symbol('headers');
|
|
16
|
+
const __endpoint = Symbol('endpoint');
|
|
15
17
|
function getInternals(client) {
|
|
16
18
|
const c = client;
|
|
17
19
|
return {
|
|
18
20
|
amplify: c[__amplify],
|
|
21
|
+
apiKey: c[__apiKey],
|
|
19
22
|
authMode: c[__authMode],
|
|
20
23
|
authToken: c[__authToken],
|
|
24
|
+
endpoint: c[__endpoint],
|
|
21
25
|
headers: c[__headers],
|
|
22
26
|
};
|
|
23
27
|
}
|
|
24
28
|
|
|
25
|
-
export { GraphQLAuthError, __amplify, __authMode, __authToken, __headers, getInternals };
|
|
29
|
+
export { GraphQLAuthError, __amplify, __apiKey, __authMode, __authToken, __endpoint, __headers, getInternals };
|
|
26
30
|
//# 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 __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;
|
|
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 __apiKey = Symbol('apiKey');\nexport const __headers = Symbol('headers');\nexport const __endpoint = Symbol('endpoint');\nexport function getInternals(client) {\n const c = client;\n return {\n amplify: c[__amplify],\n apiKey: c[__apiKey],\n authMode: c[__authMode],\n authToken: c[__authToken],\n endpoint: c[__endpoint],\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,QAAQ,GAAG,MAAM,CAAC,QAAQ,EAAE;AAC7B,MAAC,SAAS,GAAG,MAAM,CAAC,SAAS,EAAE;AAC/B,MAAC,UAAU,GAAG,MAAM,CAAC,UAAU,EAAE;AACtC,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,MAAM,EAAE,CAAC,CAAC,QAAQ,CAAC;AAC3B,QAAQ,QAAQ,EAAE,CAAC,CAAC,UAAU,CAAC;AAC/B,QAAQ,SAAS,EAAE,CAAC,CAAC,WAAW,CAAC;AACjC,QAAQ,QAAQ,EAAE,CAAC,CAAC,UAAU,CAAC;AAC/B,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.
|
|
3
|
+
"version": "4.6.7-graphql-multi-client.93b5136.0+93b5136",
|
|
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.
|
|
88
|
-
"@aws-amplify/core": "6.7.
|
|
87
|
+
"@aws-amplify/api-rest": "4.0.64-graphql-multi-client.93b5136.0+93b5136",
|
|
88
|
+
"@aws-amplify/core": "6.7.4-graphql-multi-client.93b5136.0+93b5136",
|
|
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": "93b51360e57e283a7d4ed64c6b701d85ec71e94b"
|
|
105
105
|
}
|
|
@@ -88,7 +88,14 @@ export class InternalGraphQLAPIClass {
|
|
|
88
88
|
amplify:
|
|
89
89
|
| AmplifyClassV6
|
|
90
90
|
| ((fn: (amplify: any) => Promise<any>) => Promise<AmplifyClassV6>),
|
|
91
|
-
{
|
|
91
|
+
{
|
|
92
|
+
query: paramQuery,
|
|
93
|
+
variables = {},
|
|
94
|
+
authMode,
|
|
95
|
+
authToken,
|
|
96
|
+
endpoint,
|
|
97
|
+
apiKey,
|
|
98
|
+
}: GraphQLOptions,
|
|
92
99
|
additionalHeaders?: CustomHeaders,
|
|
93
100
|
customUserAgentDetails?: CustomUserAgentDetails,
|
|
94
101
|
): Observable<GraphQLResult<T>> | Promise<GraphQLResult<T>> {
|
|
@@ -115,7 +122,7 @@ export class InternalGraphQLAPIClass {
|
|
|
115
122
|
if (isAmplifyInstance(amplify)) {
|
|
116
123
|
responsePromise = this._graphql<T>(
|
|
117
124
|
amplify,
|
|
118
|
-
{ query, variables, authMode },
|
|
125
|
+
{ query, variables, authMode, apiKey, endpoint },
|
|
119
126
|
headers,
|
|
120
127
|
abortController,
|
|
121
128
|
customUserAgentDetails,
|
|
@@ -127,7 +134,7 @@ export class InternalGraphQLAPIClass {
|
|
|
127
134
|
const wrapper = async (amplifyInstance: AmplifyClassV6) => {
|
|
128
135
|
const result = await this._graphql<T>(
|
|
129
136
|
amplifyInstance,
|
|
130
|
-
{ query, variables, authMode },
|
|
137
|
+
{ query, variables, authMode, apiKey, endpoint },
|
|
131
138
|
headers,
|
|
132
139
|
abortController,
|
|
133
140
|
customUserAgentDetails,
|
|
@@ -152,7 +159,7 @@ export class InternalGraphQLAPIClass {
|
|
|
152
159
|
case 'subscription':
|
|
153
160
|
return this._graphqlSubscribe(
|
|
154
161
|
amplify as AmplifyClassV6,
|
|
155
|
-
{ query, variables, authMode },
|
|
162
|
+
{ query, variables, authMode, apiKey, endpoint },
|
|
156
163
|
headers,
|
|
157
164
|
customUserAgentDetails,
|
|
158
165
|
authToken,
|
|
@@ -164,7 +171,13 @@ export class InternalGraphQLAPIClass {
|
|
|
164
171
|
|
|
165
172
|
private async _graphql<T = any>(
|
|
166
173
|
amplify: AmplifyClassV6,
|
|
167
|
-
{
|
|
174
|
+
{
|
|
175
|
+
query,
|
|
176
|
+
variables,
|
|
177
|
+
authMode: authModeOverride,
|
|
178
|
+
endpoint: endpointOverride,
|
|
179
|
+
apiKey: apiKeyOverride,
|
|
180
|
+
}: GraphQLOptions,
|
|
168
181
|
additionalHeaders: CustomHeaders = {},
|
|
169
182
|
abortController: AbortController,
|
|
170
183
|
customUserAgentDetails?: CustomUserAgentDetails,
|
|
@@ -179,7 +192,7 @@ export class InternalGraphQLAPIClass {
|
|
|
179
192
|
defaultAuthMode,
|
|
180
193
|
} = resolveConfig(amplify);
|
|
181
194
|
|
|
182
|
-
const initialAuthMode =
|
|
195
|
+
const initialAuthMode = authModeOverride || defaultAuthMode || 'iam';
|
|
183
196
|
// identityPool is an alias for iam. TODO: remove 'iam' in v7
|
|
184
197
|
const authMode =
|
|
185
198
|
initialAuthMode === 'identityPool' ? 'iam' : initialAuthMode;
|
|
@@ -205,7 +218,7 @@ export class InternalGraphQLAPIClass {
|
|
|
205
218
|
const requestOptions: RequestOptions = {
|
|
206
219
|
method: 'POST',
|
|
207
220
|
url: new AmplifyUrl(
|
|
208
|
-
customEndpoint || appSyncGraphqlEndpoint || '',
|
|
221
|
+
endpointOverride || customEndpoint || appSyncGraphqlEndpoint || '',
|
|
209
222
|
).toString(),
|
|
210
223
|
queryString: print(query as DocumentNode),
|
|
211
224
|
};
|
|
@@ -226,7 +239,7 @@ export class InternalGraphQLAPIClass {
|
|
|
226
239
|
const authHeaders = await headerBasedAuth(
|
|
227
240
|
amplify,
|
|
228
241
|
authMode,
|
|
229
|
-
apiKey,
|
|
242
|
+
apiKeyOverride ?? apiKey,
|
|
230
243
|
additionalCustomHeaders,
|
|
231
244
|
);
|
|
232
245
|
|
|
@@ -282,7 +295,8 @@ export class InternalGraphQLAPIClass {
|
|
|
282
295
|
};
|
|
283
296
|
}
|
|
284
297
|
|
|
285
|
-
const endpoint =
|
|
298
|
+
const endpoint =
|
|
299
|
+
endpointOverride || customEndpoint || appSyncGraphqlEndpoint;
|
|
286
300
|
|
|
287
301
|
if (!endpoint) {
|
|
288
302
|
throw createGraphQLResultWithError<T>(new GraphQLApiError(NO_ENDPOINT));
|
|
@@ -341,7 +355,13 @@ export class InternalGraphQLAPIClass {
|
|
|
341
355
|
|
|
342
356
|
private _graphqlSubscribe(
|
|
343
357
|
amplify: AmplifyClassV6,
|
|
344
|
-
{
|
|
358
|
+
{
|
|
359
|
+
query,
|
|
360
|
+
variables,
|
|
361
|
+
authMode: authModeOverride,
|
|
362
|
+
apiKey: apiKeyOverride,
|
|
363
|
+
endpoint,
|
|
364
|
+
}: GraphQLOptions,
|
|
345
365
|
additionalHeaders: CustomHeaders = {},
|
|
346
366
|
customUserAgentDetails?: CustomUserAgentDetails,
|
|
347
367
|
authToken?: string,
|
|
@@ -349,7 +369,7 @@ export class InternalGraphQLAPIClass {
|
|
|
349
369
|
const config = resolveConfig(amplify);
|
|
350
370
|
|
|
351
371
|
const initialAuthMode =
|
|
352
|
-
|
|
372
|
+
authModeOverride || config?.defaultAuthMode || 'iam';
|
|
353
373
|
// identityPool is an alias for iam. TODO: remove 'iam' in v7
|
|
354
374
|
const authMode =
|
|
355
375
|
initialAuthMode === 'identityPool' ? 'iam' : initialAuthMode;
|
|
@@ -369,10 +389,10 @@ export class InternalGraphQLAPIClass {
|
|
|
369
389
|
{
|
|
370
390
|
query: print(query as DocumentNode),
|
|
371
391
|
variables,
|
|
372
|
-
appSyncGraphqlEndpoint: config?.endpoint,
|
|
392
|
+
appSyncGraphqlEndpoint: endpoint ?? config?.endpoint,
|
|
373
393
|
region: config?.region,
|
|
374
394
|
authenticationType: authMode,
|
|
375
|
-
apiKey: config?.apiKey,
|
|
395
|
+
apiKey: apiKeyOverride ?? config?.apiKey,
|
|
376
396
|
additionalHeaders,
|
|
377
397
|
authToken,
|
|
378
398
|
libraryConfigHeaders,
|
|
@@ -13,8 +13,10 @@ import {
|
|
|
13
13
|
import {
|
|
14
14
|
V6Client,
|
|
15
15
|
__amplify,
|
|
16
|
+
__apiKey,
|
|
16
17
|
__authMode,
|
|
17
18
|
__authToken,
|
|
19
|
+
__endpoint,
|
|
18
20
|
__headers,
|
|
19
21
|
getInternals,
|
|
20
22
|
} from '../types';
|
|
@@ -22,7 +24,7 @@ import {
|
|
|
22
24
|
import { isApiGraphQLConfig } from './utils/runtimeTypeGuards/isApiGraphQLProviderConfig';
|
|
23
25
|
import { isConfigureEventWithResourceConfig } from './utils/runtimeTypeGuards/isConfigureEventWithResourceConfig';
|
|
24
26
|
import { cancel, graphql, isCancelError } from './v6';
|
|
25
|
-
import { ClientGenerationParams } from './types';
|
|
27
|
+
import { ClientGenerationParams, CommonPublicClientOptions } from './types';
|
|
26
28
|
|
|
27
29
|
/**
|
|
28
30
|
* @private
|
|
@@ -33,13 +35,16 @@ import { ClientGenerationParams } from './types';
|
|
|
33
35
|
* @param params
|
|
34
36
|
* @returns
|
|
35
37
|
*/
|
|
36
|
-
export function generateClient<
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
export function generateClient<
|
|
39
|
+
T extends Record<any, any> = never,
|
|
40
|
+
Options extends CommonPublicClientOptions = object,
|
|
41
|
+
>(params: ClientGenerationParams): V6Client<T, Options> {
|
|
39
42
|
const client = {
|
|
40
43
|
[__amplify]: params.amplify,
|
|
41
44
|
[__authMode]: params.authMode,
|
|
42
45
|
[__authToken]: params.authToken,
|
|
46
|
+
[__apiKey]: 'apiKey' in params ? params.apiKey : undefined,
|
|
47
|
+
[__endpoint]: 'endpoint' in params ? params.endpoint : undefined,
|
|
43
48
|
[__headers]: params.headers,
|
|
44
49
|
graphql,
|
|
45
50
|
cancel,
|
|
@@ -53,22 +58,37 @@ export function generateClient<T extends Record<any, any> = never>(
|
|
|
53
58
|
|
|
54
59
|
const apiGraphqlConfig = params.amplify.getConfig().API?.GraphQL;
|
|
55
60
|
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
61
|
+
if (client[__endpoint]) {
|
|
62
|
+
if (!client[__authMode]) {
|
|
63
|
+
throw new Error(
|
|
64
|
+
'generateClient() requires an explicit `authMode` when `endpoint` is provided.',
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
if (client[__authMode] === 'apiKey' && !client[__apiKey]) {
|
|
68
|
+
throw new Error(
|
|
69
|
+
"generateClient() requires an explicit `apiKey` when `endpoint` is provided and `authMode = 'apiKey'`.",
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (!client[__endpoint]) {
|
|
75
|
+
if (isApiGraphQLConfig(apiGraphqlConfig)) {
|
|
76
|
+
addSchemaToClient(client, apiGraphqlConfig, getInternals);
|
|
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
|
+
}
|
|
72
92
|
}
|
|
73
93
|
|
|
74
94
|
return client as any;
|
package/src/internals/index.ts
CHANGED
|
@@ -9,8 +9,10 @@ import {
|
|
|
9
9
|
V6ClientSSRCookies,
|
|
10
10
|
V6ClientSSRRequest,
|
|
11
11
|
__amplify,
|
|
12
|
+
__apiKey,
|
|
12
13
|
__authMode,
|
|
13
14
|
__authToken,
|
|
15
|
+
__endpoint,
|
|
14
16
|
__headers,
|
|
15
17
|
getInternals,
|
|
16
18
|
} from '../../types';
|
|
@@ -40,6 +42,8 @@ export function generateClientWithAmplifyInstance<
|
|
|
40
42
|
[__amplify]: params.amplify,
|
|
41
43
|
[__authMode]: params.authMode,
|
|
42
44
|
[__authToken]: params.authToken,
|
|
45
|
+
[__apiKey]: 'apiKey' in params ? params.apiKey : undefined,
|
|
46
|
+
[__endpoint]: 'endpoint' in params ? params.endpoint : undefined,
|
|
43
47
|
[__headers]: params.headers,
|
|
44
48
|
graphql,
|
|
45
49
|
cancel,
|
|
@@ -48,7 +52,20 @@ export function generateClientWithAmplifyInstance<
|
|
|
48
52
|
|
|
49
53
|
const apiGraphqlConfig = params.config?.API?.GraphQL;
|
|
50
54
|
|
|
51
|
-
if (
|
|
55
|
+
if (client[__endpoint]) {
|
|
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)) {
|
|
52
69
|
addSchemaToClientWithInstance<T>(client, params, getInternals);
|
|
53
70
|
}
|
|
54
71
|
|
package/src/internals/types.ts
CHANGED
|
@@ -16,8 +16,25 @@ export type ClientGenerationParams = {
|
|
|
16
16
|
/**
|
|
17
17
|
* Common options that can be used on public `generateClient()` interfaces.
|
|
18
18
|
*/
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
19
|
+
export type CommonPublicClientOptions =
|
|
20
|
+
| {
|
|
21
|
+
endpoint?: never;
|
|
22
|
+
authMode?: GraphQLAuthMode;
|
|
23
|
+
authToken?: string;
|
|
24
|
+
apiKey?: string;
|
|
25
|
+
headers?: CustomHeaders;
|
|
26
|
+
}
|
|
27
|
+
| {
|
|
28
|
+
endpoint: string;
|
|
29
|
+
authMode: 'apiKey';
|
|
30
|
+
apiKey: string;
|
|
31
|
+
authToken?: string;
|
|
32
|
+
headers?: CustomHeaders;
|
|
33
|
+
}
|
|
34
|
+
| {
|
|
35
|
+
endpoint: string;
|
|
36
|
+
authMode: Exclude<GraphQLAuthMode, 'apiKey'>;
|
|
37
|
+
apiKey?: string;
|
|
38
|
+
authToken?: string;
|
|
39
|
+
headers?: CustomHeaders;
|
|
40
|
+
};
|
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
|
+
CommonPublicClientOptions,
|
|
8
8
|
GraphQLOptionsV6,
|
|
9
9
|
GraphQLResponseV6,
|
|
10
10
|
V6Client,
|
|
@@ -98,15 +98,51 @@ import {
|
|
|
98
98
|
export function graphql<
|
|
99
99
|
FALLBACK_TYPES = unknown,
|
|
100
100
|
TYPED_GQL_STRING extends string = string,
|
|
101
|
+
Options extends CommonPublicClientOptions = object,
|
|
101
102
|
>(
|
|
102
103
|
this: V6Client,
|
|
103
|
-
options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING>,
|
|
104
|
+
options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING, Options>,
|
|
104
105
|
additionalHeaders?: CustomHeaders,
|
|
105
106
|
): GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING> {
|
|
106
107
|
// inject client-level auth
|
|
107
108
|
const internals = getInternals(this as any);
|
|
108
|
-
|
|
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;
|
|
109
138
|
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
|
+
|
|
110
146
|
const headers = additionalHeaders || internals.headers;
|
|
111
147
|
|
|
112
148
|
/**
|
|
@@ -114,11 +150,13 @@ export function graphql<
|
|
|
114
150
|
* Neither of these can actually be validated at runtime. Hence, we don't perform
|
|
115
151
|
* any validation or type-guarding here.
|
|
116
152
|
*/
|
|
117
|
-
|
|
118
153
|
const result = GraphQLAPI.graphql(
|
|
119
154
|
// TODO: move V6Client back into this package?
|
|
120
155
|
internals.amplify as any,
|
|
121
|
-
|
|
156
|
+
{
|
|
157
|
+
...options,
|
|
158
|
+
endpoint: clientEndpoint,
|
|
159
|
+
} as any,
|
|
122
160
|
headers,
|
|
123
161
|
);
|
|
124
162
|
|
|
@@ -5,6 +5,7 @@ import {
|
|
|
5
5
|
AmplifyServer,
|
|
6
6
|
getAmplifyServerContext,
|
|
7
7
|
} from '@aws-amplify/core/internals/adapter-core';
|
|
8
|
+
import { ResourcesConfig } from '@aws-amplify/core';
|
|
8
9
|
import { CustomHeaders } from '@aws-amplify/data-schema/runtime';
|
|
9
10
|
|
|
10
11
|
import { generateClientWithAmplifyInstance } from '../internals/server';
|
|
@@ -33,38 +34,35 @@ import {
|
|
|
33
34
|
* }),
|
|
34
35
|
* });
|
|
35
36
|
*/
|
|
36
|
-
export function generateClient<
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}: GenerateServerClientParams): V6ClientSSRRequest<T> {
|
|
37
|
+
export function generateClient<
|
|
38
|
+
T extends Record<any, any> = never,
|
|
39
|
+
Options extends GenerateServerClientParams = { config: ResourcesConfig },
|
|
40
|
+
>(options: Options): V6ClientSSRRequest<T, Options> {
|
|
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
|
-
|
|
46
|
-
authMode,
|
|
47
|
-
authToken,
|
|
45
|
+
...options,
|
|
48
46
|
});
|
|
49
47
|
|
|
50
48
|
// TODO: improve this and the next type
|
|
51
|
-
const prevGraphql = client.graphql as unknown as GraphQLMethod
|
|
49
|
+
const prevGraphql = client.graphql as unknown as GraphQLMethod<Options>;
|
|
52
50
|
|
|
53
51
|
const wrappedGraphql = (
|
|
54
52
|
contextSpec: AmplifyServer.ContextSpec,
|
|
55
|
-
|
|
53
|
+
innerOptions: GraphQLOptionsV6,
|
|
56
54
|
additionalHeaders?: CustomHeaders,
|
|
57
55
|
) => {
|
|
58
56
|
const amplifyInstance = getAmplifyServerContext(contextSpec).amplify;
|
|
59
57
|
|
|
60
58
|
return prevGraphql.call(
|
|
61
59
|
{ [__amplify]: amplifyInstance },
|
|
62
|
-
|
|
60
|
+
innerOptions as any,
|
|
63
61
|
additionalHeaders as any,
|
|
64
62
|
);
|
|
65
63
|
};
|
|
66
64
|
|
|
67
|
-
client.graphql = wrappedGraphql as unknown as GraphQLMethodSSR
|
|
65
|
+
client.graphql = wrappedGraphql as unknown as GraphQLMethodSSR<Options>;
|
|
68
66
|
|
|
69
67
|
return client;
|
|
70
68
|
}
|