-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
executable file
·48 lines (39 loc) · 1.48 KB
/
app.js
File metadata and controls
executable file
·48 lines (39 loc) · 1.48 KB
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
42
43
44
45
46
47
48
const express = require('express')
const graphqlHTTP = require('express-graphql')
const gnx = require('@simtlix/gnx')
const app = express()
const mongoose = require('mongoose')
mongoose.connect('mongodb://localhost:27017,localhost:27018,localhost:27019/example', { replicaSet: 'rs', useNewUrlParser: true, useUnifiedTopology: true })
mongoose.connection.once('open', () => {
console.log('connected to database')
})
const type = require('./types')
const includedTypes = [type.Book]
/* This route will be used as an endpoint to interact with Graphql,
All queries will go through this route. */
const schema2 = gnx.createSchema(includedTypes, includedTypes)
const schema = gnx.createSchema()
app.use('/graphql', graphqlHTTP({
// Directing express-graphql to use this schema to map out the graph
schema,
/* Directing express-graphql to use graphiql when goto '/graphql' address in the browser
which provides an interface to make GraphQl queries */
graphiql: true,
formatError: gnx.buildErrorFormatter((err) => {
console.log(err)
})
}))
app.use('/graphql2', graphqlHTTP({
// Directing express-graphql to use this schema to map out the graph
schema: schema2,
/* Directing express-graphql to use graphiql when goto '/graphql' address in the browser
which provides an interface to make GraphQl queries */
graphiql: true,
formatError: gnx.buildErrorFormatter((err) => {
console.log(err)
return err
})
}))
app.listen(3000, () => {
console.log('Listening on port 3000')
})