#Unable to spin apollo server with API route | next 14.2

5 messages · Page 1 of 1 (latest)

rapid fox
#
//app/api/graphql/route.ts
import { startServerAndCreateNextHandler } from '@as-integrations/next';
import { ApolloServer } from '@apollo/server';
import { gql } from 'graphql-tag';
import { NextRequest } from 'next/server';

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

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

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

const handler = startServerAndCreateNextHandler<NextRequest>(server, {
    context: async req => ({ req }),
  });

export { handler as GET, handler as POST };

When I tried to visit http://localhost:3000/api/graphql I got this response

{
    "errors": [
        {
            "message": "module.require is not a function",
            "extensions": {
                "code": "INTERNAL_SERVER_ERROR",
                "stacktrace": [
                    "TypeError: module.require is not a function",
                    "    at createHash (.next\\server\\chunks\\node_modules__pnpm_f22ca6._.js:5380:23)",
                    "    at Object.html (.next\\server\\chunks\\node_modules__pnpm_7ff79c._.js:241:323)",
                    "    at ApolloServer.executeHTTPGraphQLRequest (.next\\server\\chunks\\53229_@apollo_server_dist_157170._.js:6283:77)"
                ]
            }
        }
    ]
}

what am I doing wrong here?

nocturne smeltBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

rapid fox
#

If I add

export const runtime = 'edge';

its working fine in development server

#

but unable to build the app because of some errors

Error: The edge runtime does not support Node.js 'path' module.

specifically this one

#

just for clarity I'm not using path anywhere in my entire app