UNPKG

@moonwell-fi/moonwell-sdk

Version:

TypeScript Interface for Moonwell

55 lines 1.96 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getGraphQL = getGraphQL; exports.getSubgraph = getSubgraph; const fetch_headers_js_1 = require("../../../common/fetch-headers.js"); async function getGraphQL(query, operationName, variables) { try { const response = await fetch("https://blue-api.morpho.org/graphql", { method: "POST", headers: fetch_headers_js_1.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; } } 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: fetch_headers_js_1.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