Skip to content

Commit ad66ef7

Browse files
Update README.md in line with Next 13.4+ (#130)
Co-authored-by: Trevor Scheer <[email protected]>
1 parent 03bdc85 commit ad66ef7

File tree

2 files changed

+16
-22
lines changed

2 files changed

+16
-22
lines changed

.changeset/moody-plums-brake.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@as-integrations/next': patch
3+
---
4+
5+
Update README.md in line with Next 13.4+

README.md

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,17 @@ export default startServerAndCreateNextHandler(server, {
4444

4545
The Next.js `req` and `res` objects are passed along to the context function.
4646

47-
## Route Handlers (experimental)
47+
## App Router (Route Handlers)
4848

49-
This integration has experimental support for Next.js' new Route Handlers feature.
49+
This integration has experimental support for [Next.js' App Router](https://nextjs.org/docs/app/building-your-application/routing/router-handlers), which is now the stable and default project structure for Next.js.
5050

51-
To use this integration with Route Handlers, first opt into Next.js' beta app directory by adding the following to `next.config.js`:
51+
Make sure you're on recent version of Next.js (13.4+), then create a new Route
52+
Handler file, for example at `app/api/graphql/route.js`.
5253

53-
```js
54-
module.exports = {
55-
experimental: {
56-
appDir: true,
57-
},
58-
};
59-
```
54+
This file's route handlers will be accessible at URI path `/api/graphql`.
6055

61-
Then create a new file at for example `app/graphql/route.js`.
62-
This file's route handlers will be accessible at `/graphql`.
63-
64-
Next create an Apollo Server instance, pass it to `startServerAndCreateNextHandler` and finally pass the handler to both a GET and a POST route handler:
56+
Next create an Apollo Server instance, pass it to `startServerAndCreateNextHandler` and
57+
finally pass the handler to both a GET and a POST route handler:
6558

6659
```js
6760
import { startServerAndCreateNextHandler } from '@as-integrations/next';
@@ -87,13 +80,7 @@ const server = new ApolloServer({
8780

8881
const handler = startServerAndCreateNextHandler(server);
8982

90-
export async function GET(request) {
91-
return handler(request);
92-
}
93-
94-
export async function POST(request) {
95-
return handler(request);
96-
}
83+
export { handler as GET, handler as POST };
9784
```
9885

9986
## Typescript
@@ -104,5 +91,7 @@ When using this integration with Route Handlers you will have to specify the typ
10491
import { NextRequest } from 'next/server';
10592

10693
// req has the type NextRequest
107-
const handler = startServerAndCreateNextHandler<NextRequest>(server, { context: async req => ({ req }) });
94+
const handler = startServerAndCreateNextHandler<NextRequest>(server, {
95+
context: async req => ({ req }),
96+
});
10897
```

0 commit comments

Comments
 (0)