UNPKG

core-types-graphql

Version:
20 lines (19 loc) 515 B
export function gqlLocationsToCoreTypesLocation(source, loc) { if (loc.length === 0) return {}; const firstLoc = loc[0]; const offset = source .split("\n") .slice(0, firstLoc.line) .map((line, index, arr) => (index === arr.length - 1) ? firstLoc.column : line.length) .reduce((prev, cur) => prev + cur, 0); return { start: { line: firstLoc.line, column: firstLoc.column, offset, }, }; }