# All files / dist indexing-status.js

35.29% Statements 12/34
45% Branches 9/20
15.38% Functions 2/13
41.38% Lines 12/29

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    3x

    3x
    3x

    3x
    3x
    3x
    3x
    3x
    3x

    31x
    31x

    3x
     "use strict";
    var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
        function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
        return new (P || (P = Promise))(function (resolve, reject) {
            function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
            function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
            function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
            step((generator = generator.apply(thisArg, _arguments || [])).next());
        });
    };
    var __importDefault = (this && this.__importDefault) || function (mod) {
        return (mod && mod.__esModule) ? mod : { "default": mod };
    };
    Object.defineProperty(exports, "__esModule", { value: true });
    exports.IndexingStatusResolver = void 0;
    const isomorphic_fetch_1 = __importDefault(require("isomorphic-fetch"));
    const core_1 = require("@urql/core");
    const common_ts_1 = require("@graphprotocol/common-ts");
    const errors_1 = require("./errors");
    class IndexingStatusResolver {
        constructor(options) {
            this.logger = options.logger.child({ component: 'IndexingStatusFetcher' });
            this.statuses = core_1.createClient({
                url: options.statusEndpoint,
                fetch: isomorphic_fetch_1.default,
                requestPolicy: 'network-only',
            });
        }
        indexingStatus(deployments) {
            return __awaiter(this, void 0, void 0, function* () {
                const indexingStatusesQueryBody = `
          subgraphDeployment: subgraph
          synced
          health
          fatalError {
            handler
            message
          }
          node
          chains {
            network
            ... on EthereumIndexingStatus {
              latestBlock {
                number
                hash
              }
              chainHeadBlock {
                number
                hash
              }
              earliestBlock {
                number
                hash
              }
            }
          }`;
                const query = deployments.length > 0
                    ? `query indexingStatus($deployments: [String!]!) {
                indexingStatuses(subgraphs: $deployments) {
                  ${indexingStatusesQueryBody}
                }
              }`
                    : `query indexingStatus {
                indexingStatuses {
                  ${indexingStatusesQueryBody}
                }
              }`;
                try {
                    const result = yield this.statuses
                        .query(query, { deployments: deployments.map((id) => id.ipfsHash) })
                        .toPromise();
                    return (result.data.indexingStatuses
                        // eslint-disable-next-line @typescript-eslint/no-explicit-any
                        .map((status) => (Object.assign(Object.assign({}, status), { subgraphDeployment: new common_ts_1.SubgraphDeploymentID(status.subgraphDeployment) }))));
                }
                catch (error) {
                    const err = errors_1.indexerError(errors_1.IndexerErrorCode.IE018, error);
                    this.logger.error(`Failed to query indexing status API`, {
                        err,
                    });
                    throw err;
                }
            });
        }
    }
    exports.IndexingStatusResolver = IndexingStatusResolver;
    //# sourceMappingURL=indexing-status.js.map