@sterblue/sterblue-sdk
Version:
Sterblue Graph SDK for graphile.sterblue.com
407 lines (393 loc) • 8.17 kB
JavaScript
"use strict";
var _fp = require("lodash/fp");
var _streamingIterables = require("streaming-iterables");
var _streamQueryNoCount = require("../stream-query-no-count");
var _graphqlTag = _interopRequireDefault(require("graphql-tag"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
test("streamQueryNoCount", async () => {
const query = (0, _graphqlTag.default)`
query toto($first: Int, $offset: Int) {
myList(first: $first, offset: $offset) {
index
first
offset
}
}
`;
const maxRealData = 35;
const mockListQuery = async (_ref) => {
let {
variables: {
first,
offset
}
} = _ref,
rest = _objectWithoutProperties(_ref.variables, ["first", "offset"]);
return {
data: {
myList: (0, _fp.map)(index => _objectSpread({
index,
first,
offset
}, rest), (0, _fp.range)(Math.min(maxRealData, offset), Math.min(maxRealData, offset + first)))
}
};
};
expect(await (0, _streamingIterables.collect)(await (0, _streamQueryNoCount.streamQueryNoCount)(mockListQuery, ["data"])({
query: query,
variables: {
first: 17,
offset: 11,
batchSize: 3
}
}))).toEqual([{
first: 3,
index: 11,
offset: 11
}, {
first: 3,
index: 12,
offset: 11
}, {
first: 3,
index: 13,
offset: 11
}, {
first: 3,
index: 14,
offset: 14
}, {
first: 3,
index: 15,
offset: 14
}, {
first: 3,
index: 16,
offset: 14
}, {
first: 3,
index: 17,
offset: 17
}, {
first: 3,
index: 18,
offset: 17
}, {
first: 3,
index: 19,
offset: 17
}, {
first: 3,
index: 20,
offset: 20
}, {
first: 3,
index: 21,
offset: 20
}, {
first: 3,
index: 22,
offset: 20
}, {
first: 3,
index: 23,
offset: 23
}, {
first: 3,
index: 24,
offset: 23
}, {
first: 3,
index: 25,
offset: 23
}, {
first: 2,
index: 26,
offset: 26
}, {
first: 2,
index: 27,
offset: 26
}]);
expect(await (0, _streamingIterables.collect)(await (0, _streamQueryNoCount.streamQueryNoCount)(mockListQuery, ["data"])({
query: query,
variables: {
offset: 11,
batchSize: 3
}
}))).toEqual([{
first: 3,
index: 11,
offset: 11
}, {
first: 3,
index: 12,
offset: 11
}, {
first: 3,
index: 13,
offset: 11
}, {
first: 3,
index: 14,
offset: 14
}, {
first: 3,
index: 15,
offset: 14
}, {
first: 3,
index: 16,
offset: 14
}, {
first: 3,
index: 17,
offset: 17
}, {
first: 3,
index: 18,
offset: 17
}, {
first: 3,
index: 19,
offset: 17
}, {
first: 3,
index: 20,
offset: 20
}, {
first: 3,
index: 21,
offset: 20
}, {
first: 3,
index: 22,
offset: 20
}, {
first: 3,
index: 23,
offset: 23
}, {
first: 3,
index: 24,
offset: 23
}, {
first: 3,
index: 25,
offset: 23
}, {
first: 3,
index: 26,
offset: 26
}, {
first: 3,
index: 27,
offset: 26
}, {
first: 3,
index: 28,
offset: 26
}, {
first: 3,
index: 29,
offset: 29
}, {
first: 3,
index: 30,
offset: 29
}, {
first: 3,
index: 31,
offset: 29
}, {
first: 3,
index: 32,
offset: 32
}, {
first: 3,
index: 33,
offset: 32
}, {
first: 3,
index: 34,
offset: 32
}]);
expect(await (0, _streamingIterables.collect)(await (0, _streamQueryNoCount.streamQueryNoCount)(mockListQuery, ["data"])({
query: query,
variables: {
offset: 0,
first: 35,
batchSize: 35
}
}))).toEqual([{
first: 35,
index: 0,
offset: 0
}, {
first: 35,
index: 1,
offset: 0
}, {
first: 35,
index: 2,
offset: 0
}, {
first: 35,
index: 3,
offset: 0
}, {
first: 35,
index: 4,
offset: 0
}, {
first: 35,
index: 5,
offset: 0
}, {
first: 35,
index: 6,
offset: 0
}, {
first: 35,
index: 7,
offset: 0
}, {
first: 35,
index: 8,
offset: 0
}, {
first: 35,
index: 9,
offset: 0
}, {
first: 35,
index: 10,
offset: 0
}, {
first: 35,
index: 11,
offset: 0
}, {
first: 35,
index: 12,
offset: 0
}, {
first: 35,
index: 13,
offset: 0
}, {
first: 35,
index: 14,
offset: 0
}, {
first: 35,
index: 15,
offset: 0
}, {
first: 35,
index: 16,
offset: 0
}, {
first: 35,
index: 17,
offset: 0
}, {
first: 35,
index: 18,
offset: 0
}, {
first: 35,
index: 19,
offset: 0
}, {
first: 35,
index: 20,
offset: 0
}, {
first: 35,
index: 21,
offset: 0
}, {
first: 35,
index: 22,
offset: 0
}, {
first: 35,
index: 23,
offset: 0
}, {
first: 35,
index: 24,
offset: 0
}, {
first: 35,
index: 25,
offset: 0
}, {
first: 35,
index: 26,
offset: 0
}, {
first: 35,
index: 27,
offset: 0
}, {
first: 35,
index: 28,
offset: 0
}, {
first: 35,
index: 29,
offset: 0
}, {
first: 35,
index: 30,
offset: 0
}, {
first: 35,
index: 31,
offset: 0
}, {
first: 35,
index: 32,
offset: 0
}, {
first: 35,
index: 33,
offset: 0
}, {
first: 35,
index: 34,
offset: 0
}]); // expect(
// await collect(
// await streamQuery(mockListQuery)({
// first: 3,
// offset: 4,
// batchSize: 17
// })
// )
// ).toEqual([
// { first: 3, index: 4, offset: 4 },
// { first: 3, index: 5, offset: 4 },
// { first: 3, index: 6, offset: 4 }
// ]);
// expect(
// await collect(
// await streamQuery(mockListQuery, mockCountQuery)({
// first: 17,
// offset: 7,
// batchSize: 11
// })
// )
// ).toEqual([
// { first: 3, index: 7, offset: 7 },
// { first: 3, index: 8, offset: 7 },
// { first: 3, index: 9, offset: 7 }
// ]);
});