-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Breakout Hooks Docs into Seperate Pages (#632)
* doc: (#519) adding examples for getStaticPaths * Update API Router auth import docs * Update API Router imports to use `@faustjs/core/api` * Breakout Hooks into individual Pages (#631) * docs: break out hooks * Update links to appropriate hooks url * Logging queries guide * Fix docs site URLs * Fix hooks links Co-authored-by: William Johnston <[email protected]>
- Loading branch information
1 parent
8d9bc5f
commit 84ba1b1
Showing
19 changed files
with
627 additions
and
475 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
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
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 | ||
// ... | ||
} | ||
``` |
Oops, something went wrong.