Database not connected on first run when not navigating to /api/graphql if hitting another api endpoint (/api/login)
webface opened this issue · 4 comments
Describe the bug
After cloning the Vulcan Next repo using the devel branch and setting env vars to a local db or docker db. Any attempt to login or signup throws this error.
MongooseError: Operation `vulcanusers.findOne()` buffering timed out after 10000ms
If I first navigate to http://localhost:3000/api/graphql
then the database is created and seeded then everything works
Expected behavior
For the db to get created and seeded without first navigating to http://localhost:3000/api/graphql
Desktop (if applicable):
- OS: IOS
- Browser Chrome
with remote atlas db run dev.
event - compiled successfully
MongooseError: Operation `vulcanusers.findOne()` buffering timed out after 10000ms
at Timeout.<anonymous> (/Applications/MAMP/htdocs/PROJECTS2021/vulcan-next/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:185:20)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
MongooseError: Operation `vulcanusers.findOne()` buffering timed out after 10000ms
at Timeout.<anonymous> (/Applications/MAMP/htdocs/PROJECTS2021/vulcan-next/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:185:20)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
event - build page: /api/graphql
wait - compiling...
event - compiled successfully
API resolved without sending a response for /, this may result in stalled requests.
(node:97119) DeprecationWarning: collection.count is deprecated, and will be removed in a future version. Use Collection.countDocuments or Collection.estimatedDocumentCount instead
(Use `node --trace-deprecation ...` to show where the warning was created)
No admin user found, seeding admin
API resolved without sending a response for /, this may result in stalled requests.
had to navigate first to /api/graphql
If i shut down dev and run dev again it doesnt connect to remote db in env
event - build page: /api/user
wait - compiling...
event - compiled successfully
MongooseError: Operation `vulcanusers.findOne()` buffering timed out after 10000ms
at Timeout.<anonymous> (/Applications/MAMP/htdocs/PROJECTS2021/vulcan-next/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:185:20)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
MongooseError: Operation `vulcanusers.findOne()` buffering timed out after 10000ms
at Timeout.<anonymous> (/Applications/MAMP/htdocs/PROJECTS2021/vulcan-next/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:185:20)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
MongooseError: Operation `vulcanusers.findOne()` buffering timed out after 10000ms
at Timeout.<anonymous> (/Applications/MAMP/htdocs/PROJECTS2021/vulcan-next/node_modules/mongoose/lib/drivers/node-mongodb-native/collection.js:185:20)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
have to hit /api/graphql
first again
That's weird because opening /api/graphql
is the same as sending a request to it, that doesn't matter if you open it in the browser or not. At the moment it's impossible to seed without first querying this endpoint. And that makes sense, since you shouldn't need to seed if you don't hit it.
Next is based on serverless patterns, I provide seeding as a convenience but that should'nt even live in the framework, seed should happen before the Next app even starts up.
I will probably improve that in the future.
Fixed on devel, with a slightly better unit test for mongoConnection testing.