-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
72 lines (67 loc) · 1.6 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
const { graphqlHTTP } = require('express-graphql')
const {
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
GraphQLList,
GraphQLInt,
GraphQLNonNull
} = require('graphql')
const express = require('express')
const app = express()
const HelloType = require('./modules/Hello')
const ArtistType = require('./modules/ArtistType')
const SongType = require('./modules/SongType')
const artists = require('./modules/Artists')
const songs = require('./modules/Songs')
const RootQueryType = new GraphQLObjectType({
name: 'Query',
description: 'Root Query',
fields: () => ({
hello: {
type: HelloType,
description: 'Example hello world',
resolve: () => ({ message: 'Hi' })
},
artists: {
type: new GraphQLList(ArtistType),
description: 'List an artists',
resolve: () => artists
},
artist: {
type: ArtistType,
description: 'Find Spesific artist',
args: {
id: {
type: GraphQLInt
}
},
resolve: (parent, args) => artists.find(artist => artist.id === args.id)
},
songs: {
type: GraphQLList(SongType),
description: 'List of songs',
resolve: () => songs
},
song: {
type: SongType,
description: 'Find spesific a song',
args: {
uuid: {
type: GraphQLString
}
},
resolve: (parent, args) => songs.find(song => song.uuid === args.uuid)
}
})
})
const schema = new GraphQLSchema({
query: RootQueryType
})
app.use('/graphql', graphqlHTTP({
schema: schema,
graphiql: true
}))
app.listen(5000, () => {
console.log('Server running');
})