StephenGrider / Lyrical-GraphQL

Starter project from a GraphQL course on Udemy.com
197 stars 372 forks source link

code doesn't run out of the box anymore #24

Open thujone opened 5 years ago

thujone commented 5 years ago

I don't know if it just needs module updating or what, but mLab doesn't even exist anymore.

I bought the tutorial on udemy yesterday thinking it was new.

ildx commented 5 years ago

@thujone

You can use a local instance of Mongodb as well. In that case, the URI would just be something like:

"mongodb://127.0.0.1/lyricaldb"

thujone commented 5 years ago

thanks for the info.

dbishoponline commented 5 years ago

code needs to be updated. mongodb url is not valid according to the code. Latest version of mongoose works though

nenadmarinkovic commented 4 years ago

This works for me! Install latest mongoose (5.7.13) and instead of MLab, use MongoDB Atlas, and change server.js file into something like this:

const express = require("express");
const models = require("./models");
const expressGraphQL = require("express-graphql");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const schema = require("./schema/schema");

const app = express();

const MONGO_URI =
  "mongodb+srv://nenad:<PASSWORDHERE>@cluster0-lxh0n.mongodb.net/lyricaldb";
if (!MONGO_URI) {
  throw new Error("You must provide a MongoDB URI");
}

mongoose.Promise = global.Promise;
mongoose.connect(MONGO_URI, {
  useUnifiedTopology: true,
  useNewUrlParser: true
});
mongoose.connection
  .once("open", () => console.log("Connected to MongoDB."))
  .on("error", error => console.log("Error connecting to MongoLab:", error));

app.use(bodyParser.json());
app.use(
  "/graphql",
  expressGraphQL({
    schema,
    graphiql: true
  })
);

const webpackMiddleware = require("webpack-dev-middleware");
const webpack = require("webpack");
const webpackConfig = require("../webpack.config.js");
app.use(webpackMiddleware(webpack(webpackConfig)));

module.exports = app;