Skip to content

Commit

Permalink
[RFC] Environment var to silence warning about invalid names.
Browse files Browse the repository at this point in the history
This provides an opt-out of a spec compliance naming style for legacy schema
  • Loading branch information
leebyron committed May 1, 2017
1 parent 9033685 commit 423200f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/utilities/assertValidName.js
Expand Up @@ -11,6 +11,10 @@
const NAME_RX = /^[_a-zA-Z][_a-zA-Z0-9]*$/;
const ERROR_PREFIX_RX = /^Error: /;

// Silences warnings if an environment flag is enabled
const noNameWarning =
Boolean(process && process.env && process.env.GRAPHQL_NO_NAME_WARNING);

This comment has been minimized.

Copy link
@steadicat

steadicat May 3, 2017

Can you please use typeof process !== 'undefined'? process is not guaranteed to exist, depending on the build system/configuration.


// Ensures console warnings are only issued once.
let hasWarnedAboutDunder = false;

Expand All @@ -26,7 +30,12 @@ export function assertValidName(
`Must be named. Unexpected name: ${name}.`
);
}
if (!isIntrospection && name.slice(0, 2) === '__' && !hasWarnedAboutDunder) {
if (
!isIntrospection &&
!hasWarnedAboutDunder &&
!noNameWarning &&
name.slice(0, 2) === '__'
) {
hasWarnedAboutDunder = true;
/* eslint-disable no-console */
if (console && console.warn) {
Expand Down

0 comments on commit 423200f

Please sign in to comment.