UNPKG

@moonwell-fi/moonwell-sdk

Version:

TypeScript Interface for Moonwell

51 lines 1.8 kB
import { MOONWELL_FETCH_JSON_HEADERS } from "../../../common/fetch-headers.js"; export async function getGraphQL(query, operationName, variables) { try { const response = await fetch("https://blue-api.morpho.org/graphql", { method: "POST", headers: MOONWELL_FETCH_JSON_HEADERS, body: JSON.stringify({ query: query, operationName, variables }), signal: AbortSignal.timeout(10000), }); const json = await response.json(); if (response.status !== 200 || json.errors) { console.log(`Non-200 (${response.statusText} }) or other error from Morpho GraphQL! - ${JSON.stringify(response.statusText)}`); return undefined; } return json.data; } catch (error) { return undefined; } } export async function getSubgraph(environment, query, operationName, variables) { const url = environment.custom.morpho?.subgraphUrl; const body = { query }; if (operationName) { body.operationName = operationName; } if (variables) { body.variables = variables; } try { const response = await fetch(url, { method: "POST", headers: MOONWELL_FETCH_JSON_HEADERS, body: JSON.stringify(body), signal: AbortSignal.timeout(10000), }); const json = await response.json(); if (response.status !== 200 || json.errors) { console.log(response); console.log(`Non-200 (${response.statusText} }) or other error from Morpho GraphQL! - ${JSON.stringify(response.statusText)}`); return undefined; } return json.data; } catch (error) { return undefined; } } //# sourceMappingURL=graphql.js.map