-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TypeError: resolver is not a function using apollo-server-micro
latest version v3.0.1
#5517
Comments
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 |
Unfortunately, it's a big private repo. Here's a similar repo found through SourceGraph's awesome search -> https://gitlab.com/yo/devparty Check this file -> https://gitlab.com/yo/devparty/-/blob/main/src/pages/api/index.ts#L19-30 Try running the project using Then It should run. Then try installing the latest It'll yell to use |
Can you make your own fork of this that shows your work, so I don't have to guess what you mean by "which I did"? |
It's exactly the same thing, man. I've tried it myself. By "which I did", I mean I did use The thing is I only need to get it to work like the 1st code-block that uses an older version. I read through the whole docs & tried different variations but was unable to get it to work. |
@glasser I've made a simple demo here that works on older version -> https://stackblitz.com/edit/nextjs-nt4pub?file=pages%2Fapi%2Findex.js Click on Open in New Window at the top-right in Stackblitz & go to Try changing |
+1 I have same issue with v3, but works as expected with v2 |
+1, am getting same error. Tested with the official Next.js |
I came across a similar error. Try the updated example. |
@lukin, thanks for sharing. That works great on the same origin, but I was unable to query it on apollo studio. I fixed it by using this in the handler: const handler: NextApiHandler = async (req, res) => {
res.setHeader('Access-Control-Allow-Credentials', 'true')
res.setHeader('Access-Control-Allow-Origin', '*')
res.setHeader(
'Access-Control-Allow-Methods',
'GET,OPTIONS,PATCH,DELETE,POST,PUT',
)
res.setHeader(
'Access-Control-Allow-Headers',
'X-CSRF-Token, X-Requested-With, Accept, Accept-Version, Content-Length, Content-MD5, Content-Type, Date, X-Api-Version',
)
if (req.method === 'OPTIONS') return res.end()
await startServer
await server.createHandler({
path: '/api/graphql',
})(req, res)
return res.end()
}
export default handler as per Vercel's cors docs. You can also use import Cors from 'micro-cors'
const cors = Cors()
const handler: NextApiHandler = async (req, res) => {
if (req.method === 'OPTIONS') return res.end()
await startServer
await server.createHandler({
path: '/api/graphql',
})(req, res)
return res.end()
}
// @ts-expect-error these are compatible
export default cors(handler) |
@lukin @sachinraja any idea how to fix mine -> #5517 (comment) |
@deadcoder0904 should work the same way: const apiHandler: NextApiHandler = async (req, res) => {
if (req.method === 'OPTIONS') return res.end()
await startServer
const ncHandler = handler.use(server.createHandler({
path: '/api/graphql',
}))
await ncHandler.run(req, res)
return res.end()
}
export default apiHandler |
@sachinraja confused what is |
@deadcoder0904 I am not sure how to alter that, there are two default exports. |
@sachinraja Thank you. I managed to make it work thanks to you & SourceGraph's search again. Had to do it like this: const apolloServer = new ApolloServer({
typeDefs,
resolvers
});
export default handler().use(async (req, res) => {
await apolloServer.start();
await apolloServer.createHandler({
path: '/api'
});
}); |
@deadcoder0904 that shouldn't work, you are supposed to start the server only once, outside the handler. |
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 :) |
@sachinraja Hi, I tried to follow the directions in #5517 (comment) but it looks like you already edited the project away from the example of what doesn't work, so I'm not able to help. (I'm on and off vacation this month, thus the delay.) Also as I mentioned today in #5547 (comment) — I am personally incredibly confused by the relationship between Micro and Next. I see there are many people coming to this repo confused that apollo-server-micro doesn't work in Next... but when I try to do basic research like looking at the Next.js website and Wikipedia page for references to Micro, or look at the Micro README for references to Next.js, I find nothing. I don't really understand where the expectation that |
@glasser I think Next.js used or used to use This is a case similar to Redux. Better state-management libraries exist but since the Internet is filled with tutorials of it, everyone uses it :) |
|
I have an old project using
apollo-server-micro@2.21.2
like:And it works 🎉
When I updated it to
v3.0.1
& tried using thestart
method, I getInternal Server Error
. For reference, this is my new updated code:How do I solve it with the latest version? Others are also facing the same issue :(
The text was updated successfully, but these errors were encountered: