Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: custom visitor documentation #9675

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 4 additions & 6 deletions website/src/pages/docs/custom-codegen/using-visitor.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ module.exports = {
Then, create your initial visitor, in our case, we would like to transform a `FieldDefinition` and `ObjectTypeDefinition`, so let's create an object with a stub definitions, an use `visit` to run it:

```js {8-13}
const { getCachedDocumentNodeFromSchema } = require('@graphql-codegen/plugin-helpers')
const { visit } = require('graphql')
const { getCachedDocumentNodeFromSchema, oldVisit } = require('@graphql-codegen/plugin-helpers')

module.exports = {
plugin(schema, documents, config) {
Expand All @@ -67,7 +66,7 @@ module.exports = {
}
}

const result = visit(astNode, { leave: visitor })
const result = oldVisit(astNode, { leave: visitor })

return result.definitions.join('\n')
}
Expand All @@ -77,8 +76,7 @@ module.exports = {
Now, let's implement `ObjectTypeDefinition` and `FieldDefinition`:

```js {8-15}
const { getCachedDocumentNodeFromSchema } = require('@graphql-codegen/plugin-helpers')
const { visit } = require('graphql')
const { getCachedDocumentNodeFromSchema, oldVisit } = require('@graphql-codegen/plugin-helpers')

module.exports = {
plugin(schema, documents, config) {
Expand All @@ -94,7 +92,7 @@ module.exports = {
}
}

const result = visit(astNode, { leave: visitor })
const result = oldVisit(astNode, { leave: visitor })

return result.definitions.join('\n')
}
Expand Down