Skip to content

Commit

Permalink
fix: custom visitor documentation (#9675)
Browse files Browse the repository at this point in the history
  • Loading branch information
geisterfurz007 authored Jul 9, 2024
1 parent a2dab00 commit ca366ec
Showing 1 changed file with 4 additions and 6 deletions.
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

0 comments on commit ca366ec

Please sign in to comment.