Skip to content

Commit

Permalink
chore(adapter-nextjs): update public APIs inline docs
Browse files Browse the repository at this point in the history
  • Loading branch information
HuiSF committed Oct 31, 2023
1 parent aaa7e98 commit a5fa255
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 17 deletions.
26 changes: 11 additions & 15 deletions packages/adapter-nextjs/src/api/generateServerClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any, any> = never
Expand Down Expand Up @@ -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<any, any> = never
Expand Down
22 changes: 20 additions & 2 deletions packages/adapter-nextjs/src/createServerRunner.ts
Original file line number Diff line number Diff line change
@@ -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,
}) => {
Expand Down

0 comments on commit a5fa255

Please sign in to comment.