-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
41 lines (34 loc) · 930 Bytes
/
index.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
32
33
34
35
36
37
38
39
40
41
import express from "express";
import bodyParser from "body-parser";
import { graphiqlExpress, graphqlExpress } from "apollo-server-express";
import { makeExecutableSchema } from "graphql-tools";
import typeDefs from "./schema";
import resolvers from "./resolvers";
import models from "./models";
// Put together a schema
const schema = makeExecutableSchema({
typeDefs,
resolvers
});
// Initialize the app
const app = express();
// The GraphQL endpoint
app.use(
"/graphql",
bodyParser.json(),
graphqlExpress({ schema, context: { models } })
);
// GraphiQL, a visual editor for queries
app.use("/graphiql", graphiqlExpress({ endpointURL: "/graphql" }));
// Start the server
models.sequelize
.sync()
.then(() =>
app.listen(3000, () =>
console.log(
`
Running a GraphQL API server at http://localhost:3000/graphql`
)
)
)
.catch(err => console.log("Error Massage:" + err));