DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

Discussion on: Building A GraphQL Server With Next.js API Routes

Collapse
 
pakman198 profile image
Pako • Edited on

Thanks for sharing
I want to give it a try man, I was 2 days ago trying to upload my graphql server to vercel but with no success I ended up going to heroku.
I noticed you have everything inside your api endpoint, but if you decided to have everything organized in different files and folders, would you keep all those files and folders inside the api folder ?

Collapse
 
lyonwj profile image
William Lyon

Hi Pako - what issues did you run into?

Yes, you can use whatever file strucutre makes sense and import as modules as necessary, and still leverage Next.js's file-based router convention (so in pages/api/foobar.js just import as modules any lib type code that you want to use).

Collapse
 
pakman198 profile image
Pako

So my first thought was:
Vercel basically allows you to deploy compiled frontend apps, so maybe I would need to compile the playground to present it as my frontend app and all my routes move them to lambdas.
But I didn't know in what direction to go so I just went with Heroku.

2 years ago I took Wes Bos' advanced react course with graphql and I was able to deploy the app in vercel, but that was before they added the new /api file structure.

Anyways, I'll try to update my code and upload it to vercel and if I have some problems deploying I might reach out for help :P

Thread Thread
 
lyonwj profile image
William Lyon

Gotcha. You can serve GraphQL Playground from a Next.js API Route. In Apollo Server 3 you'll just need to enable it via a plugin: apollographql.com/docs/apollo-serv...