๐Ÿ“ฆ leonardomso / graphql-101

๐Ÿ“„ index.js ยท 31 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31require("dotenv").config();
import { GraphQLServer } from "graphql-yoga";
import mongoose from "mongoose";

import schema from "./graphql/";
import { options } from "./utils/options";
import { context } from "./utils/context";

const DB =
    "mongodb://leonardomso:graphql101@ds113749.mlab.com:13749/graphql-101";

// Connect to MongoDB with Mongoose.
mongoose
    .connect(DB, {
        useCreateIndex: true,
        useNewUrlParser: true
    })
    .then(() => console.log("MongoDB connected"))
    .catch(err => console.log(err));

const server = new GraphQLServer({
    schema,
    context
});

server.start(options, ({ port }) => {
    console.log(
        `๐Ÿš€ GraphQL 101 Server is running on http://localhost:${port}/playground`
    );
});