try {
const serviceID = process.env.SITE_SERVICE_ID
const environmentID = process.env.SITE_ENVIRONMENT_ID
const gqlReq = async (options) => {
const req = await fetch(`https://backboard.railway.app/graphql/v2?q=${options.operationName}`, {
headers: {
"cache-control": "no-cache",
"content-type": "application/json",
},
method: "POST",
body: JSON.stringify({
operationName: options.operationName,
query: options.query,
variables: options.variables,
}),
mode: "cors",
credentials: "include",
})
if (req.status != 200) {
return [null, Error(`Non 200 status code returned from API: ${req.status}`)]
}
const res = await req.json()
if (res.errors != undefined) {
return [null, Error(res.errors[0].message)]
}
if (res.data == null) {
return [null, Error("The API returned the null data type")]
}
return [res.data[options.operationName], null]
}
const [serviceInstanceRedeploy, serviceInstanceRedeployError] = await gqlReq({
operationName: "serviceInstanceRedeploy",
query: `mutation serviceInstanceRedeploy($environmentId: String!, $serviceId: String!) {\n serviceInstanceRedeploy(environmentId: $environmentId, serviceId: $serviceId)\n}`,
variables: {
"environmentId": environmentID,
"serviceId": serviceID,
},
})
if (serviceInstanceRedeployError != null) {
console.error('Error hitting webhook', serviceInstanceRedeployError)
return
}
publishWebhookTimeout = null
} catch (err) {
// eslint-disable-next-line no-console
console.error('Error hitting webhook', err)
}