-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.js
72 lines (60 loc) · 1.42 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 { ApolloServer, gql } = require('apollo-server');
var propertyList = require('./mock.js').propertyList;
// The GraphQL schema
const typeDefs = gql`
# property type and query
type PropertyListType {
properties: [PropertyType]
}
type PropertyType {
"Information about an available property."
id: ID!
title: String
neighborhood: String
likes: Int
price: Float
contacts: [ContactType]
}
type ContactType {
id: ID!
name: String!
message: String!
}
type Query {
propertyList: PropertyListType
}
# property like mutation
type Mutation {
likeProperty(id: ID!): PropertyUpdateResponse!
}
type PropertyUpdateResponse {
success: Boolean!
message: String
}
`;
// A map of functions which return data for the schema.
const resolvers = {
Query: {
propertyList: () => propertyList,
// getWelcomeText: () => 'Hello 🙋. Your 🍤 will be ready soon!',
},
Mutation: {
likeProperty: async (_, { id }) => {
let property = propertyList.properties.find(function(property) {
return property.id == id
})
property.likes += 1
return {
success: true,
message: "The property amount of likes was correctly updated!"
}
}
}
};
const server = new ApolloServer({
typeDefs,
resolvers,
});
server.listen().then(({ url }) => {
console.log(`🚀 Server ready at ${url}`)
});