Skip to content

Commit 46819e5

Browse files
authored
docs: debugging (#1788)
1 parent d5db6e5 commit 46819e5

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Debugging
2+
3+
You can run Yoga in a debug mode by running it with `DEBUG=1` in the environment. Doing so will increase verbosity of the logger delivering additional information including:
4+
5+
- Processing of GraphQL parameters
6+
- Parsing of GraphQL parameters
7+
- Execution or subscription start
8+
- Received GraphQL operation variables
9+
- Execution or subscription end
10+
- [GraphiQL](https://github.com/graphql/graphiql) rendering
11+
- Healthcheck and readiness checks
12+
13+
The default logger in Yoga is the [JavaScript console](https://developer.mozilla.org/en-US/docs/Web/API/console) and its respective methods ([debug](https://developer.mozilla.org/en-US/docs/Web/API/console/debug), [info](https://developer.mozilla.org/en-US/docs/Web/API/console/info), [warn](https://developer.mozilla.org/en-US/docs/Web/API/console/warn) and [error](https://developer.mozilla.org/en-US/docs/Web/API/console/error)) matching the log level.
14+
15+
You can of course provide your own logger for piping to your favourite logging service/utility:
16+
17+
```ts
18+
import { createYoga } from 'graphql-yoga'
19+
import { createServer } from 'node:http'
20+
import { schema } from './my-schema'
21+
import { logger } from './my-logger'
22+
23+
const yoga = createYoga({
24+
schema,
25+
logging: {
26+
debug(...args) {
27+
// will only get triggered if DEBUG=1 in environment
28+
logger.debug(...args)
29+
},
30+
info(...args) {
31+
logger.info(...args)
32+
},
33+
warn(...args) {
34+
logger.warn(...args)
35+
},
36+
error(...args) {
37+
logger.error(...args)
38+
},
39+
},
40+
})
41+
42+
const server = createServer(yoga)
43+
server.listen(4000)
44+
```

0 commit comments

Comments
 (0)