Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IDE friendly errors #2752

Closed
wants to merge 5 commits into from
Closed

IDE friendly errors #2752

wants to merge 5 commits into from

Conversation

alloy
Copy link
Contributor

@alloy alloy commented Jun 4, 2019

These changes make it so file/line locations in errors can be made linkable by IDEs. This is the format used by jest, flow, typescript, and many others.

Before

relay-ide-friendly-errors-before

After

relay-ide-friendly-errors-after

@@ -110,7 +110,7 @@ function createCombinedError(
`${prefix}Encountered ${errors.length} error(s):\n` +
errors
.map(error =>
String(error)
(error instanceof GraphQLError ? printError(error) : String(error))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use our own formatter for GraphQLError instances, instead of the one from graphql-js.

return printedLocations.length === 0
? error.message
: [error.message, ...printedLocations].join('\n\n') + '\n';
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All only needed so we can use our own copy of highlightSourceAtLocation.

@@ -23,14 +23,14 @@ import type {
GraphQLTagFinder,
} from '../language/RelayLanguagePluginInterface';

const cache = new RelayCompilerCache('RelayFindGraphQLTags', 'v1');
const cache = new RelayCompilerCache('RelayFindGraphQLTags', 'v2');
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have to bust the cache, as we should now cache the entire tag, instead of only the tag.template.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kassens This work is distinct from #2784 imo.

memoizedTagFinder(text, baseDir, file).forEach(tag => {
const source = new GraphQL.Source(
tag.template,
path.join(path.relative(process.cwd(), baseDir), file.relPath),
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep path short by making it relative, but in a way that the IDE can find it (i.e. relative to the working dir).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kassens This too.

@alloy
Copy link
Contributor Author

alloy commented Jun 4, 2019

It strikes me that all of the code in RelayCompilerError that’s imported from graphql-js is only done because it isn’t exported upstream. I would rather have these file/line locations formatted correctly for IDEs anywhere graphql-js is used, so would you be open to my trying to get those exported upstream and remove them from our codebase?

(I made a upstream PR for the formatting regardless graphql/graphql-js#1949)

@nodkz
Copy link
Contributor

nodkz commented Jun 4, 2019

Yay! ❤❤❤

@alloy
Copy link
Contributor Author

alloy commented Jun 5, 2019

Unsure why the ‘push’ build failed, but it’s due to some git branch issue.

Copy link
Contributor

@facebook-github-bot facebook-github-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alunyov has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.

@alunyov
Copy link
Contributor

alunyov commented Jun 7, 2019

@alloy thank you for this PR. The demo looks super awesome!

We may need more time to merge this internally, because this PRs, as is, is breaking our internal compiler setup.

I'll follow up on the progress.

@IvanGoncharov
Copy link

It strikes me that all of the code in RelayCompilerError that’s imported from graphql-js is only done because it isn’t exported upstream. I would rather have these file/line locations formatted correctly for IDEs anywhere graphql-js is used, so would you be open to my trying to get those exported upstream and remove them from our codebase?

@alloy Thanks for pinging me on Slack. I merged graphql/graphql-js#1984 that expose new printLocation and printSourceLocation functions.
You can try it on using npm branch: https://github.com/graphql/graphql-js#want-to-ride-the-bleeding-edge
Would be great if you rebase your PR on top of this branch so we can figure out if printSourceLocation location will work for Relay.

@alloy
Copy link
Contributor Author

alloy commented Jun 14, 2019

@IvanGoncharov Great stuff, thanks! I’ll give it a try and let you know 👍

@alloy
Copy link
Contributor Author

alloy commented Jun 26, 2019

@IvanGoncharov Follow-up is at #2784

@kassens
Copy link
Member

kassens commented Jul 19, 2019

@alloy Sorry for the delay here, can you summarize the latest status? Is this PR made redundant due to the graphql-js change and we just need #2784?

(I'm not a big fan how GitHub handles dependent changes).

@alloy
Copy link
Contributor Author

alloy commented Jul 19, 2019

@kassens No worries–no need ever to apologise for not having time to work on external OSS!

So, semantically speaking this PR is still needed and separate from #2784. However, seeing as those changes also exist in #2784 and if you are ready to bump the version constraint of the graphql-js dependency, it might be easier on your end to just merge #2784 separately. My suggestion for future maintenance purposes, though, seeing as these commits all get squashed otherwise, would be to still merge them separately as they are imo distinct units of work.

In the meantime I'll rebase these PRs and I'll be available the rest of the day for further coordination on these.

@kassens
Copy link
Member

kassens commented Jun 23, 2020

Since we're 100% focused on the compiler rewrite and this required some internal changes. I'll close this for now. Better IDE integration is one of our new goals :)

@kassens kassens closed this Jun 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants