-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
31 lines (26 loc) · 859 Bytes
/
server.js
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
31
const express = require("express");
const graphqlHTTP = require("express-graphql");
const db = require("./docker/db");
const { PORT } = require("./env-config");
const addDataToDB = require("./authorsAndBooks");
const schema = require("./graphql/schema");
const sdlSchema = require("./graphql/SDLSchema.js");
const app = express();
db.connect();
db.connection.on("connected", () => {
// addDataToDB();
});
// Note: If you want to use graphQL schema that is created using
// schema-first/SDL-first approach use "sdlSchema" in graphqlHTTP
// and if you want to use graphQL schema that is created using JavaScript objects
// also known as code-first/resolvers-first use "schema" in graphqlHTTP
app.use(
"/graphql",
graphqlHTTP({
schema,
graphiql: true
})
);
app.listen(PORT || 4001, () => {
console.log("Server running on PORT", PORT);
});