apollo-server: TypeError: resolver is not a function using `apollo-server-micro` latest version v3.0.1

I have an old project using apollo-server-micro@2.21.2 like:

export default handler().use(
  new ApolloServer({
    schema,
    context: ({ req }): GraphQLContext => ({
      user: req.user,
      origin: getRequestOrigin(req),
      prisma,
    }),
  }).createHandler({
    path: "/api",
  })
);

And it works 🎉

When I updated it to v3.0.1 & tried using the start method, I get Internal Server Error. For reference, this is my new updated code:

const apolloServer = new ApolloServer({
  schema,
  context: ({ req }): GraphQLContext => ({
    user: req.user,
    origin: getRequestOrigin(req),
    prisma,
  }),
  plugins: [ApolloServerPluginLandingPageGraphQLPlayground({})],
});

export default apolloServer.start().then(() => {
  return handler().use(
    apolloServer.createHandler({
      path: "/api",
    })
  );
});

How do I solve it with the latest version? Others are also facing the same issue 😦

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 19 (3 by maintainers)

Most upvoted comments

+1 I have same issue with v3, but works as expected with v2

I came across a similar error. Try the updated example.

@glasser the repro of the issue is unrelated to the connection between Next.js and apollo-server-micro and has since been resolved (see #5517 (comment). Next.js has a working example here, which is essentially the same as what I recommended. About the connection between the two, I think this is an issue on Next.js’s side. They really need to clarify it as I am confused as well. Everyone is using micro because Next.js uses it in their examples, yet they says it’s not meant for serverless environments.

+1, am getting same error. Tested with the official Next.js api-routes-apollo-server example too. Repro here. npm install, npm run dev, and then go to localhost:3000/api/graphql.

Alright, I’ll put that out but it does work on Stackblitz maybe because Stackblitz runs in isolated context but I’ll see it in my app or put it out 😃

I responded on the Reddit thread, but that looks like a different issue than what you’re describing.

I’d love to help you solve your problem, but it’s not possible unless I can reproduce it on my own machine. Can you create a minimal reproduction (eg, something I can git clone or play around with in codesandbox.io) that demonstrates the issue? I’ll be happy to re-open this issue if you can.