gatsby-theme-advanced
Version:
GatsbyJS theme equipped with advanced features.
48 lines (47 loc) • 2.35 kB
JavaScript
;
/* eslint "no-console": "off" */
/* eslint "@typescript-eslint/no-explicit-any": "off" */
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());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getCategoryListing = exports.getTagListing = exports.getIndexListing = void 0;
const types_1 = require("../../src/types");
const queries_1 = require("../../src/templates/feed/queries");
// Process the query results and return a PostList
const processQueryResult = (result) => {
// Exit on error
if (result.errors) {
console.error("Error while processing query results:");
console.error(result.errors);
throw Error(result.errors);
}
if (!result.data) {
console.warn("processQueryResult: No data returned by the query. Returning empty PostList.");
return [];
}
return (0, types_1.queryIntoListing)(result.data);
};
const getIndexListing = (graphql) => __awaiter(void 0, void 0, void 0, function* () {
const indexQueryResult = yield graphql(queries_1.indexListingQuery);
return processQueryResult(indexQueryResult);
});
exports.getIndexListing = getIndexListing;
const getTagListing = (graphql, tag) => __awaiter(void 0, void 0, void 0, function* () {
const tagQueryResult = yield graphql(queries_1.tagListingQuery, {
tag,
});
return processQueryResult(tagQueryResult);
});
exports.getTagListing = getTagListing;
const getCategoryListing = (graphql, category) => __awaiter(void 0, void 0, void 0, function* () {
const categoryQueryResult = yield graphql(queries_1.categoryListingQuery, { category });
return processQueryResult(categoryQueryResult);
});
exports.getCategoryListing = getCategoryListing;