Skip to content

Commit ce5e205

Browse files
committed
make debug logs optional
1 parent 01191be commit ce5e205

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/index.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,14 @@ import {
99
OneGraphClient,
1010
} from 'netlify-onegraph-internal';
1111
import path from 'path';
12+
import process from 'process'
1213

1314
const { Kind, parse, print } = GraphQL
1415

16+
const condLog = (message) => {
17+
process.env.NETLIFY_GRAPH_DEBUG === 'true' && console.log(message);
18+
}
19+
1520
/**
1621
* Remove any relative path components from the given path
1722
* @param {string[]} items Filesystem path items to filter
@@ -368,8 +373,8 @@ const readGraphQLOperationsSourceFiles = (netlifyGraphConfig) => {
368373

369374
const filenames = fs.readdirSync(operationsPath)
370375

371-
console.log("operationsPath", operationsPath)
372-
console.log("filenames", filenames)
376+
condLog("operationsPath", operationsPath)
377+
condLog("filenames", filenames)
373378
filenames.forEach((filename) => {
374379
if (/.*\.(graphql?)/gi.test(filename)) {
375380
const content = fs.readFileSync(path.resolve(operationsPath, filename), 'utf8')
@@ -400,7 +405,7 @@ const readGraphQLOperationsSourceFiles = (netlifyGraphConfig) => {
400405

401406
const source = print(parsedDoc)
402407

403-
console.log("GraphQL source", source)
408+
condLog("GraphQL source", source)
404409

405410
return source
406411
}
@@ -521,7 +526,7 @@ Run \`netlify graph:init\` to generate a new token.`
521526
site: siteInfo,
522527
});
523528

524-
console.log("netlifyGraphConfig", netlifyGraphConfig)
529+
condLog("netlifyGraphConfig", netlifyGraphConfig)
525530

526531
let netlifyGraphJson;
527532
try {
@@ -537,7 +542,7 @@ Run \`netlify graph:init\` to generate a new token.`
537542
);
538543
}
539544

540-
console.log('Creating a new Netlify Graph schema');
545+
condLog('Creating a new Netlify Graph schema');
541546

542547
const createGraphQLSchemaResult =
543548
await OneGraphClient.executeCreateGraphQLSchemaMutation(
@@ -557,7 +562,7 @@ Run \`netlify graph:init\` to generate a new token.`
557562
}
558563
);
559564

560-
console.log(
565+
condLog(
561566
'Created a new Netlify Graph schema',
562567
createGraphQLSchemaResult
563568
);

0 commit comments

Comments
 (0)