@superfluid-finance/sdk-core
Version:
SDK Core for building with Superfluid Protocol
28 lines • 1.01 kB
JavaScript
import { request } from "graphql-request";
export class SubgraphClient {
constructor(subgraphUrl) {
this.subgraphUrl = subgraphUrl;
}
async request(document, variables) {
return await 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
});
}
}
// 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