Skip to content

SubgraphService

Defined in: packages/synapse-sdk/src/subgraph/service.ts:169

Defines the contract for a service that can retrieve provider information from a data source, typically a Synapse-compatible subgraph.

This interface allows for custom implementations to be provided in place of the default SubgraphService. Any service that implements this interface can be used with the Synapse SDK by passing it via the subgraphService option when creating a Synapse instance.

This enables integration with alternative data sources or custom implementations while maintaining compatibility with the SDK’s retrieval system.

new SubgraphService(subgraphConfig): SubgraphService;

Defined in: packages/synapse-sdk/src/subgraph/service.ts:173

ParameterType
subgraphConfigSubgraphConfig

SubgraphService

getApprovedProvidersForPieceCID(pieceCid): Promise<ProviderInfo[]>;

Defined in: packages/synapse-sdk/src/subgraph/service.ts:475

Queries the subgraph to find approved service providers that have a specific piece (PieceCID).

It sends a GraphQL query to the configured endpoint and parses the response to extract a list of providers, including their addresses and retrieval URLs.

ParameterTypeDescription
pieceCidPieceLinkThe piece commitment (PieceCID) to search for.

Promise<ProviderInfo[]>

A promise that resolves to an array of ProviderInfo objects. Returns an empty array if no providers are found or if an error occurs during the fetch.

SubgraphRetrievalService.getApprovedProvidersForPieceCID


getProviderByAddress(address): Promise<
| ProviderInfo
| null>;

Defined in: packages/synapse-sdk/src/subgraph/service.ts:520

Queries the subgraph to find a specific approved service provider by their address.

ParameterTypeDescription
addressstringThe wallet address of the provider to search for.

Promise< | ProviderInfo | null>

A promise that resolves to an ProviderInfo object if the provider is found, or null otherwise.

SubgraphRetrievalService.getProviderByAddress


queryDataSets(options): Promise<DetailedSubgraphDataSetInfo[]>;

Defined in: packages/synapse-sdk/src/subgraph/service.ts:600

Generic method to query data sets with flexible where clauses

ParameterTypeDescription
optionsQueryOptionsQuery options including where clause, pagination, and ordering

Promise<DetailedSubgraphDataSetInfo[]>

A promise that resolves to an array of DetailedSubgraphDataSetInfo objects

// Get active data sets
const activeDataSets = await service.queryDataSets({
where: { isActive: true },
first: 50,
orderBy: "createdAt",
orderDirection: "desc"
});
// Get data sets by owner with minimum data size
const largeDataSets = await service.queryDataSets({
where: {
owner: "0x123...",
totalDataSize_gte: "1000000000"
}
});

queryFaultRecords(options): Promise<FaultRecord[]>;

Defined in: packages/synapse-sdk/src/subgraph/service.ts:736

Generic method to query fault records with flexible where clauses

ParameterTypeDescription
optionsQueryOptionsQuery options including where clause, pagination, and ordering

Promise<FaultRecord[]>

A promise that resolves to an array of FaultRecord objects

// Get recent fault records
const recentFaults = await service.queryFaultRecords({
where: { createdAt_gte: "1640995200" },
first: 20,
orderBy: "createdAt",
orderDirection: "desc"
});
// Get fault records for specific data set
const dataSetFaults = await service.queryFaultRecords({
where: { dataSetId: "123" }
});

queryPieces(options): Promise<PieceInfo[]>;

Defined in: packages/synapse-sdk/src/subgraph/service.ts:676

Generic method to query pieces with flexible where clauses

ParameterTypeDescription
optionsQueryOptionsQuery options including where clause, pagination, and ordering

Promise<PieceInfo[]>

A promise that resolves to an array of PieceInfo objects

// Get pieces by data set
const dataSetPieces = await service.queryPieces({
where: { dataSet: "0x123..." },
first: 100,
orderBy: "createdAt"
});
// Get non-removed pieces with minimum size
const largePieces = await service.queryPieces({
where: {
removed: false,
rawSize_gte: "1000000"
}
});

queryProviders(options): Promise<ProviderInfo[]>;

Defined in: packages/synapse-sdk/src/subgraph/service.ts:558

Generic method to query providers with flexible where clauses

ParameterTypeDescription
optionsQueryOptionsQuery options including where clause, pagination, and ordering

Promise<ProviderInfo[]>

A promise that resolves to an array of ProviderInfo objects

// Get providers with specific status
const approvedProviders = await service.queryProviders({
where: { status: "APPROVED" },
first: 10,
orderBy: "approvedAt",
orderDirection: "desc"
});
// Get providers with minimum data sets
const activeProviders = await service.queryProviders({
where: { totalDataSets_gte: "5" },
first: 20
});