Skip to content

Instantly share code, notes, and snippets.

@alloy
Last active April 20, 2019 16:34
Show Gist options
  • Select an option

  • Save alloy/1a9334eef68204e196b2ff75ccd9c30e to your computer and use it in GitHub Desktop.

Select an option

Save alloy/1a9334eef68204e196b2ff75ccd9c30e to your computer and use it in GitHub Desktop.
relay-compiler v3 clickable error messages
patch-package
--- a/node_modules/graphql/error/printError.js
+++ b/node_modules/graphql/error/printError.js
@@ -53,7 +53,7 @@ function highlightSourceAtLocation(source, location) {
var padLen = nextLineNum.length;
var lines = source.body.split(/\r\n|[\n\r]/g);
lines[0] = whitespace(source.locationOffset.column - 1) + lines[0];
- var outputLines = [source.name + ' (' + contextLine + ':' + contextColumn + ')', line >= 2 && lpad(padLen, prevLineNum) + ': ' + lines[line - 2], lpad(padLen, lineNum) + ': ' + lines[line - 1], whitespace(2 + padLen + contextColumn - 1) + '^', line < lines.length && lpad(padLen, nextLineNum) + ': ' + lines[line]];
+ var outputLines = [source.name + ':' + contextLine + ':' + contextColumn, line >= 2 && lpad(padLen, prevLineNum) + ': ' + lines[line - 2], lpad(padLen, lineNum) + ': ' + lines[line - 1], whitespace(2 + padLen + contextColumn - 1) + '^', line < lines.length && lpad(padLen, nextLineNum) + ': ' + lines[line]];
return outputLines.filter(Boolean).join('\n');
}
--- a/node_modules/graphql/error/printError.mjs
+++ b/node_modules/graphql/error/printError.mjs
@@ -47,7 +47,7 @@ function highlightSourceAtLocation(source, location) {
var padLen = nextLineNum.length;
var lines = source.body.split(/\r\n|[\n\r]/g);
lines[0] = whitespace(source.locationOffset.column - 1) + lines[0];
- var outputLines = [source.name + ' (' + contextLine + ':' + contextColumn + ')', line >= 2 && lpad(padLen, prevLineNum) + ': ' + lines[line - 2], lpad(padLen, lineNum) + ': ' + lines[line - 1], whitespace(2 + padLen + contextColumn - 1) + '^', line < lines.length && lpad(padLen, nextLineNum) + ': ' + lines[line]];
+ var outputLines = [source.name + ':' + contextLine + ':' + contextColumn, line >= 2 && lpad(padLen, prevLineNum) + ': ' + lines[line - 2], lpad(padLen, lineNum) + ': ' + lines[line - 1], whitespace(2 + padLen + contextColumn - 1) + '^', line < lines.length && lpad(padLen, nextLineNum) + ': ' + lines[line]];
return outputLines.filter(Boolean).join('\n');
}
patch-package
--- a/node_modules/relay-compiler/bin/relay-compiler
+++ b/node_modules/relay-compiler/bin/relay-compiler
@@ -5555,7 +5555,7 @@ function highlightSourceAtLocation(source, location) {
var columnOffset = location.line === 1 ? firstLineColumnOffset : 0;
var columnNum = location.column + columnOffset;
var lines = body.split(/\r\n|[\n\r]/g);
- return "".concat(source.name, " (").concat(lineNum, ":").concat(columnNum, ")\n") + printPrefixedLines([// Lines specified like this: ["prefix", "string"],
+ return "".concat(source.name, ":").concat(lineNum, ":").concat(columnNum, "\n") + printPrefixedLines([// Lines specified like this: ["prefix", "string"],
["".concat(lineNum - 1, ": "), lines[lineIndex - 1]], ["".concat(lineNum, ": "), lines[lineIndex]], ['', whitespace(columnNum - 1) + '^'], ["".concat(lineNum + 1, ": "), lines[lineIndex + 1]]]);
}
@@ -16051,10 +16051,10 @@ module.exports = function (tagFinder) {
!(text.indexOf('graphql') >= 0) ? true ? invariant(false, 'RelaySourceModuleParser: Files should be filtered before passed to the ' + 'parser, got unfiltered file `%s`.', file.relPath) : undefined : void 0;
var astDefinitions = [];
var sources = [];
- memoizedTagFinder(text, baseDir, file).forEach(function (template) {
- var source = new GraphQL.Source(template, file.relPath);
+ memoizedTagFinder(text, baseDir, file).forEach(function (tag) {
+ var source = new GraphQL.Source(tag.template, path.join(path.relative(process.cwd(), baseDir), file.relPath), tag.sourceLocationOffset);
var ast = parseGraphQL(source);
- !ast.definitions.length ? true ? invariant(false, 'RelaySourceModuleParser: Expected GraphQL text to contain at least one ' + 'definition (fragment, mutation, query, subscription), got `%s`.', template) : undefined : void 0;
+ !ast.definitions.length ? true ? invariant(false, 'RelaySourceModuleParser: Expected GraphQL text to contain at least one ' + 'definition (fragment, mutation, query, subscription), got `%s`.', tag.template) : undefined : void 0;
sources.push(source.body);
astDefinitions.push.apply(astDefinitions, (0, _toConsumableArray2["default"])(ast.definitions));
});
@@ -16128,9 +16128,10 @@ function find(tagFinder, text, absPath) {
tags.forEach(function (tag) {
return validateTemplate(tag, moduleName, absPath);
});
- return tags.map(function (tag) {
- return tag.template;
- });
+ return tags;
+ // return tags.map(function (tag) {
+ // return tag.template;
+ // });
}
function validateTemplate(_ref, moduleName, filePath) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment