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.
Implements
Section titled “Implements”Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new SubgraphService(subgraphConfig): SubgraphService;
Defined in: packages/synapse-sdk/src/subgraph/service.ts:173
Parameters
Section titled “Parameters”Parameter | Type |
---|---|
subgraphConfig | SubgraphConfig |
Returns
Section titled “Returns”SubgraphService
Methods
Section titled “Methods”getApprovedProvidersForPieceCID()
Section titled “getApprovedProvidersForPieceCID()”getApprovedProvidersForPieceCID(pieceCid): Promise<ProviderInfo[]>;
Defined in: packages/synapse-sdk/src/subgraph/service.ts:474
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.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
pieceCid | PieceLink | The piece commitment (PieceCID) to search for. |
Returns
Section titled “Returns”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.
Implementation of
Section titled “Implementation of”SubgraphRetrievalService
.getApprovedProvidersForPieceCID
getProviderByAddress()
Section titled “getProviderByAddress()”getProviderByAddress(address): Promise<null | ProviderInfo>;
Defined in: packages/synapse-sdk/src/subgraph/service.ts:519
Queries the subgraph to find a specific approved service provider by their address.
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
address | string | The wallet address of the provider to search for. |
Returns
Section titled “Returns”Promise
<null
| ProviderInfo
>
A promise that resolves to an ProviderInfo
object if the provider is found, or null
otherwise.
Implementation of
Section titled “Implementation of”SubgraphRetrievalService
.getProviderByAddress
queryDataSets()
Section titled “queryDataSets()”queryDataSets(options): Promise<DetailedSubgraphDataSetInfo[]>;
Defined in: packages/synapse-sdk/src/subgraph/service.ts:599
Generic method to query data sets with flexible where clauses
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
options | QueryOptions | Query options including where clause, pagination, and ordering |
Returns
Section titled “Returns”Promise
<DetailedSubgraphDataSetInfo
[]>
A promise that resolves to an array of DetailedSubgraphDataSetInfo
objects
Example
Section titled “Example”// Get active data setsconst activeDataSets = await service.queryDataSets({ where: { isActive: true }, first: 50, orderBy: "createdAt", orderDirection: "desc"});
// Get data sets by owner with minimum data sizeconst largeDataSets = await service.queryDataSets({ where: { owner: "0x123...", totalDataSize_gte: "1000000000" }});
queryFaultRecords()
Section titled “queryFaultRecords()”queryFaultRecords(options): Promise<FaultRecord[]>;
Defined in: packages/synapse-sdk/src/subgraph/service.ts:735
Generic method to query fault records with flexible where clauses
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
options | QueryOptions | Query options including where clause, pagination, and ordering |
Returns
Section titled “Returns”A promise that resolves to an array of FaultRecord
objects
Example
Section titled “Example”// Get recent fault recordsconst recentFaults = await service.queryFaultRecords({ where: { createdAt_gte: "1640995200" }, first: 20, orderBy: "createdAt", orderDirection: "desc"});
// Get fault records for specific data setconst dataSetFaults = await service.queryFaultRecords({ where: { dataSetId: "123" }});
queryPieces()
Section titled “queryPieces()”queryPieces(options): Promise<PieceInfo[]>;
Defined in: packages/synapse-sdk/src/subgraph/service.ts:675
Generic method to query pieces with flexible where clauses
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
options | QueryOptions | Query options including where clause, pagination, and ordering |
Returns
Section titled “Returns”A promise that resolves to an array of PieceInfo
objects
Example
Section titled “Example”// Get pieces by data setconst dataSetPieces = await service.queryPieces({ where: { dataSet: "0x123..." }, first: 100, orderBy: "createdAt"});
// Get non-removed pieces with minimum sizeconst largePieces = await service.queryPieces({ where: { removed: false, rawSize_gte: "1000000" }});
queryProviders()
Section titled “queryProviders()”queryProviders(options): Promise<ProviderInfo[]>;
Defined in: packages/synapse-sdk/src/subgraph/service.ts:557
Generic method to query providers with flexible where clauses
Parameters
Section titled “Parameters”Parameter | Type | Description |
---|---|---|
options | QueryOptions | Query options including where clause, pagination, and ordering |
Returns
Section titled “Returns”A promise that resolves to an array of ProviderInfo
objects
Example
Section titled “Example”// Get providers with specific statusconst approvedProviders = await service.queryProviders({ where: { status: "APPROVED" }, first: 10, orderBy: "approvedAt", orderDirection: "desc"});
// Get providers with minimum data setsconst activeProviders = await service.queryProviders({ where: { totalDataSets_gte: "5" }, first: 20});