willwill96-petfinder-graphql
Version:
contains files and utilities to bootstrap a graphql instance wrapping the petfinder api
77 lines (76 loc) • 3.74 kB
JavaScript
;
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 __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const query_string_1 = __importDefault(require("query-string"));
const animals = (_, args, context) => __awaiter(void 0, void 0, void 0, function* () {
const { fetchPetfinderRoute } = context;
const res = yield fetchPetfinderRoute(`animals?${query_string_1.default.stringify(args, {
arrayFormat: 'comma',
})}`);
const { animals } = res, rest = __rest(res, ["animals"]);
return Object.assign(Object.assign({}, rest), { animals: animals.map(animal => {
const { organization_id } = animal, rest = __rest(animal, ["organization_id"]);
return Object.assign(Object.assign({}, rest), { organization: () => organization({}, { id: organization_id }, context) });
}) });
});
const animal = (_, args, context) => __awaiter(void 0, void 0, void 0, function* () {
const { fetchPetfinderRoute } = context;
const { id } = args;
const res = yield fetchPetfinderRoute(`animals/${id}`);
const _b = res.animal, { organization_id } = _b, rest = __rest(_b, ["organization_id"]);
return Object.assign(Object.assign({}, rest), { organization: () => organization({}, { id: organization_id }, context) });
});
const types = (_, _a, { fetchPetfinderRoute }) => __awaiter(void 0, void 0, void 0, function* () {
return yield fetchPetfinderRoute('types');
});
const typeBreeds = (_, args, { fetchPetfinderRoute }) => __awaiter(void 0, void 0, void 0, function* () {
const { type } = args;
return yield fetchPetfinderRoute(`types/${type}/breeds`);
});
const type = (_, args, { fetchPetfinderRoute }) => __awaiter(void 0, void 0, void 0, function* () {
const { type } = args;
return yield fetchPetfinderRoute(`types/${type}`);
});
const organizations = (_, args, { fetchPetfinderRoute }) => __awaiter(void 0, void 0, void 0, function* () {
return yield fetchPetfinderRoute(`/organizations?${query_string_1.default.stringify(args, {
arrayFormat: 'comma',
})}`);
});
const organization = (_, args, { fetchPetfinderRoute }) => __awaiter(void 0, void 0, void 0, function* () {
const { id } = args;
const res = yield fetchPetfinderRoute(`organizations/${id}`);
return res.organization;
});
exports.default = {
Query: {
animal,
animals,
organization,
organizations,
type,
types,
typeBreeds,
},
};