Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(adapter-nextjs): update public APIs inline docs #12472

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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';
jimblanc marked this conversation as resolved.
Show resolved Hide resolved
* import config from './amplifyconfiguration.json';
*
* export const { runWithAmplifyServerContext } = createServerRunner({ config })
*
*/
export const createServerRunner: NextServer.CreateServerRunner = ({
config,
}) => {
Expand Down
Loading