denny_dha91
2/25/2020 - 10:18 AM

Function to check info parameter on graphql whether path exists or not

function doesPathExist(nodes, path) {
  if (!nodes) {
    return false;
  }

  const node = nodes.find(x => x.name.value === path[0]);

  if (!node) {
    return false;
  }

  if (path.length === 1) {
    return true;
  }

  return doesPathExist(node.selectionSet.selections, path.slice(1));
}