-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c719d7c
commit 664ba05
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
--- | ||
slug: /next/guides/logging-queries | ||
title: Logging Queries | ||
description: You can log all the queries that are executed in Faust.js | ||
--- | ||
|
||
In a development environment, you may want to log GraphQL queries that are being executed in your application. Faust.js provides a function, `logQueries`, to do this. | ||
|
||
`logQueries` is called within your `client/index.ts` file. Take the following `client/index.ts` example: | ||
|
||
```ts title="client/index.ts" {23-25} | ||
/** | ||
* GQTY: You can safely modify this file and Query Fetcher based on your needs | ||
*/ | ||
import type { IncomingMessage } from 'http'; | ||
import { getClient } from '@faustjs/next'; | ||
import { | ||
generatedSchema, | ||
scalarsEnumsHash, | ||
GeneratedSchema, | ||
SchemaObjectTypes, | ||
SchemaObjectTypesNames, | ||
} from './schema.generated'; | ||
|
||
export const client = getClient< | ||
GeneratedSchema, | ||
SchemaObjectTypesNames, | ||
SchemaObjectTypes | ||
>({ | ||
schema: generatedSchema, | ||
scalarsEnumsHash, | ||
}); | ||
|
||
if (process.env.NODE_ENV === 'development') { | ||
logQueries(client); | ||
} | ||
|
||
export function serverClient(req: IncomingMessage) { | ||
return getClient<GeneratedSchema, SchemaObjectTypesNames, SchemaObjectTypes>({ | ||
schema: generatedSchema, | ||
scalarsEnumsHash, | ||
context: req, | ||
}); | ||
} | ||
|
||
export * from './schema.generated'; | ||
``` | ||
|
||
Note the conditional check for the node environment. It is recommended that you only log queries in a dev environment, and not in production. | ||
|
||
Additionally, the `logQueries` function returns a function than can be called to turn off the logger: | ||
|
||
```ts | ||
if (process.env.NODE_ENV === 'development') { | ||
const unsubscribe = logQueries(client); | ||
|
||
// queries are now logging | ||
// ... | ||
|
||
unsubscribe(); | ||
|
||
// queries no longer log | ||
// ... | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
664ba05
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Branch site-dev could not be deployed
Your environment Development of app faustjs-site could not be updated
View build logs: https://my.wpengine.com/atlas#/faustjs-site/cixzyt38dn5ak04xxcqc36lf/pqlgc0rr4hu1vahmvde54gq2
View your environment URL: https://hcixzyt38dn5ak04xxcqc36lf.js.wpenginepowered.com
664ba05
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Branch site-dev could not be deployed
Your environment Development of app faustjs-site could not be updated
View build logs: https://my.wpengine.com/atlas#/faustjs-site/cixzyt38dn5ak04xxcqc36lf/mvwpr86gfr2s07phch7jgoda
View your environment URL: https://hcixzyt38dn5ak04xxcqc36lf.js.wpenginepowered.com