-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.ts
86 lines (77 loc) · 1.97 KB
/
app.ts
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
const express = require("express");
const bodyParser = require("body-parser");
const Sentry = require("@sentry/node");
const { ApolloServer } = require("apollo-server-express");
const { gql } = require("graphql-tag");
const { createContext } = require("./context");
const SentryPlugin = require("./plugin");
const port = 3000;
const tools = [
{
sku: "32fszdcqdq3rasdfasdf",
image: "wrench.png",
make: "wrench",
name: "super wrench",
price: 2341,
},
{
sku: "12341234tueqweradsf",
image: "hammer.png",
make: "hammer",
name: "poor hammer",
price: 5134,
},
{
sku: "134rwqejfsdkfvzxcv",
image: "nails.png",
make: "nails",
name: "maker nails",
price: 1234,
},
];
const typeDefs = gql`
type Query {
tools: [Tool]
}
type Tool {
sku: String
image: String
make: String
name: String
price: Int
}
`;
const resolvers = {
Query: { tools: () => tools },
};
const server = new ApolloServer({
typeDefs,
resolvers,
plugins: [SentryPlugin.default],
context: ({ req, connection }: { req: any; connection: any }) =>
createContext({ req, connection }),
});
const app = express();
Sentry.init({
dsn:
"https://[email protected]/5744593",
project: "express-gql",
debug: true,
integrations: [
// enable HTTP calls tracing
new Sentry.Integrations.Http({ tracing: true }),
// enable Express.js middleware tracing
// new Tracing.Integrations.Express({ app }),
],
// Set tracesSampleRate to 1.0 to capture 100%
// of transactions for performance monitoring.
// We recommend adjusting this value in production
tracesSampleRate: 1.0,
});
server.applyMiddleware({ app });
// The error handler must be before any other error middleware and after all controllers
app.use(Sentry.Handlers.errorHandler());
app.use("/graphql", bodyParser.json());
app.listen(port, () =>
console.log(`🚀 Server ready at http://localhost:3000${server.graphqlPath}`)
);