This repository has been archived by the owner on May 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
65 lines (59 loc) · 1.79 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
const express = require('express');
const {graphqlHTTP} = require('express-graphql');
const graphql = require('graphql');
const {Cheese, Contributor} = require('./db');
const contributorType = new graphql.GraphQLObjectType({
name: 'Contributor',
fields: {
id: {type: graphql.GraphQLID},
name: {type: graphql.GraphQLString},
github: {type: graphql.GraphQLString},
discord: {type: graphql.GraphQLString},
member: {type: graphql.GraphQLBoolean},
}
})
const cheeseType = new graphql.GraphQLObjectType({
name: 'Cheese',
fields: {
id: {type: graphql.GraphQLID},
name: {type: graphql.GraphQLString},
description: {type: graphql.GraphQLString},
origin: {type: graphql.GraphQLString},
score: {type: graphql.GraphQLInt},
legal: {type: graphql.GraphQLBoolean},
searches: {type: graphql.GraphQLInt},
repository: {type: graphql.GraphQLString},
created_by: {type: contributorType},
}
});
const queryType = new graphql.GraphQLObjectType({
name: 'Query',
fields: {
cheese: {
type: cheeseType,
args: {
id: {type: graphql.GraphQLID}
},
resolve: (_, {id}) => {
return Cheese[id];
}
},
contributor: {
type: contributorType,
args: {
id: {type: graphql.GraphQLID}
},
resolve: (_, {id}) => {
return Contributor[id];
}
}
}
})
const schema = new graphql.GraphQLSchema({query: queryType})
const app = express();
app.use('/cheeseapi', graphqlHTTP({
schema: schema,
graphiql: true,
}));
app.listen(4000);
console.log('Running a GraphQL API server at http://localhost:4000/cheeseapi');