-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
92 lines (78 loc) · 2.44 KB
/
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import express from 'express'
import bodyParser from 'body-parser'
// DEPRECATED
// import { graphiqlExpress, graphqlExpress } from 'graphql-server-express';
// is the SAME !!!!!!
// import { graphiqlExpress, graphqlExpress } from 'apollo-server-express';
// AND equivalent to, which is better:
import graphqlHTTP from 'express-graphql'
import { makeExecutableSchema } from 'graphql-tools'
// import { buildSchema } from 'graphql'
import typeDefs from './schema/typeDefs'
import resolvers from './schema/resolvers'
const schema = makeExecutableSchema({
typeDefs,
resolvers,
})
// const schema = buildSchema(typeDefs)
const PORT = 8080
const app = express()
// app.use('/graphiql', graphiqlExpress({ endpointURL: '/graphql' }));
// app.use('/graphql', bodyParser.json(), graphqlExpress({ schema }));
// app.use('/graphql', graphqlHTTP({ schema, graphiql: false }));
// app.use('/graphql', graphqlHTTP({ schema, graphiql: true }));
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const root = {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
hello: (args, context, info, ddd) => {
console.log('hello:', args, context, info, ddd)
// console.log('hello: args', args)
// console.log('hello: context', context)
// console.log('hello: info', info)
// console.log('hello: ddd', ddd)
return 'Hello world!'
},
item: (args, context, info, ddd) => {
// console.log('item:', args, context, info, ddd)
console.log('item: args', args)
// console.log('item: context', context)
// console.log('item: info', info)
console.log('item: ddd', ddd)
return {
book: 'sdssds',
}
},
Item: {
book: (args, context, info, ddd) => {
console.log('book:', args, context, info, ddd)
// console.log('book: args', args)
// console.log('book: context', context)
// console.log('book: info', info)
// console.log('book: ddd', ddd)
return 'book book'
},
},
}
app.use(bodyParser.json())
app.use('/graphql', graphqlHTTP({
schema,
// rootValue: root,
graphiql: true,
}))
app.use((req, res, next) => {
console.log('Request:')
console.log(req)
console.log('Response:')
console.log(res)
// res.status(200).send({ name: 'Well, Hard to tell...' });
next()
})
app.get('/', (req, res) => {
res.json({ result: 'ok' })
})
app.get('/hello', (req, res) => {
res.json({ result: 'Hi there...' })
})
app.listen(PORT, () => {
console.log('app running at 8080')
})