From d20651fa161b9653c279edf343fb2d7b9f98885a Mon Sep 17 00:00:00 2001 From: Hui Zhao Date: Mon, 30 Oct 2023 13:08:08 -0700 Subject: [PATCH] chore(adapter-nextjs): update public APIs inline docs --- .../src/api/generateServerClient.ts | 26 ++++++++----------- .../adapter-nextjs/src/createServerRunner.ts | 22 ++++++++++++++-- 2 files changed, 31 insertions(+), 17 deletions(-) diff --git a/packages/adapter-nextjs/src/api/generateServerClient.ts b/packages/adapter-nextjs/src/api/generateServerClient.ts index 8c43c86e604..41229bd30ba 100644 --- a/packages/adapter-nextjs/src/api/generateServerClient.ts +++ b/packages/adapter-nextjs/src/api/generateServerClient.ts @@ -21,12 +21,10 @@ import { getAmplifyConfig } from '../utils'; * Generates an API client that can be used inside a Next.js Server Component with Dynamic Rendering * * @example - * ```ts * import { cookies } from "next/headers" * - * const client = generateServerClientUsingCookies({ cookies }) - * const result = await client.graphql({query: listPosts}) - * ``` + * const client = generateServerClientUsingCookies({ cookies }); + * const result = await client.graphql({ query: listPosts }); */ export function generateServerClientUsingCookies< T extends Record = never @@ -68,19 +66,17 @@ export function generateServerClientUsingCookies< * Generates an API client that can be used with both Pages Router and App Router * * @example - * ```ts + * import config from './amplifyconfiguration.json'; + * import { listPosts } from './graphql/queries'; + * + * const client = generateServerClientUsingReqRes(); * - * const client = generateServerClient() - * * result = await runWithAmplifyServerContext({ - nextServerContext: { request, response }, - operation: async (contextSpec) => { - return await client.graphql(contextSpec, { - query: listPosts, - }) - }, - }) - * ``` + * nextServerContext: { request, response }, + * operation: (contextSpec) => client.graphql(contextSpec, { + * query: listPosts, + * }), + * }); */ export function generateServerClientUsingReqRes< T extends Record = never diff --git a/packages/adapter-nextjs/src/createServerRunner.ts b/packages/adapter-nextjs/src/createServerRunner.ts index f6d39566b56..7b39007e494 100644 --- a/packages/adapter-nextjs/src/createServerRunner.ts +++ b/packages/adapter-nextjs/src/createServerRunner.ts @@ -1,14 +1,32 @@ // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 -import { ResourcesConfig } from '@aws-amplify/core'; -import { parseAWSExports } from '@aws-amplify/core/internals/utils'; +import { ResourcesConfig } from 'aws-amplify'; import { AmplifyServerContextError } from '@aws-amplify/core/internals/adapter-core'; import { createRunWithAmplifyServerContext, getAmplifyConfig } from './utils'; import { NextServer } from './types'; let amplifyConfig: ResourcesConfig | undefined; +/** + * Creates the `runWithAmplifyServerContext` function to run Amplify server side APIs in an isolated request context. + * + * @remarks + * This function should be called only once; you can use the returned `runWithAmplifyServerContext` across + * your codebase. + * + * @param input The input used to create the `runWithAmplifyServerContext` function. + * @param input.config The {@link ResourcesConfig} imported from the `amplifyconfiguration.json` file or manually + * created. + * @returns An object that contains the `runWithAmplifyServerContext` function. + * + * @example + * import { createServerRunner } from '@aws-amplify/adapter-nextjs'; + * import config from './amplifyconfiguration.json'; + * + * export const { runWithAmplifyServerContext } = createServerRunner({ config }) + * + */ export const createServerRunner: NextServer.CreateServerRunner = ({ config, }) => {