@envelop/extended-validation
Advanced tools
Comparing version 4.1.0-alpha-20240806125641-9b9885ba to 4.1.0-alpha-20240810114324-912296f8
@@ -85,9 +85,18 @@ "use strict"; | ||
}; | ||
function visitPath(path, data = {}) { | ||
let currentData = (data ||= typeof path[0] === 'number' ? [] : {}); | ||
for (const pathItemIndex in path.slice(0, -1)) { | ||
const pathItem = path[pathItemIndex]; | ||
currentData = currentData[pathItem] ||= | ||
typeof path[Number(pathItemIndex) + 1] === 'number' ? [] : {}; | ||
if (Array.isArray(currentData)) { | ||
currentData = currentData.map((c, i) => visitPath(path.slice(Number(pathItemIndex) + 1), c)); | ||
} | ||
} | ||
currentData[path[path.length - 1]] = null; | ||
return data; | ||
} | ||
errors.forEach(e => { | ||
if (e.path?.length) { | ||
let currentData = (newResult.data ||= {}); | ||
for (const pathItem of e.path.slice(0, -1)) { | ||
currentData = currentData[pathItem] ||= {}; | ||
} | ||
currentData[e.path[e.path.length - 1]] = null; | ||
newResult.data = visitPath(e.path, newResult.data); | ||
} | ||
@@ -94,0 +103,0 @@ }); |
@@ -81,9 +81,18 @@ import { TypeInfo, ValidationContext, visit, visitInParallel, visitWithTypeInfo, } from 'graphql'; | ||
}; | ||
function visitPath(path, data = {}) { | ||
let currentData = (data ||= typeof path[0] === 'number' ? [] : {}); | ||
for (const pathItemIndex in path.slice(0, -1)) { | ||
const pathItem = path[pathItemIndex]; | ||
currentData = currentData[pathItem] ||= | ||
typeof path[Number(pathItemIndex) + 1] === 'number' ? [] : {}; | ||
if (Array.isArray(currentData)) { | ||
currentData = currentData.map((c, i) => visitPath(path.slice(Number(pathItemIndex) + 1), c)); | ||
} | ||
} | ||
currentData[path[path.length - 1]] = null; | ||
return data; | ||
} | ||
errors.forEach(e => { | ||
if (e.path?.length) { | ||
let currentData = (newResult.data ||= {}); | ||
for (const pathItem of e.path.slice(0, -1)) { | ||
currentData = currentData[pathItem] ||= {}; | ||
} | ||
currentData[e.path[e.path.length - 1]] = null; | ||
newResult.data = visitPath(e.path, newResult.data); | ||
} | ||
@@ -90,0 +99,0 @@ }); |
{ | ||
"name": "@envelop/extended-validation", | ||
"version": "4.1.0-alpha-20240806125641-9b9885ba", | ||
"version": "4.1.0-alpha-20240810114324-912296f8", | ||
"sideEffects": false, | ||
@@ -5,0 +5,0 @@ "peerDependencies": { |
29521
435