(
endpoint: string,
query: string,
headers: Record<string, any> = {},
retries = 1,
waitMillis = 300,
)
| 129 | } |
| 130 | |
| 131 | export async function sendGraphqlQuery( |
| 132 | endpoint: string, |
| 133 | query: string, |
| 134 | headers: Record<string, any> = {}, |
| 135 | retries = 1, |
| 136 | waitMillis = 300, |
| 137 | ): Promise<any> { |
| 138 | try { |
| 139 | const res = await axios({ |
| 140 | method: 'POST', |
| 141 | url: endpoint, |
| 142 | headers: { |
| 143 | 'Content-Type': 'application/json', |
| 144 | Accept: 'application/json', |
| 145 | ...headers, |
| 146 | }, |
| 147 | data: { |
| 148 | query: compress(query), |
| 149 | }, |
| 150 | }) |
| 151 | |
| 152 | // retry 5xx errors |
| 153 | if (res.status >= 500 && retries) { |
| 154 | await wait(waitMillis) |
| 155 | return sendGraphqlQuery(endpoint, query, headers, retries - 1) |
| 156 | } |
| 157 | |
| 158 | return res.data |
| 159 | } catch (e) { |
| 160 | if (e.response?.status >= 500 && retries) { |
| 161 | await wait(waitMillis) |
| 162 | return sendGraphqlQuery(endpoint, query, headers, retries - 1) |
| 163 | } |
| 164 | if (e.response?.data?.errors?.[0]?.message) { |
| 165 | throw new Error(e.response.data.errors[0].message) |
| 166 | } |
| 167 | throw e |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | export async function runSubgraphOperation( |
| 172 | endpoints: Endpoints, |
no test coverage detected