11# @react-libraries/next-apollo-server
22
33Package for calling ApolloServer4 from Next.js.
4+
45'scalar Upload' is available for multipart data.
6+ The following headers need to be added to the client-side request in order for the upload to take place.
7+
8+ ``` ts
9+ {' apollo-require-preflight' : ' true' }
10+ ```
511
612## Sample
713
@@ -16,11 +22,11 @@ Package for calling ApolloServer4 from Next.js.
1622``` ts
1723import { promises as fs } from " fs" ;
1824import { ApolloServer } from " @apollo/server" ;
19- import { IResolvers } from " @graphql-tools/utils" ;
2025import {
2126 executeHTTPGraphQLRequest ,
2227 FormidableFile ,
2328} from " @react-libraries/next-apollo-server" ;
29+ import type { IResolvers } from " @graphql-tools/utils" ;
2430import type { NextApiHandler , NextApiRequest , NextApiResponse } from " next" ;
2531
2632/**
@@ -74,22 +80,21 @@ const resolvers: IResolvers<Context> = {
7480const apolloServer = new ApolloServer <Context >({
7581 typeDefs ,
7682 resolvers ,
77- plugins: [],
7883});
7984apolloServer .start ();
8085
8186/**
8287 * APIRoute handler for Next.js
8388 */
8489const handler: NextApiHandler = async (req , res ) => {
85- // Convert NextApiRequest to body format for GraphQL (multipart/form-data support).
90+ // Convert NextApiRequest to body format for GraphQL (multipart/form-data support).
8691 return executeHTTPGraphQLRequest ({
8792 req ,
8893 res ,
8994 apolloServer ,
9095 context : async () => ({ req , res }),
9196 options: {
92- // Maximum upload file size set at 10 MB
97+ // Maximum upload file size set at 10 MB
9398 maxFileSize: 10 * 1024 * 1024 ,
9499 },
95100 });
0 commit comments