Search code examples
mongodbexpressmongoosegraphqlapollo

Migration from Rest(Express) to GraphQL: Models(mongoose) don't work in graphQL resolvers


Thank you for your attention!

I decided to transfer my REST API(Express) to GraphGL. Everything worked before adding subscribers. Now all models return Timeout: enter image description here enter image description here

Resolvers: enter image description here

If I clean the model, then it can return something to me: enter image description here enter image description here

Here is the code: https://codesandbox.io/s/zen-cohen-7o74v?file=/models/owner.js


Solution

  • I forgot to add:

    require("dotenv").config();
    const mongoose = require("mongoose");
    
    ...
    
     // mongoose
     mongoose
      .connect(process.env.DB_HOST, {
        useNewUrlParser: true,
        useUnifiedTopology: true,
      })
      .then(() => console.log("MongoDB connected"))
      .catch((err) => console.log(err));