How to start the graphql server in new version of next js 13.2 api route?

1.2k views Asked by At

Unable to start the server in next js 13.2.

import { ApolloServer } from '@apollo/server';
import { startServerAndCreateNextHandler } from '@as-integrations/next';

const resolvers = {
  Query: {
    hello: () => 'world',
  },
};

const typeDefs = `#graphql
  type Query {
    hello: String
  }
`;

const server = new ApolloServer({
  resolvers,
  typeDefs,
});


export async function GET(request: Request) {
  return startServerAndCreateNextHandler(server);
}

I tried to integrate the graphql server in next js 13.2 app directory api route but it's not working for me.

2

There are 2 answers

0
Teffi On BEST ANSWER

Unless you have a different workflow requirement, you seem to be missing the default?

Replace export async function ... to

export default startServerAndCreateNextHandler(server);

Here's the reference for sample integration on NextJS https://github.com/apollo-server-integrations/apollo-server-integration-next

0
nbaird On

The @as-integrations/next package hasn't been updated to work with this feature yet, but in the issues someone has modified the code to work.