#Build time error with api route.

1 messages · Page 1 of 1 (latest)

opaque mural
#

I get the below error when building the app, is anyone aware of how to resolve this?

Error:

Type error: Route "app/api/graphql/route.ts" has an invalid "GET" export:
  Type "undefined" is not a valid type for the function's second argument.
    Expected "RouteContext", got "undefined".

Code

import { startServerAndCreateNextHandler } from "@as-integrations/next";
import { ApolloServer } from "@apollo/server";
import { NextRequest } from "next/server";
import db from "@/lib/mongo/db";
import typeDefs from "./schema/typedefs";
import resolvers from "./schema/resolvers";


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

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

export { handler as GET, handler as POST };

native wrenBOT
#

🔎 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)

raven stump
#

According the documentation the context function requires a res in its signature

export default startServerAndCreateNextHandler<NextRequest>(server, {
  context: async (req, res) => {
    await db();
    return { req, res }
  }
});
#

Its either that or your call to db() is misbehaving