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

GraphQL 16 compatibility #47

Closed
aaronadamsCA opened this issue Jan 17, 2022 · 2 comments · Fixed by #48
Closed

GraphQL 16 compatibility #47

aaronadamsCA opened this issue Jan 17, 2022 · 2 comments · Fixed by #48

Comments

@aaronadamsCA
Copy link
Contributor

Make the toolkit compatible with GQL 16.

The only problem I see is this visitor, which is causing TypeError: visitFn.call is not a function:

return {
enter: {
FragmentSpread: node => {
currentSpreads.push(node.name.value)
},
},
leave: {
OperationDefinition: node => {
if (!node.name?.value) {
throw new Error("Every query must have a name")
}
definitionSpreads.set(node.name.value, currentSpreads)
currentSpreads = []
},
FragmentDefinition: node => {
definitionSpreads.set(node.name.value, currentSpreads)
currentSpreads = []
},
Document: node => {
const operations = node.definitions.filter(isOperation)
const operationNames = operations.map(op => op.name?.value)
const usedSpreads = new Set(
operationNames.reduce(collectSpreadsRecursively, [])
)
const usedFragments = node.definitions.filter(
node => isFragment(node) && usedSpreads.has(node.name.value)
)
return GraphQLAST.document([...operations, ...usedFragments])
},
},
}

Support for enter and leave objects was dropped in GraphQL 16 (graphql/graphql-js#2957), so the visitor would just need to be rewritten in this format:

visit(ast, {
  Kind: {
    enter(node) {
      // enter the "Kind" node
    }
    leave(node) {
      // leave the "Kind" node
    }
  }
})

I've patched this locally, and otherwise everything seems to be working fine.

@AbdallahAbis
Copy link

@aaronadamsCA Is there a workaround while waiting for the PR to be merged? I'm trying to use the Toolkit to source from Sanity CMS.

@cameronbraid
Copy link

This is also needed for gatsby 5

LekoArts pushed a commit that referenced this issue Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants