@settlemint/sdk-thegraph
Version:
TheGraph integration module for SettleMint SDK, enabling querying and indexing of blockchain data through subgraphs
85 lines (83 loc) • 2.96 kB
text/typescript
import { AbstractSetupSchema, FragmentOf, ResultOf, VariablesOf, initGraphQLTada, readFragment } from "gql.tada";
import { GraphQLClient } from "graphql-request";
import { z } from "zod/v4";
//#region src/thegraph.d.ts
/**
* Type definition for GraphQL client configuration options
*/
type RequestConfig = ConstructorParameters<typeof GraphQLClient>[1];
/**
* Schema for validating client options for the TheGraph client.
*/
declare const ClientOptionsSchema: z.ZodObject<{
instances: z.ZodArray<z.ZodUnion<readonly [z.ZodString, z.ZodString]>>;
accessToken: z.ZodOptional<z.ZodString>;
subgraphName: z.ZodString;
cache: z.ZodOptional<z.ZodEnum<{
default: "default";
"force-cache": "force-cache";
"no-cache": "no-cache";
"no-store": "no-store";
"only-if-cached": "only-if-cached";
reload: "reload";
}>>;
}, z.core.$strip>;
/**
* Type definition for client options derived from the ClientOptionsSchema
*/
type ClientOptions = z.infer<typeof ClientOptionsSchema>;
/**
* Creates a TheGraph GraphQL client with proper type safety using gql.tada
*
* @param options - Configuration options for the client including instance URLs,
* access token and subgraph name
* @param clientOptions - Optional GraphQL client configuration options
* @returns An object containing:
* - client: The configured GraphQL client instance
* - graphql: The initialized gql.tada function for type-safe queries
* @throws Will throw an error if the options fail validation against ClientOptionsSchema
* @example
* import { createTheGraphClient } from '@settlemint/sdk-thegraph';
* import type { introspection } from '@schemas/the-graph-env-kits';
* import { createLogger, requestLogger } from '@settlemint/sdk-utils/logging';
*
* const logger = createLogger();
*
* const { client, graphql } = createTheGraphClient<{
* introspection: introspection;
* disableMasking: true;
* scalars: {
* Bytes: string;
* Int8: string;
* BigInt: string;
* BigDecimal: string;
* Timestamp: string;
* };
* }>({
* instances: JSON.parse(process.env.SETTLEMINT_THEGRAPH_SUBGRAPHS_ENDPOINTS || '[]'),
* accessToken: process.env.SETTLEMINT_ACCESS_TOKEN,
* subgraphName: 'kits'
* }, {
* fetch: requestLogger(logger, "the-graph-kits", fetch) as typeof fetch,
* });
*
* // Making GraphQL queries
* const query = graphql(`
* query SearchAssets {
* assets {
* id
* name
* symbol
* }
* }
* `);
*
* const result = await client.request(query);
*/
declare function createTheGraphClient<const Setup extends AbstractSetupSchema>(options: ClientOptions, clientOptions?: RequestConfig): {
client: GraphQLClient;
graphql: initGraphQLTada<Setup>;
};
//#endregion
export { ClientOptions, ClientOptionsSchema, FragmentOf, RequestConfig, ResultOf, VariablesOf, createTheGraphClient, readFragment };
//# sourceMappingURL=thegraph.d.cts.map