@apollo/core-schema
Version:
Apollo Core Schema processing library
35 lines • 1.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.print = exports.test = void 0;
const graphql_1 = require("graphql");
const de_1 = require("../de");
const test = (val) => typeof (val === null || val === void 0 ? void 0 : val.kind) === 'string';
exports.test = test;
const print = (val) => {
var _a, _b;
const gref = (0, de_1.hasRef)(val)
? `<${(_b = (_a = val.gref) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : ''}>`
: '';
if (!val.loc)
return `${gref}[+] ${(0, graphql_1.print)(val)}`;
const loc = skipDescription(val.loc);
const { line } = loc;
let start = loc;
let end = loc;
while (start.prev && start.prev.line === line)
start = start.prev;
while (end.next && end.next.line === line)
end = end.next;
const text = val.loc.source.body.substring(start.start, end.end);
const col = loc.start - start.start;
const head = text.substring(0, col);
const tail = text.substring(col);
return `${gref}[${val.loc.source.name}] ${head}👉${tail}`;
};
exports.print = print;
function skipDescription(loc) {
if (loc.startToken.kind === graphql_1.TokenKind.BLOCK_STRING)
return loc.startToken.next;
return loc.startToken;
}
//# sourceMappingURL=ast.js.map