Skip to content

graphql 16 not supported #9230

Open
Open
@erquhart

Description

@erquhart

Which packages are impacted by your issue?

@graphql-codegen/cli

Describe the bug

Note - this is not a duplicate of #6937, this is to point out that issue is not actually complete.

The example in the docs does not work with graphql 16: https://the-guild.dev/graphql/codegen/docs/custom-codegen/using-visitor

The example does work if I downgrade to graphql 15.

Specifically this plugin example:

const { getCachedDocumentNodeFromSchema } = require('@graphql-codegen/plugin-helpers')
const { visit } = require('graphql')
 
module.exports = {
  plugin(schema, documents, config) {
    const astNode = getCachedDocumentNodeFromSchema(schema) // Transforms the GraphQLSchema into ASTNode
    const visitor = {
      FieldDefinition(node) {
        // This function triggered per each field
      },
      ObjectTypeDefinition(node) {
        // This function triggered per each type
      }
    }
 
    const result = visit(astNode, { leave: visitor })
 
    return result.definitions.join('\n')
  }
}

Running this results in visitFn.call is not a function.

This is outlined in #6937, which is closed, but the issue persists as other recent comments on that issue indicate.

Your Example Website or App

https://codesandbox.io/p/sandbox/headless-cloud-6z6r45

Steps to Reproduce the Bug or Issue

  1. Go to linked example
  2. Run npm run codegen in the terminal
  3. Observe output

Expected behavior

Visitor function should not error.

Screenshots or Videos

Screenshot 2023-03-26 at 12 23 39 PM

Platform

  • OS: multiple, n/a
  • NodeJS: multiple, n/a
  • graphql version: 16.6
  • @graphql-codegen/* version(s): all latest, see sandbox

Codegen Config File

See sandbox, copied from docs

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions