UNPKG

tempus-api-graphql

Version:

A GraphQL wrapper for the tempus api (tempus2.xyz)

318 lines (284 loc) 11.1 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); Object.defineProperty(exports, "newCachedTempusFetcher", { enumerable: true, get: function get() { return _tempus.newCachedTempusFetcher; } }); exports.newTempusSchema = newTempusSchema; exports.schema = void 0; require("regenerator-runtime/runtime"); var _graphql = require("graphql"); var _tempus = require("./tempus"); var _map = _interopRequireDefault(require("./types/map")); var _map2 = _interopRequireDefault(require("./models/map")); var _player = _interopRequireDefault(require("./types/player")); var _player2 = _interopRequireDefault(require("./models/player")); var _record = _interopRequireDefault(require("./types/record")); var _record2 = _interopRequireDefault(require("./models/record")); var _demo = _interopRequireDefault(require("./types/demo")); var _demo2 = _interopRequireDefault(require("./models/demo")); var _server = _interopRequireDefault(require("./types/server")); var _server2 = _interopRequireDefault(require("./models/server")); var _activity = _interopRequireDefault(require("./types/activity")); var _activity2 = _interopRequireDefault(require("./models/activity")); var _ranking_type_enum = _interopRequireDefault(require("./types/ranking_type_enum")); var _ranking = _interopRequireDefault(require("./types/ranking")); var _ranking2 = _interopRequireDefault(require("./models/ranking")); var _fetch_response_by_url = _interopRequireDefault(require("./utils/fetch_response_by_url")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } var RankingListingType = new _graphql.GraphQLObjectType({ name: "RankingListing", fields: function fields() { return { count: { type: new _graphql.GraphQLNonNull(_graphql.GraphQLInt) }, entries: { type: new _graphql.GraphQLNonNull(new _graphql.GraphQLList(new _graphql.GraphQLNonNull(_ranking["default"]))) } }; } }); function newTempusSchema(tempus) { var context = { tempus: tempus }; var QueryType = new _graphql.GraphQLObjectType({ name: "Query", fields: function fields() { return { map: { type: _map["default"], args: { name: { type: _graphql.GraphQLString }, id: { type: _graphql.GraphQLInt } }, resolve: function resolve(root, args) { return new _map2["default"](context, args); } }, maps: { type: new _graphql.GraphQLNonNull(new _graphql.GraphQLList(new _graphql.GraphQLNonNull(_map["default"]))), args: { search: { type: _graphql.GraphQLString }, start: { type: _graphql.GraphQLInt }, limit: { type: _graphql.GraphQLInt } }, resolve: function resolve(root, args) { return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() { var maps; return regeneratorRuntime.wrap(function _callee$(_context) { while (1) { switch (_context.prev = _context.next) { case 0: _context.next = 2; return context.tempus.allMaps.load(); case 2: maps = _context.sent; if (args.search) maps = maps.filter(function (map) { return map.name.includes(args.search); }); if (args.start) maps = maps.slice(args.start - 1); if (args.limit) maps = maps.slice(0, args.limit); return _context.abrupt("return", maps.map(function (m) { return new _map2["default"](context, m); })); case 7: case "end": return _context.stop(); } } }, _callee); }))(); } }, player: { type: _player["default"], args: { id: { type: new _graphql.GraphQLNonNull(_graphql.GraphQLInt) } }, resolve: function resolve(root, args) { return new _player2["default"](context, args); } }, record: { type: _record["default"], args: { id: { type: new _graphql.GraphQLNonNull(_graphql.GraphQLInt) } }, resolve: function resolve(root, args) { return new _record2["default"](context, args); } }, demo: { type: _demo["default"], args: { id: { type: new _graphql.GraphQLNonNull(_graphql.GraphQLInt) } }, resolve: function resolve(root, args) { return new _demo2["default"](context, args); } }, server: { type: _server["default"], args: { id: { type: new _graphql.GraphQLNonNull(_graphql.GraphQLInt) } }, resolve: function resolve(root, args) { return new _server2["default"](context, args); } }, servers: { type: new _graphql.GraphQLNonNull(new _graphql.GraphQLList(new _graphql.GraphQLNonNull(_server["default"]))), args: { search: { type: _graphql.GraphQLString }, start: { type: _graphql.GraphQLInt }, limit: { type: _graphql.GraphQLInt } }, resolve: function resolve(root, args) { return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee2() { var servers; return regeneratorRuntime.wrap(function _callee2$(_context2) { while (1) { switch (_context2.prev = _context2.next) { case 0: _context2.next = 2; return context.tempus.allServers.load(); case 2: servers = _context2.sent; if (args.search) servers = servers.filter(function (server) { return server.name.includes(args.search); }); if (args.start) servers = servers.slice(args.start - 1); if (args.limit) servers = servers.slice(0, args.limit); return _context2.abrupt("return", servers.map(function (s) { return new _server2["default"](context, s); })); case 7: case "end": return _context2.stop(); } } }, _callee2); }))(); } }, activity: { type: new _graphql.GraphQLNonNull(_activity["default"]), resolve: function resolve() { return new _activity2["default"](context); } }, players: { type: new _graphql.GraphQLNonNull(new _graphql.GraphQLList(new _graphql.GraphQLNonNull(_player["default"]))), args: { search: { type: _graphql.GraphQLString }, start: { type: _graphql.GraphQLInt }, limit: { type: _graphql.GraphQLInt } }, resolve: function resolve(root, args) { return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee3() { var players; return regeneratorRuntime.wrap(function _callee3$(_context3) { while (1) { switch (_context3.prev = _context3.next) { case 0: _context3.next = 2; return context.tempus.playerSearch.load(args.search); case 2: players = _context3.sent; if (args.start) players = players.slice(args.start - 1); if (args.limit) players = players.slice(0, args.limit); return _context3.abrupt("return", players.map(function (m) { return new _player2["default"](context, m); })); case 6: case "end": return _context3.stop(); } } }, _callee3); }))(); } }, rankings: { type: new _graphql.GraphQLNonNull(RankingListingType), args: { start: { type: _graphql.GraphQLInt }, type: { type: new _graphql.GraphQLNonNull(_ranking_type_enum["default"]) } }, resolve: function resolve(root, args) { return _asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee4() { var rankings; return regeneratorRuntime.wrap(function _callee4$(_context4) { while (1) { switch (_context4.prev = _context4.next) { case 0: _context4.next = 2; return context.tempus.rankingsByType.load(args); case 2: rankings = _context4.sent; return _context4.abrupt("return", { count: rankings.count, entries: rankings.players.map(function (s) { return new _ranking2["default"](context, s); }) }); case 4: case "end": return _context4.stop(); } } }, _callee4); }))(); } } }; } }); return new _graphql.GraphQLSchema({ query: QueryType }); } var schema = newTempusSchema((0, _tempus.newCachedTempusFetcher)(_fetch_response_by_url["default"])); exports.schema = schema;