@superfluid-finance/sdk-core
Version:
SDK Core for building with Superfluid Protocol
32 lines • 1.19 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.SubgraphClient = void 0;
const graphql_request_1 = require("graphql-request");
class SubgraphClient {
constructor(subgraphUrl) {
this.subgraphUrl = subgraphUrl;
}
async request(document, variables) {
return await (0, graphql_request_1.request)({
url: this.subgraphUrl,
document,
variables: variables ? cleanVariables(variables) : undefined,
// TODO: explicit casting is semi-dirty and not recommended
// but I am not sure how to fix this right now
});
}
}
exports.SubgraphClient = SubgraphClient;
// Inspired by: https://stackoverflow.com/a/38340730
// Remove properties with null, undefined, empty string values.
function cleanVariables(variables) {
return Object.fromEntries(Object.entries(variables)
.filter(([, value]) => value !== "" && value !== null && value !== undefined)
.map(([key, value]) => [
key,
value === Object(value) && !Array.isArray(value)
? cleanVariables(value)
: value,
]));
}
//# sourceMappingURL=SubgraphClient.js.map
;