@@ -9,9 +9,14 @@ import {
99 OneGraphClient ,
1010} from 'netlify-onegraph-internal' ;
1111import path from 'path' ;
12+ import process from 'process'
1213
1314const { 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 ( / .* \. ( g r a p h q l ? ) / 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