From cee19aebe76645ce519949cb254f7e563f9d77ce Mon Sep 17 00:00:00 2001 From: Jordan Frankfurt Date: Wed, 22 Mar 2023 11:14:07 -0400 Subject: [PATCH] fix: improve fetch-schema logging and platform support (#6191) * fix: improve fetch-schema logging and platform support * don't use async/await because linter doesn't like it --- scripts/fetch-schema.js | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/scripts/fetch-schema.js b/scripts/fetch-schema.js index 987f5ff7c9..963fbb2bd5 100644 --- a/scripts/fetch-schema.js +++ b/scripts/fetch-schema.js @@ -1,22 +1,27 @@ /* eslint-env node */ require('dotenv').config({ path: '.env.production' }) - -const { exec } = require('child_process') +const child_process = require('child_process') +const fs = require('fs/promises') +const { promisify } = require('util') const dataConfig = require('../graphql.config') const thegraphConfig = require('../graphql_thegraph.config') +const exec = promisify(child_process.exec) + function fetchSchema(url, outputFile) { - exec( - `get-graphql-schema --h Origin=https://app.uniswap.org ${url} | tee ${outputFile}.temp`, - (error, stdout, stderr) => { - if (error || stderr) { - console.log(`Failed to fetch schema from ${url}`) - } else if (stdout) { - exec(`mv ${outputFile}.temp ${outputFile}`) + exec(`npx get-graphql-schema --h Origin=https://app.uniswap.org ${url}`) + .then(({ stderr, stdout }) => { + if (stderr) { + throw new Error(stderr) + } else { + fs.writeFile(outputFile, stdout) } - } - ) + }) + .catch((err) => { + console.error(err) + console.error(`Failed to fetch schema from ${url}`) + }) } fetchSchema(process.env.THE_GRAPH_SCHEMA_ENDPOINT, thegraphConfig.schema)