Javascript 运行并行脚本的Npm不工作
脚本的目的是不断尝试连接到服务器端点,并在可能的情况下生成graphql模式 如果在另一个命令提示符下运行该脚本,则该脚本工作正常。只是我想在一个命令提示符下运行一个命令 相反,我得到了一个错误: (节点:4212)MaxListenerSexceed矮化:检测到可能的EventEmitter内存泄漏。添加了11个终端侦听器。使用emitter.setMaxListeners()增加限制 这对我来说毫无意义,因为听众应该只被设置一次,而不是11次Javascript 运行并行脚本的Npm不工作,javascript,node.js,npm,graphql,Javascript,Node.js,Npm,Graphql,脚本的目的是不断尝试连接到服务器端点,并在可能的情况下生成graphql模式 如果在另一个命令提示符下运行该脚本,则该脚本工作正常。只是我想在一个命令提示符下运行一个命令 相反,我得到了一个错误: (节点:4212)MaxListenerSexceed矮化:检测到可能的EventEmitter内存泄漏。添加了11个终端侦听器。使用emitter.setMaxListeners()增加限制 这对我来说毫无意义,因为听众应该只被设置一次,而不是11次 dotnet run只运行asp.net服务器。
dotnet run
只运行asp.net服务器。很明显,这需要一些时间来启动,这就是为什么我编写这个脚本来不断尝试访问服务器
"start": "npm-run-all --parallel dotnet-run get-schema:dev",
"get-schema:dev": "node scripts/getSchema.js --url http://localhost:8080/graphql"
我正在使用npm软件包
getSchema脚本:
require('isomorphic-fetch');
const getArgs = require('get-args');
const FormData = require('form-data');
const fs = require('fs');
const {
buildClientSchema,
introspectionQuery,
printSchema,
} = require('graphql/utilities');
const path = require('path');
const schemaPath = path.join(__dirname, '../schema/schema');
const formData = new FormData();
formData.append('query', introspectionQuery);
const args = getArgs();
const url = args.options.url;
let intervalId = null;
// Save JSON of full schema introspection for Babel Relay Plugin to use
const setSchema = () => {
fetch(url, {
method: 'post',
body: formData,
})
.then((res) => {
if (res.ok) {
return res.json();
}
throw new Error(res.statusText);
})
.then((schemaJSON) => {
fs.writeFileSync(
`${schemaPath}.json`,
JSON.stringify(schemaJSON, null, 2),
);
// Save user readable type system shorthand of schema
const graphQLSchema = buildClientSchema(schemaJSON.data);
fs.writeFileSync(
`${schemaPath}.graphql`,
printSchema(graphQLSchema),
);
clearInterval(intervalId);
console.log('Successfuly updated schema.');
})
.catch((error) => {
console.log(error);
});
};
intervalId = setInterval(setSchema, 1000);
此脚本运行一段时间后,即使服务器已启动,也会出现错误:
FetchError:请求失败,原因:套接字挂起
更准确地说,这似乎“太好了”。实际上,您似乎实际上需要延迟依赖于服务器启动的脚本。该错误似乎表明在运行“获取”脚本时服务器尚未启动。@NeilLunn脚本确实在服务器启动之前运行,应该在找到服务器之前运行,因为如果使用延迟,我们不知道在服务器启动之前要延迟多长时间。但是,获取错误发生在服务器确实启动之后。我认为问题与此有关:也许我需要使用ping来代替。更准确地说,这似乎“太好了”。实际上,您似乎实际上需要延迟依赖于服务器启动的脚本。该错误似乎表明在运行“获取”脚本时服务器尚未启动。@NeilLunn脚本确实在服务器启动之前运行,应该在找到服务器之前运行,因为如果使用延迟,我们不知道在服务器启动之前要延迟多长时间。但是,获取错误发生在服务器确实启动之后。我认为问题与此有关:也许我需要使用ping来代替。