Skip to content

Instantly share code, notes, and snippets.

@giacomorebonato
Created May 22, 2020 21:27
Show Gist options
  • Save giacomorebonato/1d2670e0374e48219ea3e2c24038a768 to your computer and use it in GitHub Desktop.
Save giacomorebonato/1d2670e0374e48219ea3e2c24038a768 to your computer and use it in GitHub Desktop.
GraphQL utilities
import { FieldNode } from 'graphql'
export const doesPathExists = (
nodes: readonly FieldNode[],
path: string[]
): boolean => {
if (!nodes) {
return false
}
const node = nodes.find((x) => x.name.value === path[0])
if (!node) return false
if (path.length === 1) return true
if (!node.selectionSet) return false
return doesPathExists(
node.selectionSet.selections as FieldNode[],
path.slice(1)
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment