Skip to content

Convert error to warning for non-compliant use of __ #692

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

Merged
merged 1 commit into from
Jan 26, 2017
Merged

Conversation

leebyron
Copy link
Contributor

This unbreaks various uses of graphql-js which were defining fields with __ while retaining some form of reporting warning for non-compliant use.

Fixes #690

This unbreaks various uses of graphql-js which were defining fields with __ while retaining some form of reporting warning for non-compliant use.

Fixes #690
Copy link
Contributor

@wincent wincent left a comment

Choose a reason for hiding this comment

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

Great!

if (!isIntrospection && name.slice(0, 2) === '__' && !hasWarnedAboutDunder) {
hasWarnedAboutDunder = true;
/* eslint-disable no-console */
if (console && console.error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

When would console ever be defined but falsey? Just being paranoid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just being paranoid. I'd rather not have a cascading failure because someone's running graphql-js in some environment that either has no console or has console but doesn't have console.error.

Copy link
Contributor

Choose a reason for hiding this comment

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

Would typeof console !== 'undefined' be even more robust then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't know what environment might have console set to null or false or something silly like that, but I think this check should robust against whatever value console might have.

Technically typeof console === 'object' would be more specific, but it wouldn't yield a different result

'';
console.error(
`GraphQL: Name "${name}" must not begin with "__", which is ` +
'reserved by GraphQL introspection.' + stackOnly
Copy link
Contributor

Choose a reason for hiding this comment

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

"reserved for" better than "reserved by"?

const prevConsoleError = console.error;
const calls = [];
console.error = function () {
calls.push(Array.prototype.slice.call(arguments));
Copy link
Contributor

Choose a reason for hiding this comment

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

calls.push(Array.from(arguments));

Probably works in this environment too.

@leebyron leebyron merged commit 80f5ecb into master Jan 26, 2017
@leebyron leebyron deleted the dunder-warn branch January 26, 2017 21:22
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.

3 participants