@aws-amplify/api-graphql 4.6.6 → 4.6.7-graphql-multi-client.4f8e7a9.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 +1 -1
- 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.d.ts +1 -1
- 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 +23 -4
- package/dist/esm/internals/v6.mjs +32 -2
- package/dist/esm/internals/v6.mjs.map +1 -1
- package/dist/esm/server/generateClient.d.ts +1 -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 +42 -19
- package/src/internals/index.ts +1 -0
- package/src/internals/server/generateClientWithAmplifyInstance.ts +21 -4
- package/src/internals/types.ts +38 -7
- package/src/internals/v6.ts +40 -4
- package/src/server/generateClient.ts +22 -13
- package/src/types/index.ts +113 -32
|
@@ -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, WithCustomEndpoint extends boolean = false, WithApiKey extends boolean = false> = WithCustomEndpoint extends true ? WithApiKey extends true ? {
|
|
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, WithCustomEndpoint extends boolean = false, WithApiKey extends boolean = false> = {
|
|
328
|
+
graphql: GraphQLMethod<WithCustomEndpoint, WithApiKey>;
|
|
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, WithCustomEndpoint extends boolean = false, WithApiKey extends boolean = false> = {
|
|
333
|
+
graphql: GraphQLMethodSSR<WithCustomEndpoint, WithApiKey>;
|
|
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, WithCustomEndpoint extends boolean = false, WithApiKey extends boolean = false> = {
|
|
338
|
+
graphql: GraphQLMethod<WithCustomEndpoint, WithApiKey>;
|
|
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<WithCustomEndpoint extends boolean, WithApiKey extends boolean> = <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING, WithCustomEndpoint, WithApiKey>, additionalHeaders?: CustomHeaders | undefined) => GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING>;
|
|
343
|
+
export type GraphQLMethodSSR<WithCustomEndpoint extends boolean, WithApiKey extends boolean> = <FALLBACK_TYPES = unknown, TYPED_GQL_STRING extends string = string>(contextSpec: AmplifyServer.ContextSpec, options: GraphQLOptionsV6<FALLBACK_TYPES, TYPED_GQL_STRING, WithCustomEndpoint, WithApiKey>, 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<WithCustomEndpoint extends boolean, WithApiKey extends boolean> = {
|
|
319
365
|
config: ResourcesConfig;
|
|
320
|
-
|
|
321
|
-
authToken?: string;
|
|
322
|
-
}
|
|
366
|
+
} & CommonPublicClientOptions<WithCustomEndpoint, WithApiKey>;
|
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.4f8e7a9.0+4f8e7a9",
|
|
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.4f8e7a9.0+4f8e7a9",
|
|
88
|
+
"@aws-amplify/core": "6.7.4-graphql-multi-client.4f8e7a9.0+4f8e7a9",
|
|
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": "4f8e7a94a1c2540baa7eda530787b248b0fb237a"
|
|
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';
|
|
@@ -33,13 +35,19 @@ 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
|
+
WithCustomEndpoint extends boolean = false,
|
|
41
|
+
WithApiKey extends boolean = false,
|
|
42
|
+
>(
|
|
43
|
+
params: ClientGenerationParams<WithCustomEndpoint, WithApiKey>,
|
|
44
|
+
): V6Client<T, WithCustomEndpoint, WithApiKey> {
|
|
39
45
|
const client = {
|
|
40
46
|
[__amplify]: params.amplify,
|
|
41
47
|
[__authMode]: params.authMode,
|
|
42
48
|
[__authToken]: params.authToken,
|
|
49
|
+
[__apiKey]: 'apiKey' in params ? params.apiKey : undefined,
|
|
50
|
+
[__endpoint]: 'endpoint' in params ? params.endpoint : undefined,
|
|
43
51
|
[__headers]: params.headers,
|
|
44
52
|
graphql,
|
|
45
53
|
cancel,
|
|
@@ -53,22 +61,37 @@ export function generateClient<T extends Record<any, any> = never>(
|
|
|
53
61
|
|
|
54
62
|
const apiGraphqlConfig = params.amplify.getConfig().API?.GraphQL;
|
|
55
63
|
|
|
56
|
-
if (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
64
|
+
if (client[__endpoint]) {
|
|
65
|
+
if (!client[__authMode]) {
|
|
66
|
+
throw new Error(
|
|
67
|
+
'generateClient() requires an explicit `authMode` when `endpoint` is provided.',
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
if (client[__authMode] === 'apiKey' && !client[__apiKey]) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
"generateClient() requires an explicit `apiKey` when `endpoint` is provided and `authMode = 'apiKey'`.",
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
if (!client[__endpoint]) {
|
|
78
|
+
if (isApiGraphQLConfig(apiGraphqlConfig)) {
|
|
79
|
+
addSchemaToClient(client, apiGraphqlConfig, getInternals);
|
|
80
|
+
} else {
|
|
81
|
+
// This happens when the `Amplify.configure()` call gets evaluated after the `generateClient()` call.
|
|
82
|
+
//
|
|
83
|
+
// Cause: when the `generateClient()` and the `Amplify.configure()` calls are located in
|
|
84
|
+
// different source files, script bundlers may randomly arrange their orders in the production
|
|
85
|
+
// bundle.
|
|
86
|
+
//
|
|
87
|
+
// With the current implementation, the `client.models` instance created by `generateClient()`
|
|
88
|
+
// will be rebuilt on every `Amplify.configure()` call that's provided with a valid GraphQL
|
|
89
|
+
// provider configuration.
|
|
90
|
+
//
|
|
91
|
+
// TODO: revisit, and reverify this approach when enabling multiple clients for multi-endpoints
|
|
92
|
+
// configuration.
|
|
93
|
+
generateModelsPropertyOnAmplifyConfigure(client);
|
|
94
|
+
}
|
|
72
95
|
}
|
|
73
96
|
|
|
74
97
|
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';
|
|
@@ -31,15 +33,17 @@ import { cancel, graphql, isCancelError } from '..';
|
|
|
31
33
|
export function generateClientWithAmplifyInstance<
|
|
32
34
|
T extends Record<any, any> = never,
|
|
33
35
|
ClientType extends
|
|
34
|
-
| V6ClientSSRRequest<T>
|
|
35
|
-
| V6ClientSSRCookies<T> = V6ClientSSRCookies<T>,
|
|
36
|
+
| V6ClientSSRRequest<T, any, any>
|
|
37
|
+
| V6ClientSSRCookies<T, any, any> = V6ClientSSRCookies<T, any, any>,
|
|
36
38
|
>(
|
|
37
|
-
params: ServerClientGenerationParams & CommonPublicClientOptions,
|
|
39
|
+
params: ServerClientGenerationParams & CommonPublicClientOptions<any, any>,
|
|
38
40
|
): ClientType {
|
|
39
41
|
const client = {
|
|
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
|
@@ -9,15 +9,46 @@ import { CustomHeaders } from '@aws-amplify/data-schema/runtime';
|
|
|
9
9
|
*
|
|
10
10
|
* The knobs available for configuring `generateClient` internally.
|
|
11
11
|
*/
|
|
12
|
-
export type ClientGenerationParams
|
|
12
|
+
export type ClientGenerationParams<
|
|
13
|
+
WithCustomEndpoint extends boolean,
|
|
14
|
+
WithApiKey extends boolean,
|
|
15
|
+
> = {
|
|
13
16
|
amplify: AmplifyClassV6;
|
|
14
|
-
} & CommonPublicClientOptions
|
|
17
|
+
} & CommonPublicClientOptions<WithCustomEndpoint, WithApiKey>;
|
|
15
18
|
|
|
16
19
|
/**
|
|
17
20
|
* Common options that can be used on public `generateClient()` interfaces.
|
|
18
21
|
*/
|
|
19
|
-
export
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
export type CommonPublicClientOptions<
|
|
23
|
+
WithCustomEndpoint extends boolean,
|
|
24
|
+
WithApiKey extends boolean,
|
|
25
|
+
> = WithCustomEndpoint extends true
|
|
26
|
+
? WithApiKey extends true
|
|
27
|
+
?
|
|
28
|
+
| {
|
|
29
|
+
endpoint: string;
|
|
30
|
+
authMode: 'apiKey';
|
|
31
|
+
apiKey: string;
|
|
32
|
+
authToken?: string;
|
|
33
|
+
headers?: CustomHeaders;
|
|
34
|
+
}
|
|
35
|
+
| {
|
|
36
|
+
endpoint: string;
|
|
37
|
+
apiKey: string;
|
|
38
|
+
authMode: Exclude<GraphQLAuthMode, 'apiKey'>;
|
|
39
|
+
authToken?: string;
|
|
40
|
+
headers?: CustomHeaders;
|
|
41
|
+
}
|
|
42
|
+
: {
|
|
43
|
+
endpoint: string;
|
|
44
|
+
authMode: Exclude<GraphQLAuthMode, 'apiKey'>;
|
|
45
|
+
apiKey?: never;
|
|
46
|
+
authToken?: string;
|
|
47
|
+
headers?: CustomHeaders;
|
|
48
|
+
}
|
|
49
|
+
: {
|
|
50
|
+
endpoint?: never;
|
|
51
|
+
authMode?: GraphQLAuthMode;
|
|
52
|
+
authToken?: string;
|
|
53
|
+
headers?: CustomHeaders;
|
|
54
|
+
};
|
package/src/internals/v6.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { CustomHeaders } from '@aws-amplify/data-schema/runtime';
|
|
|
4
4
|
|
|
5
5
|
import { GraphQLAPI } from '../GraphQLAPI';
|
|
6
6
|
import {
|
|
7
|
-
GraphQLOptions,
|
|
8
7
|
GraphQLOptionsV6,
|
|
9
8
|
GraphQLResponseV6,
|
|
10
9
|
V6Client,
|
|
@@ -105,8 +104,43 @@ export function graphql<
|
|
|
105
104
|
): GraphQLResponseV6<FALLBACK_TYPES, TYPED_GQL_STRING> {
|
|
106
105
|
// inject client-level auth
|
|
107
106
|
const internals = getInternals(this as any);
|
|
108
|
-
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* The custom `endpoint` specific to the client
|
|
110
|
+
*/
|
|
111
|
+
const clientEndpoint: string = (internals as any).endpoint;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The `authMode` specific to the client.
|
|
115
|
+
*/
|
|
116
|
+
const clientAuthMode = internals.authMode;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The `apiKey` specific to the client.
|
|
120
|
+
*/
|
|
121
|
+
const clientApiKey = (internals as any).apiKey;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The most specific `authMode` wins. Setting an `endpoint` value without also
|
|
125
|
+
* setting an `authMode` value is invalid. This helps to prevent customers apps
|
|
126
|
+
* from unexpectedly sending auth details to endpoints the auth details do not
|
|
127
|
+
* belong to.
|
|
128
|
+
*
|
|
129
|
+
* This is especially pronounced for `apiKey`. When both an `endpoint` *and*
|
|
130
|
+
* `authMode: 'apiKey'` are provided, an explicit `apiKey` override is required
|
|
131
|
+
* to prevent inadvertent sending of an API's `apiKey` to an endpoint is does
|
|
132
|
+
* not belong to.
|
|
133
|
+
*/
|
|
134
|
+
options.authMode = options.authMode || clientAuthMode;
|
|
135
|
+
options.apiKey = options.apiKey ?? clientApiKey;
|
|
109
136
|
options.authToken = options.authToken || internals.authToken;
|
|
137
|
+
|
|
138
|
+
if (clientEndpoint && options.authMode === 'apiKey' && !options.apiKey) {
|
|
139
|
+
throw new Error(
|
|
140
|
+
"graphql() requires an explicit `apiKey` for a custom `endpoint` when `authMode = 'apiKey'`.",
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
110
144
|
const headers = additionalHeaders || internals.headers;
|
|
111
145
|
|
|
112
146
|
/**
|
|
@@ -114,11 +148,13 @@ export function graphql<
|
|
|
114
148
|
* Neither of these can actually be validated at runtime. Hence, we don't perform
|
|
115
149
|
* any validation or type-guarding here.
|
|
116
150
|
*/
|
|
117
|
-
|
|
118
151
|
const result = GraphQLAPI.graphql(
|
|
119
152
|
// TODO: move V6Client back into this package?
|
|
120
153
|
internals.amplify as any,
|
|
121
|
-
|
|
154
|
+
{
|
|
155
|
+
...options,
|
|
156
|
+
endpoint: clientEndpoint,
|
|
157
|
+
},
|
|
122
158
|
headers,
|
|
123
159
|
);
|
|
124
160
|
|
|
@@ -33,38 +33,47 @@ import {
|
|
|
33
33
|
* }),
|
|
34
34
|
* });
|
|
35
35
|
*/
|
|
36
|
-
export function generateClient<
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
export function generateClient<
|
|
37
|
+
T extends Record<any, any> = never,
|
|
38
|
+
WithCustomEndpoint extends boolean = false,
|
|
39
|
+
WithApiKey extends boolean = false,
|
|
40
|
+
>(
|
|
41
|
+
options: GenerateServerClientParams<WithCustomEndpoint, WithApiKey>,
|
|
42
|
+
): V6ClientSSRRequest<T, WithCustomEndpoint, WithApiKey> {
|
|
41
43
|
// passing `null` instance because each (future model) method must retrieve a valid instance
|
|
42
44
|
// from server context
|
|
43
|
-
const client = generateClientWithAmplifyInstance<
|
|
45
|
+
const client = generateClientWithAmplifyInstance<
|
|
46
|
+
T,
|
|
47
|
+
V6ClientSSRRequest<T, any, any>
|
|
48
|
+
>({
|
|
44
49
|
amplify: null,
|
|
45
|
-
|
|
46
|
-
authMode,
|
|
47
|
-
authToken,
|
|
50
|
+
...options,
|
|
48
51
|
});
|
|
49
52
|
|
|
50
53
|
// TODO: improve this and the next type
|
|
51
|
-
const prevGraphql = client.graphql as unknown as GraphQLMethod
|
|
54
|
+
const prevGraphql = client.graphql as unknown as GraphQLMethod<
|
|
55
|
+
WithCustomEndpoint,
|
|
56
|
+
WithApiKey
|
|
57
|
+
>;
|
|
52
58
|
|
|
53
59
|
const wrappedGraphql = (
|
|
54
60
|
contextSpec: AmplifyServer.ContextSpec,
|
|
55
|
-
|
|
61
|
+
innerOptions: GraphQLOptionsV6,
|
|
56
62
|
additionalHeaders?: CustomHeaders,
|
|
57
63
|
) => {
|
|
58
64
|
const amplifyInstance = getAmplifyServerContext(contextSpec).amplify;
|
|
59
65
|
|
|
60
66
|
return prevGraphql.call(
|
|
61
67
|
{ [__amplify]: amplifyInstance },
|
|
62
|
-
|
|
68
|
+
innerOptions as any,
|
|
63
69
|
additionalHeaders as any,
|
|
64
70
|
);
|
|
65
71
|
};
|
|
66
72
|
|
|
67
|
-
client.graphql = wrappedGraphql as unknown as GraphQLMethodSSR
|
|
73
|
+
client.graphql = wrappedGraphql as unknown as GraphQLMethodSSR<
|
|
74
|
+
WithCustomEndpoint,
|
|
75
|
+
WithApiKey
|
|
76
|
+
>;
|
|
68
77
|
|
|
69
78
|
return client;
|
|
70
79
|
}
|