2

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.

  • why is it not working? – drum Feb 27 '23 at 05:14
  • I am using next js 13.2 new api route handler with apollo server and next integration ( @as-integrations/next ). Expected behaviour is to start graphql server but it does not start the server. http://localhost:3001/api/graphql – Raja Jayaraman Feb 27 '23 at 06:22

2 Answers2

1

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

Teffi
  • 2,498
  • 4
  • 21
  • 40
0

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.

nbaird
  • 1
  • 1