Skip to content

Commit

Permalink
fix readme
Browse files Browse the repository at this point in the history
  • Loading branch information
SoraKumo001 committed Jan 2, 2023
1 parent f52716f commit 2a4e247
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
# @react-libraries/next-apollo-server

Package for calling ApolloServer4 from Next.js.

'scalar Upload' is available for multipart data.
The following headers need to be added to the client-side request in order for the upload to take place.

```ts
{'apollo-require-preflight': 'true'}
```

## Sample

Expand All @@ -16,11 +22,11 @@ Package for calling ApolloServer4 from Next.js.
```ts
import { promises as fs } from "fs";
import { ApolloServer } from "@apollo/server";
import { IResolvers } from "@graphql-tools/utils";
import {
executeHTTPGraphQLRequest,
FormidableFile,
} from "@react-libraries/next-apollo-server";
import type { IResolvers } from "@graphql-tools/utils";
import type { NextApiHandler, NextApiRequest, NextApiResponse } from "next";

/**
Expand Down Expand Up @@ -74,22 +80,21 @@ const resolvers: IResolvers<Context> = {
const apolloServer = new ApolloServer<Context>({
typeDefs,
resolvers,
plugins: [],
});
apolloServer.start();

/**
* APIRoute handler for Next.js
*/
const handler: NextApiHandler = async (req, res) => {
// Convert NextApiRequest to body format for GraphQL (multipart/form-data support).
//Convert NextApiRequest to body format for GraphQL (multipart/form-data support).
return executeHTTPGraphQLRequest({
req,
res,
apolloServer,
context: async () => ({ req, res }),
options: {
// Maximum upload file size set at 10 MB
//Maximum upload file size set at 10 MB
maxFileSize: 10 * 1024 * 1024,
},
});
Expand Down
10 changes: 9 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@react-libraries/next-apollo-server",
"version": "0.0.1",
"version": "0.0.3",
"main": "dist/index.js",
"license": "MIT",
"scripts": {
Expand Down Expand Up @@ -28,5 +28,13 @@
"typescript": "^4.9.4"
},
"author": "SoraKumo <[email protected]>",
"keywords": [
"GraphQL",
"Apollo",
"Server",
"Next.js",
"Upload",
"multipart/form-data"
],
"repository": "https://github.com/ReactLibraries/next-apollo-server"
}

0 comments on commit 2a4e247

Please sign in to comment.