@settlemint/sdk-thegraph
Version:
TheGraph integration module for SettleMint SDK, enabling querying and indexing of blockchain data through subgraphs
69 lines (68 loc) • 2.72 kB
JavaScript
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/thegraph.ts
var thegraph_exports = {};
__export(thegraph_exports, {
ClientOptionsSchema: () => ClientOptionsSchema,
createTheGraphClient: () => createTheGraphClient,
readFragment: () => import_gql2.readFragment
});
module.exports = __toCommonJS(thegraph_exports);
var import_runtime = require("@settlemint/sdk-utils/runtime");
var import_validation = require("@settlemint/sdk-utils/validation");
var import_gql = require("gql.tada");
var import_graphql_request = require("graphql-request");
var import_zod = require("zod");
var import_gql2 = require("gql.tada");
var ClientOptionsSchema = import_zod.z.object({
instances: import_zod.z.array(import_validation.UrlOrPathSchema),
accessToken: import_validation.ApplicationAccessTokenSchema,
subgraphName: import_zod.z.string(),
cache: import_zod.z.enum(["default", "force-cache", "no-cache", "no-store", "only-if-cached", "reload"]).optional()
});
function getFullUrl(options) {
const instance = options.instances.find((instance2) => instance2.endsWith(`/${options.subgraphName}`));
if (!instance) {
throw new Error(`Instance for subgraph ${options.subgraphName} not found`);
}
return new URL(instance).toString();
}
function createTheGraphClient(options, clientOptions) {
(0, import_runtime.ensureServer)();
const validatedOptions = (0, import_validation.validate)(ClientOptionsSchema, options);
const graphql = (0, import_gql.initGraphQLTada)();
const fullUrl = getFullUrl(validatedOptions);
return {
client: new import_graphql_request.GraphQLClient(fullUrl, {
...clientOptions,
headers: {
...clientOptions?.headers ?? {},
"x-auth-token": validatedOptions.accessToken
}
}),
graphql
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
ClientOptionsSchema,
createTheGraphClient,
readFragment
});
//# sourceMappingURL=thegraph.cjs.map
;