Skip to content

Commit

Permalink
make debug logs optional
Browse files Browse the repository at this point in the history
sgrove committed Mar 4, 2022
1 parent 01191be commit ce5e205
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -9,9 +9,14 @@ import {
OneGraphClient,
} from 'netlify-onegraph-internal';
import path from 'path';
import process from 'process'

const { Kind, parse, print } = GraphQL

const condLog = (message) => {
process.env.NETLIFY_GRAPH_DEBUG === 'true' && console.log(message);
}

/**
* Remove any relative path components from the given path
* @param {string[]} items Filesystem path items to filter
@@ -368,8 +373,8 @@ const readGraphQLOperationsSourceFiles = (netlifyGraphConfig) => {

const filenames = fs.readdirSync(operationsPath)

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

const source = print(parsedDoc)

console.log("GraphQL source", source)
condLog("GraphQL source", source)

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

console.log("netlifyGraphConfig", netlifyGraphConfig)
condLog("netlifyGraphConfig", netlifyGraphConfig)

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

console.log('Creating a new Netlify Graph schema');
condLog('Creating a new Netlify Graph schema');

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

console.log(
condLog(
'Created a new Netlify Graph schema',
createGraphQLSchemaResult
);

0 comments on commit ce5e205

Please sign in to comment.