-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Conversation
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
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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)); |
There was a problem hiding this comment.
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.
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