-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (54 loc) · 1.38 KB
/
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import express from 'express';
import graphqlHTTP from 'express-graphql';
import {
graphql,
GraphQLSchema,
GraphQLObjectType,
GraphQLString,
GraphQLList,
GraphQLNonNull
} from 'graphql';
import { getPersons, getPerson, personType } from './model/person';
import { getMeetups, meetupType } from './model/meetup';
import { membershipType } from './model/membership';
const schema = new GraphQLSchema({
query: new GraphQLObjectType({
name: 'Query',
fields: () => ({
persons: {
type: new GraphQLList(personType),
description: 'Fetch all persons',
resolve: (root) => {
return getPersons();
}
},
person: {
type: personType,
description: 'Fetch one person',
args: {
id: {
type: new GraphQLNonNull(GraphQLString),
description: 'Id of the person to fetch',
}
},
resolve: (root, { id }) => {
return getPerson(id);
}
},
meetups: {
type: new GraphQLList(meetupType),
description: 'Fetch all meetups',
resolve: (root) => {
return getMeetups();
}
}
})
}),
types: [personType, meetupType]
});
const app = express();
app.use('/graphql', graphqlHTTP({
schema: schema,
graphiql: true,
}));
app.listen(8888, () => console.log('Now browse to localhost:8888/graphql'));