subgraphService.jsβ’1.93 kB
import axios from 'axios';
import { API_ENDPOINTS, REQUEST_TIMEOUTS, DEFAULT_HEADERS, EVIDENCE_QUERY } from '../utils/constants.js';
export class SubgraphService {
async getEvidenceSubmissions(disputeId, chainId) {
const subgraphUrl = API_ENDPOINTS.SUBGRAPHS[chainId];
if (!subgraphUrl) {
throw new Error(`No subgraph URL configured for chain ID ${chainId}`);
}
try {
const response = await axios.post(subgraphUrl, {
query: EVIDENCE_QUERY,
variables: { id: disputeId }
}, {
timeout: REQUEST_TIMEOUTS.SUBGRAPH,
headers: DEFAULT_HEADERS
});
if (response.data.errors && response.data.errors.length > 0) {
const errorMessages = response.data.errors.map(err => err.message).join(', ');
throw new Error(`Subgraph query errors: ${errorMessages}`);
}
if (!response.data.data || !response.data.data.dispute?.evidenceGroup?.evidence) {
return [];
}
return response.data.data.dispute.evidenceGroup.evidence;
}
catch (error) {
if (axios.isAxiosError(error)) {
const apiError = {
message: `Failed to query subgraph: ${error.message}`,
code: error.code || 'SUBGRAPH_ERROR',
details: {
status: error.response?.status,
statusText: error.response?.statusText,
disputeId,
chainId,
subgraphUrl
}
};
throw apiError;
}
throw new Error(`Unexpected error querying subgraph: ${error instanceof Error ? error.message : 'Unknown error'}`);
}
}
}
//# sourceMappingURL=subgraphService.js.map