@aws-amplify/api-graphql 4.0.7-unstable.f21f8f1.0 → 4.0.7-upgrade-node-18.062f74f.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/server/{generateClient.js → generateClientWithAmplifyInstance.js} +7 -5
- package/dist/cjs/internals/server/generateClientWithAmplifyInstance.js.map +1 -0
- package/dist/cjs/internals/server/index.js +3 -3
- package/dist/cjs/internals/server/index.js.map +1 -1
- package/dist/cjs/server/generateClient.js +45 -0
- package/dist/cjs/server/generateClient.js.map +1 -0
- package/dist/cjs/server/index.js +9 -0
- package/dist/cjs/server/index.js.map +1 -0
- package/dist/esm/internals/server/{generateClient.d.ts → generateClientWithAmplifyInstance.d.ts} +3 -1
- package/dist/esm/internals/server/{generateClient.mjs → generateClientWithAmplifyInstance.mjs} +5 -3
- package/dist/esm/internals/server/generateClientWithAmplifyInstance.mjs.map +1 -0
- package/dist/esm/internals/server/index.d.ts +1 -1
- package/dist/esm/internals/server/index.mjs +1 -1
- package/dist/esm/server/generateClient.d.ts +18 -0
- package/dist/esm/server/generateClient.mjs +43 -0
- package/dist/esm/server/generateClient.mjs.map +1 -0
- package/dist/esm/server/index.d.ts +1 -0
- package/dist/esm/server/index.mjs +2 -0
- package/dist/esm/server/index.mjs.map +1 -0
- package/dist/esm/types/index.d.ts +5 -0
- package/package.json +11 -5
- package/server/package.json +7 -0
- package/src/internals/server/{generateClient.ts → generateClientWithAmplifyInstance.ts} +4 -2
- package/src/internals/server/index.ts +1 -1
- package/src/server/generateClient.ts +67 -0
- package/src/server/index.ts +4 -0
- package/src/types/index.ts +6 -0
- package/dist/cjs/internals/server/generateClient.js.map +0 -1
- package/dist/esm/internals/server/generateClient.mjs.map +0 -1
package/dist/cjs/internals/server/{generateClient.js → generateClientWithAmplifyInstance.js}
RENAMED
|
@@ -3,20 +3,22 @@
|
|
|
3
3
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
4
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
const __1 = require("
|
|
6
|
+
exports.generateClientWithAmplifyInstance = void 0;
|
|
7
|
+
const __1 = require("..");
|
|
8
8
|
const generateModelsProperty_1 = require("./generateModelsProperty");
|
|
9
9
|
const types_1 = require("../../types");
|
|
10
10
|
/**
|
|
11
11
|
* @private
|
|
12
12
|
*
|
|
13
|
+
* Used internally by `adapter-nextjs` package.
|
|
14
|
+
*
|
|
13
15
|
* Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`
|
|
14
16
|
* compatible context object for config and auth fetching.
|
|
15
17
|
*
|
|
16
18
|
* @param params
|
|
17
19
|
* @returns
|
|
18
20
|
*/
|
|
19
|
-
function
|
|
21
|
+
function generateClientWithAmplifyInstance(params) {
|
|
20
22
|
const client = {
|
|
21
23
|
[types_1.__amplify]: params.amplify,
|
|
22
24
|
[types_1.__authMode]: params.authMode,
|
|
@@ -28,5 +30,5 @@ function generateClient(params) {
|
|
|
28
30
|
client.models = (0, generateModelsProperty_1.generateModelsProperty)(client, params);
|
|
29
31
|
return client;
|
|
30
32
|
}
|
|
31
|
-
exports.
|
|
32
|
-
//# sourceMappingURL=
|
|
33
|
+
exports.generateClientWithAmplifyInstance = generateClientWithAmplifyInstance;
|
|
34
|
+
//# sourceMappingURL=generateClientWithAmplifyInstance.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateClientWithAmplifyInstance.js","sources":["../../../../src/internals/server/generateClientWithAmplifyInstance.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.generateClientWithAmplifyInstance = void 0;\nconst __1 = require(\"..\");\nconst generateModelsProperty_1 = require(\"./generateModelsProperty\");\nconst types_1 = require(\"../../types\");\n/**\n * @private\n *\n * Used internally by `adapter-nextjs` package.\n *\n * Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`\n * compatible context object for config and auth fetching.\n *\n * @param params\n * @returns\n */\nfunction generateClientWithAmplifyInstance(params) {\n const client = {\n [types_1.__amplify]: params.amplify,\n [types_1.__authMode]: params.authMode,\n [types_1.__authToken]: params.authToken,\n graphql: __1.graphql,\n cancel: __1.cancel,\n isCancelError: __1.isCancelError,\n };\n client.models = (0, generateModelsProperty_1.generateModelsProperty)(client, params);\n return client;\n}\nexports.generateClientWithAmplifyInstance = generateClientWithAmplifyInstance;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,iCAAiC,GAAG,KAAK,CAAC,CAAC;AACnD,MAAM,GAAG,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAC1B,MAAM,wBAAwB,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;AACrE,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AACvC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,iCAAiC,CAAC,MAAM,EAAE;AACnD,IAAI,MAAM,MAAM,GAAG;AACnB,QAAQ,CAAC,OAAO,CAAC,SAAS,GAAG,MAAM,CAAC,OAAO;AAC3C,QAAQ,CAAC,OAAO,CAAC,UAAU,GAAG,MAAM,CAAC,QAAQ;AAC7C,QAAQ,CAAC,OAAO,CAAC,WAAW,GAAG,MAAM,CAAC,SAAS;AAC/C,QAAQ,OAAO,EAAE,GAAG,CAAC,OAAO;AAC5B,QAAQ,MAAM,EAAE,GAAG,CAAC,MAAM;AAC1B,QAAQ,aAAa,EAAE,GAAG,CAAC,aAAa;AACxC,KAAK,CAAC;AACN,IAAI,MAAM,CAAC,MAAM,GAAG,IAAI,wBAAwB,CAAC,sBAAsB,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACzF,IAAI,OAAO,MAAM,CAAC;AAClB,CAAC;AACD,OAAO,CAAC,iCAAiC,GAAG,iCAAiC;;"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
4
|
// SPDX-License-Identifier: Apache-2.0
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
7
|
-
var
|
|
8
|
-
Object.defineProperty(exports, "
|
|
6
|
+
exports.generateClientWithAmplifyInstance = void 0;
|
|
7
|
+
var generateClientWithAmplifyInstance_1 = require("./generateClientWithAmplifyInstance");
|
|
8
|
+
Object.defineProperty(exports, "generateClientWithAmplifyInstance", { enumerable: true, get: function () { return generateClientWithAmplifyInstance_1.generateClientWithAmplifyInstance; } });
|
|
9
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../../src/internals/server/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../src/internals/server/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.generateClientWithAmplifyInstance = void 0;\nvar generateClientWithAmplifyInstance_1 = require(\"./generateClientWithAmplifyInstance\");\nObject.defineProperty(exports, \"generateClientWithAmplifyInstance\", { enumerable: true, get: function () { return generateClientWithAmplifyInstance_1.generateClientWithAmplifyInstance; } });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,iCAAiC,GAAG,KAAK,CAAC,CAAC;AACnD,IAAI,mCAAmC,GAAG,OAAO,CAAC,qCAAqC,CAAC,CAAC;AACzF,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,mCAAmC,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,mCAAmC,CAAC,iCAAiC,CAAC,EAAE,EAAE,CAAC;;"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateClient = void 0;
|
|
7
|
+
const adapter_core_1 = require("@aws-amplify/core/internals/adapter-core");
|
|
8
|
+
const server_1 = require("../internals/server");
|
|
9
|
+
const types_1 = require("../types");
|
|
10
|
+
/**
|
|
11
|
+
* Generates an GraphQL API client that works with Amplify server context.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* import config from './amplifyconfiguration.json';
|
|
15
|
+
* import { listPosts } from './graphql/queries';
|
|
16
|
+
*
|
|
17
|
+
* const client = generateServerClient({ config });
|
|
18
|
+
*
|
|
19
|
+
* const result = await runWithAmplifyServerContext({
|
|
20
|
+
* nextServerContext: { request, response },
|
|
21
|
+
* operation: (contextSpec) => client.graphql(contextSpec, {
|
|
22
|
+
* query: listPosts,
|
|
23
|
+
* }),
|
|
24
|
+
* });
|
|
25
|
+
*/
|
|
26
|
+
function generateClient({ config, authMode, authToken, }) {
|
|
27
|
+
// passing `null` instance because each (future model) method must retrieve a valid instance
|
|
28
|
+
// from server context
|
|
29
|
+
const client = (0, server_1.generateClientWithAmplifyInstance)({
|
|
30
|
+
amplify: null,
|
|
31
|
+
config,
|
|
32
|
+
authMode,
|
|
33
|
+
authToken,
|
|
34
|
+
});
|
|
35
|
+
// TODO: improve this and the next type
|
|
36
|
+
const prevGraphql = client.graphql;
|
|
37
|
+
const wrappedGraphql = (contextSpec, options, additionalHeaders) => {
|
|
38
|
+
const amplifyInstance = (0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify;
|
|
39
|
+
return prevGraphql.call({ [types_1.__amplify]: amplifyInstance }, options, additionalHeaders);
|
|
40
|
+
};
|
|
41
|
+
client.graphql = wrappedGraphql;
|
|
42
|
+
return client;
|
|
43
|
+
}
|
|
44
|
+
exports.generateClient = generateClient;
|
|
45
|
+
//# sourceMappingURL=generateClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateClient.js","sources":["../../../src/server/generateClient.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.generateClient = void 0;\nconst adapter_core_1 = require(\"@aws-amplify/core/internals/adapter-core\");\nconst server_1 = require(\"../internals/server\");\nconst types_1 = require(\"../types\");\n/**\n * Generates an GraphQL API client that works with Amplify server context.\n *\n * @example\n * import config from './amplifyconfiguration.json';\n * import { listPosts } from './graphql/queries';\n *\n * const client = generateServerClient({ config });\n *\n * const result = await runWithAmplifyServerContext({\n * nextServerContext: { request, response },\n * operation: (contextSpec) => client.graphql(contextSpec, {\n * query: listPosts,\n * }),\n * });\n */\nfunction generateClient({ config, authMode, authToken, }) {\n // passing `null` instance because each (future model) method must retrieve a valid instance\n // from server context\n const client = (0, server_1.generateClientWithAmplifyInstance)({\n amplify: null,\n config,\n authMode,\n authToken,\n });\n // TODO: improve this and the next type\n const prevGraphql = client.graphql;\n const wrappedGraphql = (contextSpec, options, additionalHeaders) => {\n const amplifyInstance = (0, adapter_core_1.getAmplifyServerContext)(contextSpec).amplify;\n return prevGraphql.call({ [types_1.__amplify]: amplifyInstance }, options, additionalHeaders);\n };\n client.graphql = wrappedGraphql;\n return client;\n}\nexports.generateClient = generateClient;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,cAAc,GAAG,KAAK,CAAC,CAAC;AAChC,MAAM,cAAc,GAAG,OAAO,CAAC,0CAA0C,CAAC,CAAC;AAC3E,MAAM,QAAQ,GAAG,OAAO,CAAC,qBAAqB,CAAC,CAAC;AAChD,MAAM,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AACpC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,cAAc,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,GAAG,EAAE;AAC1D;AACA;AACA,IAAI,MAAM,MAAM,GAAG,IAAI,QAAQ,CAAC,iCAAiC,EAAE;AACnE,QAAQ,OAAO,EAAE,IAAI;AACrB,QAAQ,MAAM;AACd,QAAQ,QAAQ;AAChB,QAAQ,SAAS;AACjB,KAAK,CAAC,CAAC;AACP;AACA,IAAI,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC;AACvC,IAAI,MAAM,cAAc,GAAG,CAAC,WAAW,EAAE,OAAO,EAAE,iBAAiB,KAAK;AACxE,QAAQ,MAAM,eAAe,GAAG,IAAI,cAAc,CAAC,uBAAuB,EAAE,WAAW,CAAC,CAAC,OAAO,CAAC;AACjG,QAAQ,OAAO,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,OAAO,CAAC,SAAS,GAAG,eAAe,EAAE,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC;AACtG,KAAK,CAAC;AACN,IAAI,MAAM,CAAC,OAAO,GAAG,cAAc,CAAC;AACpC,IAAI,OAAO,MAAM,CAAC;AAClB,CAAC;AACD,OAAO,CAAC,cAAc,GAAG,cAAc;;"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
4
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.generateClient = void 0;
|
|
7
|
+
var generateClient_1 = require("./generateClient");
|
|
8
|
+
Object.defineProperty(exports, "generateClient", { enumerable: true, get: function () { return generateClient_1.generateClient; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/server/index.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.generateClient = void 0;\nvar generateClient_1 = require(\"./generateClient\");\nObject.defineProperty(exports, \"generateClient\", { enumerable: true, get: function () { return generateClient_1.generateClient; } });\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,cAAc,GAAG,KAAK,CAAC,CAAC;AAChC,IAAI,gBAAgB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;AACnD,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,gBAAgB,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,YAAY,EAAE,OAAO,gBAAgB,CAAC,cAAc,CAAC,EAAE,EAAE,CAAC;;"}
|
package/dist/esm/internals/server/{generateClient.d.ts → generateClientWithAmplifyInstance.d.ts}
RENAMED
|
@@ -2,10 +2,12 @@ import { V6ClientSSRRequest, V6ClientSSRCookies, ServerClientGenerationParams, C
|
|
|
2
2
|
/**
|
|
3
3
|
* @private
|
|
4
4
|
*
|
|
5
|
+
* Used internally by `adapter-nextjs` package.
|
|
6
|
+
*
|
|
5
7
|
* Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`
|
|
6
8
|
* compatible context object for config and auth fetching.
|
|
7
9
|
*
|
|
8
10
|
* @param params
|
|
9
11
|
* @returns
|
|
10
12
|
*/
|
|
11
|
-
export declare function
|
|
13
|
+
export declare function generateClientWithAmplifyInstance<T extends Record<any, any> = never, ClientType extends V6ClientSSRRequest<T> | V6ClientSSRCookies<T> = V6ClientSSRCookies<T>>(params: ServerClientGenerationParams & CommonPublicClientOptions): ClientType;
|
package/dist/esm/internals/server/{generateClient.mjs → generateClientWithAmplifyInstance.mjs}
RENAMED
|
@@ -10,13 +10,15 @@ import { generateModelsProperty } from './generateModelsProperty.mjs';
|
|
|
10
10
|
/**
|
|
11
11
|
* @private
|
|
12
12
|
*
|
|
13
|
+
* Used internally by `adapter-nextjs` package.
|
|
14
|
+
*
|
|
13
15
|
* Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`
|
|
14
16
|
* compatible context object for config and auth fetching.
|
|
15
17
|
*
|
|
16
18
|
* @param params
|
|
17
19
|
* @returns
|
|
18
20
|
*/
|
|
19
|
-
function
|
|
21
|
+
function generateClientWithAmplifyInstance(params) {
|
|
20
22
|
const client = {
|
|
21
23
|
[__amplify]: params.amplify,
|
|
22
24
|
[__authMode]: params.authMode,
|
|
@@ -29,5 +31,5 @@ function generateClient(params) {
|
|
|
29
31
|
return client;
|
|
30
32
|
}
|
|
31
33
|
|
|
32
|
-
export {
|
|
33
|
-
//# sourceMappingURL=
|
|
34
|
+
export { generateClientWithAmplifyInstance };
|
|
35
|
+
//# sourceMappingURL=generateClientWithAmplifyInstance.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateClientWithAmplifyInstance.mjs","sources":["../../../../src/internals/server/generateClientWithAmplifyInstance.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { graphql, cancel, isCancelError } from '..';\nimport { generateModelsProperty } from './generateModelsProperty';\nimport { __amplify, __authMode, __authToken, } from '../../types';\n/**\n * @private\n *\n * Used internally by `adapter-nextjs` package.\n *\n * Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`\n * compatible context object for config and auth fetching.\n *\n * @param params\n * @returns\n */\nexport function generateClientWithAmplifyInstance(params) {\n const client = {\n [__amplify]: params.amplify,\n [__authMode]: params.authMode,\n [__authToken]: params.authToken,\n graphql,\n cancel,\n isCancelError,\n };\n client.models = generateModelsProperty(client, params);\n return client;\n}\n"],"names":[],"mappings":";;;;;;;AAAA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,iCAAiC,CAAC,MAAM,EAAE;AAC1D,IAAI,MAAM,MAAM,GAAG;AACnB,QAAQ,CAAC,SAAS,GAAG,MAAM,CAAC,OAAO;AACnC,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC,QAAQ;AACrC,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,SAAS;AACvC,QAAQ,OAAO;AACf,QAAQ,MAAM;AACd,QAAQ,aAAa;AACrB,KAAK,CAAC;AACN,IAAI,MAAM,CAAC,MAAM,GAAG,sBAAsB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC3D,IAAI,OAAO,MAAM,CAAC;AAClB;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { generateClientWithAmplifyInstance } from './generateClientWithAmplifyInstance';
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { generateClientWithAmplifyInstance } from './generateClientWithAmplifyInstance.mjs';
|
|
2
2
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { GenerateServerClientParams, V6ClientSSRRequest } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Generates an GraphQL API client that works with Amplify server context.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* import config from './amplifyconfiguration.json';
|
|
7
|
+
* import { listPosts } from './graphql/queries';
|
|
8
|
+
*
|
|
9
|
+
* const client = generateServerClient({ config });
|
|
10
|
+
*
|
|
11
|
+
* const result = await runWithAmplifyServerContext({
|
|
12
|
+
* nextServerContext: { request, response },
|
|
13
|
+
* operation: (contextSpec) => client.graphql(contextSpec, {
|
|
14
|
+
* query: listPosts,
|
|
15
|
+
* }),
|
|
16
|
+
* });
|
|
17
|
+
*/
|
|
18
|
+
export declare function generateClient<T extends Record<any, any> = never>({ config, authMode, authToken, }: GenerateServerClientParams): V6ClientSSRRequest<T>;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { getAmplifyServerContext } from '@aws-amplify/core/internals/adapter-core';
|
|
2
|
+
import { generateClientWithAmplifyInstance } from '../internals/server/generateClientWithAmplifyInstance.mjs';
|
|
3
|
+
import { __amplify } from '../types/index.mjs';
|
|
4
|
+
|
|
5
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
6
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
7
|
+
/**
|
|
8
|
+
* Generates an GraphQL API client that works with Amplify server context.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* import config from './amplifyconfiguration.json';
|
|
12
|
+
* import { listPosts } from './graphql/queries';
|
|
13
|
+
*
|
|
14
|
+
* const client = generateServerClient({ config });
|
|
15
|
+
*
|
|
16
|
+
* const result = await runWithAmplifyServerContext({
|
|
17
|
+
* nextServerContext: { request, response },
|
|
18
|
+
* operation: (contextSpec) => client.graphql(contextSpec, {
|
|
19
|
+
* query: listPosts,
|
|
20
|
+
* }),
|
|
21
|
+
* });
|
|
22
|
+
*/
|
|
23
|
+
function generateClient({ config, authMode, authToken, }) {
|
|
24
|
+
// passing `null` instance because each (future model) method must retrieve a valid instance
|
|
25
|
+
// from server context
|
|
26
|
+
const client = generateClientWithAmplifyInstance({
|
|
27
|
+
amplify: null,
|
|
28
|
+
config,
|
|
29
|
+
authMode,
|
|
30
|
+
authToken,
|
|
31
|
+
});
|
|
32
|
+
// TODO: improve this and the next type
|
|
33
|
+
const prevGraphql = client.graphql;
|
|
34
|
+
const wrappedGraphql = (contextSpec, options, additionalHeaders) => {
|
|
35
|
+
const amplifyInstance = getAmplifyServerContext(contextSpec).amplify;
|
|
36
|
+
return prevGraphql.call({ [__amplify]: amplifyInstance }, options, additionalHeaders);
|
|
37
|
+
};
|
|
38
|
+
client.graphql = wrappedGraphql;
|
|
39
|
+
return client;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export { generateClient };
|
|
43
|
+
//# sourceMappingURL=generateClient.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generateClient.mjs","sources":["../../../src/server/generateClient.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { getAmplifyServerContext, } from '@aws-amplify/core/internals/adapter-core';\nimport { generateClientWithAmplifyInstance } from '../internals/server';\nimport { __amplify, } from '../types';\n/**\n * Generates an GraphQL API client that works with Amplify server context.\n *\n * @example\n * import config from './amplifyconfiguration.json';\n * import { listPosts } from './graphql/queries';\n *\n * const client = generateServerClient({ config });\n *\n * const result = await runWithAmplifyServerContext({\n * nextServerContext: { request, response },\n * operation: (contextSpec) => client.graphql(contextSpec, {\n * query: listPosts,\n * }),\n * });\n */\nexport function generateClient({ config, authMode, authToken, }) {\n // passing `null` instance because each (future model) method must retrieve a valid instance\n // from server context\n const client = generateClientWithAmplifyInstance({\n amplify: null,\n config,\n authMode,\n authToken,\n });\n // TODO: improve this and the next type\n const prevGraphql = client.graphql;\n const wrappedGraphql = (contextSpec, options, additionalHeaders) => {\n const amplifyInstance = getAmplifyServerContext(contextSpec).amplify;\n return prevGraphql.call({ [__amplify]: amplifyInstance }, options, additionalHeaders);\n };\n client.graphql = wrappedGraphql;\n return client;\n}\n"],"names":[],"mappings":";;;;AAAA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,cAAc,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,SAAS,GAAG,EAAE;AACjE;AACA;AACA,IAAI,MAAM,MAAM,GAAG,iCAAiC,CAAC;AACrD,QAAQ,OAAO,EAAE,IAAI;AACrB,QAAQ,MAAM;AACd,QAAQ,QAAQ;AAChB,QAAQ,SAAS;AACjB,KAAK,CAAC,CAAC;AACP;AACA,IAAI,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,CAAC;AACvC,IAAI,MAAM,cAAc,GAAG,CAAC,WAAW,EAAE,OAAO,EAAE,iBAAiB,KAAK;AACxE,QAAQ,MAAM,eAAe,GAAG,uBAAuB,CAAC,WAAW,CAAC,CAAC,OAAO,CAAC;AAC7E,QAAQ,OAAO,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC,SAAS,GAAG,eAAe,EAAE,EAAE,OAAO,EAAE,iBAAiB,CAAC,CAAC;AAC9F,KAAK,CAAC;AACN,IAAI,MAAM,CAAC,OAAO,GAAG,cAAc,CAAC;AACpC,IAAI,OAAO,MAAM,CAAC;AAClB;;;;"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { generateClient } from './generateClient';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":""}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@aws-amplify/api-graphql",
|
|
3
|
-
"version": "4.0.7-
|
|
3
|
+
"version": "4.0.7-upgrade-node-18.062f74f.0+062f74f",
|
|
4
4
|
"description": "Api-graphql category of aws-amplify",
|
|
5
5
|
"main": "./dist/cjs/index.js",
|
|
6
6
|
"module": "./dist/esm/index.mjs",
|
|
@@ -47,6 +47,11 @@
|
|
|
47
47
|
"require": "./dist/cjs/internals/server/index.js",
|
|
48
48
|
"react-native": "./src/internals/server/index.ts"
|
|
49
49
|
},
|
|
50
|
+
"./server": {
|
|
51
|
+
"types": "./dist/esm/server/index.d.ts",
|
|
52
|
+
"import": "./dist/esm/server/index.mjs",
|
|
53
|
+
"require": "./dist/cjs/server/index.js"
|
|
54
|
+
},
|
|
50
55
|
"./package.json": "./package.json"
|
|
51
56
|
},
|
|
52
57
|
"typesVersions": {
|
|
@@ -76,11 +81,12 @@
|
|
|
76
81
|
"dist/cjs",
|
|
77
82
|
"dist/esm",
|
|
78
83
|
"src",
|
|
79
|
-
"internals"
|
|
84
|
+
"internals",
|
|
85
|
+
"server"
|
|
80
86
|
],
|
|
81
87
|
"dependencies": {
|
|
82
|
-
"@aws-amplify/api-rest": "4.0.7-
|
|
83
|
-
"@aws-amplify/core": "6.0.7-
|
|
88
|
+
"@aws-amplify/api-rest": "4.0.7-upgrade-node-18.062f74f.0+062f74f",
|
|
89
|
+
"@aws-amplify/core": "6.0.7-upgrade-node-18.062f74f.0+062f74f",
|
|
84
90
|
"@aws-amplify/data-schema-types": "^0.6.6",
|
|
85
91
|
"@aws-sdk/types": "3.387.0",
|
|
86
92
|
"graphql": "15.8.0",
|
|
@@ -96,5 +102,5 @@
|
|
|
96
102
|
"limit": "91.7 kB"
|
|
97
103
|
}
|
|
98
104
|
],
|
|
99
|
-
"gitHead": "
|
|
105
|
+
"gitHead": "062f74febddfabf52c2608fb00d9d362ffe11af1"
|
|
100
106
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0
|
|
3
3
|
|
|
4
|
-
import { graphql, cancel, isCancelError } from '
|
|
4
|
+
import { graphql, cancel, isCancelError } from '..';
|
|
5
5
|
import { generateModelsProperty } from './generateModelsProperty';
|
|
6
6
|
import {
|
|
7
7
|
__amplify,
|
|
@@ -16,13 +16,15 @@ import {
|
|
|
16
16
|
/**
|
|
17
17
|
* @private
|
|
18
18
|
*
|
|
19
|
+
* Used internally by `adapter-nextjs` package.
|
|
20
|
+
*
|
|
19
21
|
* Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`
|
|
20
22
|
* compatible context object for config and auth fetching.
|
|
21
23
|
*
|
|
22
24
|
* @param params
|
|
23
25
|
* @returns
|
|
24
26
|
*/
|
|
25
|
-
export function
|
|
27
|
+
export function generateClientWithAmplifyInstance<
|
|
26
28
|
T extends Record<any, any> = never,
|
|
27
29
|
ClientType extends
|
|
28
30
|
| V6ClientSSRRequest<T>
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
AmplifyServer,
|
|
6
|
+
getAmplifyServerContext,
|
|
7
|
+
} from '@aws-amplify/core/internals/adapter-core';
|
|
8
|
+
import { generateClientWithAmplifyInstance } from '../internals/server';
|
|
9
|
+
import {
|
|
10
|
+
GenerateServerClientParams,
|
|
11
|
+
GraphQLMethod,
|
|
12
|
+
GraphQLMethodSSR,
|
|
13
|
+
GraphQLOptionsV6,
|
|
14
|
+
V6ClientSSRRequest,
|
|
15
|
+
__amplify,
|
|
16
|
+
} from '../types';
|
|
17
|
+
import { CustomHeaders } from '@aws-amplify/data-schema-types';
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Generates an GraphQL API client that works with Amplify server context.
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* import config from './amplifyconfiguration.json';
|
|
24
|
+
* import { listPosts } from './graphql/queries';
|
|
25
|
+
*
|
|
26
|
+
* const client = generateServerClient({ config });
|
|
27
|
+
*
|
|
28
|
+
* const result = await runWithAmplifyServerContext({
|
|
29
|
+
* nextServerContext: { request, response },
|
|
30
|
+
* operation: (contextSpec) => client.graphql(contextSpec, {
|
|
31
|
+
* query: listPosts,
|
|
32
|
+
* }),
|
|
33
|
+
* });
|
|
34
|
+
*/
|
|
35
|
+
export function generateClient<T extends Record<any, any> = never>({
|
|
36
|
+
config,
|
|
37
|
+
authMode,
|
|
38
|
+
authToken,
|
|
39
|
+
}: GenerateServerClientParams): V6ClientSSRRequest<T> {
|
|
40
|
+
// passing `null` instance because each (future model) method must retrieve a valid instance
|
|
41
|
+
// from server context
|
|
42
|
+
const client = generateClientWithAmplifyInstance<T, V6ClientSSRRequest<T>>({
|
|
43
|
+
amplify: null,
|
|
44
|
+
config,
|
|
45
|
+
authMode,
|
|
46
|
+
authToken,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// TODO: improve this and the next type
|
|
50
|
+
const prevGraphql = client.graphql as unknown as GraphQLMethod;
|
|
51
|
+
|
|
52
|
+
const wrappedGraphql = (
|
|
53
|
+
contextSpec: AmplifyServer.ContextSpec,
|
|
54
|
+
options: GraphQLOptionsV6,
|
|
55
|
+
additionalHeaders?: CustomHeaders
|
|
56
|
+
) => {
|
|
57
|
+
const amplifyInstance = getAmplifyServerContext(contextSpec).amplify;
|
|
58
|
+
return prevGraphql.call(
|
|
59
|
+
{ [__amplify]: amplifyInstance },
|
|
60
|
+
options,
|
|
61
|
+
additionalHeaders as any
|
|
62
|
+
);
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
client.graphql = wrappedGraphql as unknown as GraphQLMethodSSR;
|
|
66
|
+
return client;
|
|
67
|
+
}
|
package/src/types/index.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateClient.js","sources":["../../../../src/internals/server/generateClient.ts"],"sourcesContent":["\"use strict\";\n// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nObject.defineProperty(exports, \"__esModule\", { value: true });\nexports.generateClient = void 0;\nconst __1 = require(\"../\");\nconst generateModelsProperty_1 = require(\"./generateModelsProperty\");\nconst types_1 = require(\"../../types\");\n/**\n * @private\n *\n * Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`\n * compatible context object for config and auth fetching.\n *\n * @param params\n * @returns\n */\nfunction generateClient(params) {\n const client = {\n [types_1.__amplify]: params.amplify,\n [types_1.__authMode]: params.authMode,\n [types_1.__authToken]: params.authToken,\n graphql: __1.graphql,\n cancel: __1.cancel,\n isCancelError: __1.isCancelError,\n };\n client.models = (0, generateModelsProperty_1.generateModelsProperty)(client, params);\n return client;\n}\nexports.generateClient = generateClient;\n"],"names":[],"mappings":";;AACA;AACA;AACA,MAAM,CAAC,cAAc,CAAC,OAAO,EAAE,YAAY,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;AAC9D,OAAO,CAAC,cAAc,GAAG,KAAK,CAAC,CAAC;AAChC,MAAM,GAAG,GAAG,OAAO,CAAC,KAAK,CAAC,CAAC;AAC3B,MAAM,wBAAwB,GAAG,OAAO,CAAC,0BAA0B,CAAC,CAAC;AACrE,MAAM,OAAO,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AACvC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAAS,cAAc,CAAC,MAAM,EAAE;AAChC,IAAI,MAAM,MAAM,GAAG;AACnB,QAAQ,CAAC,OAAO,CAAC,SAAS,GAAG,MAAM,CAAC,OAAO;AAC3C,QAAQ,CAAC,OAAO,CAAC,UAAU,GAAG,MAAM,CAAC,QAAQ;AAC7C,QAAQ,CAAC,OAAO,CAAC,WAAW,GAAG,MAAM,CAAC,SAAS;AAC/C,QAAQ,OAAO,EAAE,GAAG,CAAC,OAAO;AAC5B,QAAQ,MAAM,EAAE,GAAG,CAAC,MAAM;AAC1B,QAAQ,aAAa,EAAE,GAAG,CAAC,aAAa;AACxC,KAAK,CAAC;AACN,IAAI,MAAM,CAAC,MAAM,GAAG,IAAI,wBAAwB,CAAC,sBAAsB,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;AACzF,IAAI,OAAO,MAAM,CAAC;AAClB,CAAC;AACD,OAAO,CAAC,cAAc,GAAG,cAAc;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"generateClient.mjs","sources":["../../../../src/internals/server/generateClient.ts"],"sourcesContent":["// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.\n// SPDX-License-Identifier: Apache-2.0\nimport { graphql, cancel, isCancelError } from '../';\nimport { generateModelsProperty } from './generateModelsProperty';\nimport { __amplify, __authMode, __authToken, } from '../../types';\n/**\n * @private\n *\n * Creates a client that can be used to make GraphQL requests, using a provided `AmplifyClassV6`\n * compatible context object for config and auth fetching.\n *\n * @param params\n * @returns\n */\nexport function generateClient(params) {\n const client = {\n [__amplify]: params.amplify,\n [__authMode]: params.authMode,\n [__authToken]: params.authToken,\n graphql,\n cancel,\n isCancelError,\n };\n client.models = generateModelsProperty(client, params);\n return client;\n}\n"],"names":[],"mappings":";;;;;;;AAAA;AACA;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAAS,cAAc,CAAC,MAAM,EAAE;AACvC,IAAI,MAAM,MAAM,GAAG;AACnB,QAAQ,CAAC,SAAS,GAAG,MAAM,CAAC,OAAO;AACnC,QAAQ,CAAC,UAAU,GAAG,MAAM,CAAC,QAAQ;AACrC,QAAQ,CAAC,WAAW,GAAG,MAAM,CAAC,SAAS;AACvC,QAAQ,OAAO;AACf,QAAQ,MAAM;AACd,QAAQ,aAAa;AACrB,KAAK,CAAC;AACN,IAAI,MAAM,CAAC,MAAM,GAAG,sBAAsB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC3D,IAAI,OAAO,MAAM,CAAC;AAClB;;;;"}
|