-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,9 @@ | |
|
||
const NAME_RX = /^[_a-zA-Z][_a-zA-Z0-9]*$/; | ||
|
||
// Ensures console warnings are only issued once. | ||
let hasWarnedAboutDunder = false; | ||
|
||
/** | ||
* Upholds the spec rules about naming. | ||
*/ | ||
|
@@ -22,11 +25,17 @@ export function assertValidName( | |
`Must be named. Unexpected name: ${name}.` | ||
); | ||
} | ||
if (!isIntrospection && name.slice(0, 2) === '__') { | ||
throw new Error( | ||
`Name "${name}" must not begin with "__", which is reserved by ` + | ||
'GraphQL introspection.' | ||
); | ||
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 commentThe reason will be displayed to describe this comment to others. Learn more. When would There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know what environment might have Technically |
||
const error = new Error( | ||
`Name "${name}" must not begin with "__", which is reserved by ` + | ||
'GraphQL introspection.' | ||
); | ||
console.error(error.stack || String(error)); | ||
} | ||
/* eslint-enable no-console */ | ||
} | ||
if (!NAME_RX.test(name)) { | ||
throw new 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.
Probably works in this environment too.