-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathindex.js
More file actions
69 lines (59 loc) · 1.33 KB
/
index.js
File metadata and controls
69 lines (59 loc) · 1.33 KB
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
const { ApolloServer, gql } = require("apollo-server");
const employees = require("./data/employees");
const typeDefs = gql`
type Employee {
id: ID!
firstName: String!
lastName: String!
job: JobType
liftOperator_yearsExperience: Int
skiPatrol_certified: Boolean
instructor_level: Level
bartender_assignment: Location
}
enum JobType {
LIFTOPERATOR
SKIPATROL
INSTRUCTOR
BARTENDER
}
enum Level {
LEVELONE
LEVELTWO
LEVELTHREE
}
enum Location {
SUMMIT
ICEBAR
EDGEDECK
}
type Query {
allEmployees(job: JobType): [Employee!]!
totalEmployees: Int!
}
`;
const resolvers = {
Query: {
allEmployees: (parent, { job }, { employees }) => {
if (job) {
return employees.filter(e => e.job === job);
} else {
return employees;
}
},
totalEmployees: (parent, args, { employees }) => employees.length
},
Employee: {
liftOperator_yearsExperience: parent => parent.yearsExperience,
instructor_level: parent => parent.level,
skiPatrol_certified: parent => parent.certified,
bartender_assignment: parent => parent.assignment
}
};
const context = { employees };
const server = new ApolloServer({
typeDefs,
resolvers,
context
});
server.listen().then(({ url }) => console.log(`Server running on ${url}`));