MCPcopy Create free account
hub / github.com/chainjet/platform / sendGraphqlQuery

Function sendGraphqlQuery

libs/definitions/src/utils/subgraph.utils.ts:131–169  ·  view source on GitHub ↗
(
  endpoint: string,
  query: string,
  headers: Record<string, any> = {},
  retries = 1,
  waitMillis = 300,
)

Source from the content-addressed store, hash-verified

129}
130
131export 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
171export async function runSubgraphOperation(
172 endpoints: Endpoints,

Callers 15

resolveAddressNameFunction · 0.90
getWalletNameFunction · 0.90
getWalletEnsFunction · 0.90
getWalletLensProfileFunction · 0.90
getNFTBalancePolygonFunction · 0.90
runMethod · 0.90
runMethod · 0.90
refreshLensAccessTokenFunction · 0.90
getLensDefaultProfileFunction · 0.90
getLensProfileFunction · 0.90
runMethod · 0.90

Calls 1

waitFunction · 0.90

Tested by

no test coverage detected