-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
53 lines (48 loc) · 904 Bytes
/
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
const {
ApolloServer,
ApolloError,
makeExecutableSchema,
mergeSchemas,
gql
} = require('apollo-server')
const cars = [
{
__typename: 'Car',
make: 'Land Rover',
model: 'Range Rover',
year: 2015,
},
];
const schema = makeExecutableSchema({
typeDefs: gql`
type Car {
make: String!
model: String!
year: Int!
inventory: Int
}
type Query {
cars: [Car]
}
`,
resolvers: {
Car: {
inventory() {
throw new ApolloError('test error', 'CUSTOM_ERROR_CODE', {
someExtraErrorProp: 'Something!',
});
}
},
Query: {
cars() {
return cars;
},
},
},
});
const goodApolloServer = new ApolloServer({ schema });
goodApolloServer.listen(3000);
const badApolloServer = new ApolloServer({
schema: mergeSchemas({ schemas: [schema] }),
});
badApolloServer.listen(3001);