@shopify/graphql-testing
Advanced tools
Comparing version 4.4.7 to 5.0.0
@@ -1,73 +0,32 @@ | ||
"use strict"; | ||
'use strict'; | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.TestingApolloClient = void 0; | ||
var apolloClient = require('apollo-client'); | ||
var _apolloClient = require("apollo-client"); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
// no-cache and network-only fetch policies cause an initial async event to be | ||
// produced which is not properly caught inside of a react-testing act scope. | ||
var invalidFetchPolicies = ['no-cache', 'network-only']; // patch getCurrentQueryResult to protect against an initial observable event | ||
const invalidFetchPolicies = ['no-cache', 'network-only']; // patch getCurrentQueryResult to protect against an initial observable event | ||
var TestingApolloClient = /*#__PURE__*/function (_ApolloClient) { | ||
_inherits(TestingApolloClient, _ApolloClient); | ||
class TestingApolloClient extends apolloClient.ApolloClient { | ||
constructor(options) { | ||
super(options); | ||
this.getCurrentQueryResult = void 0; | ||
this.getCurrentQueryResult = this.queryManager.getCurrentQueryResult.bind(this.queryManager); | ||
this.queryManager.getCurrentQueryResult = this.getCurrentQueryResultSafe.bind(this); | ||
} | ||
var _super = _createSuper(TestingApolloClient); | ||
function TestingApolloClient(options) { | ||
var _this; | ||
_classCallCheck(this, TestingApolloClient); | ||
_this = _super.call(this, options); | ||
_this.getCurrentQueryResult = void 0; | ||
_this.getCurrentQueryResult = _this.queryManager.getCurrentQueryResult.bind(_this.queryManager); | ||
_this.queryManager.getCurrentQueryResult = _this.getCurrentQueryResultSafe.bind(_assertThisInitialized(_this)); | ||
return _this; | ||
getCurrentQueryResultSafe(observableQuery, optimistic) { | ||
const result = this.getCurrentQueryResult(observableQuery, optimistic); | ||
result.partial = isPartial(observableQuery, result); | ||
return result; | ||
} | ||
_createClass(TestingApolloClient, [{ | ||
key: "getCurrentQueryResultSafe", | ||
value: function getCurrentQueryResultSafe(observableQuery, optimistic) { | ||
var result = this.getCurrentQueryResult(observableQuery, optimistic); | ||
result.partial = isPartial(observableQuery, result); | ||
return result; | ||
} | ||
}]); | ||
return TestingApolloClient; | ||
}(_apolloClient.ApolloClient); // detect the conditions where we need to override partial to true | ||
} // detect the conditions where we need to override partial to true | ||
// see https://github.com/apollographql/apollo-client/blob/413b41211a232911824e7ede62e41e2910ae1a25/packages/apollo-client/src/core/QueryManager.ts#L1036-L1038 | ||
exports.TestingApolloClient = TestingApolloClient; | ||
function isPartial(observableQuery, _ref) { | ||
var data = _ref.data, | ||
partial = _ref.partial; | ||
function isPartial(observableQuery, { | ||
data, | ||
partial | ||
}) { | ||
if (!observableQuery.getLastResult() && invalidFetchPolicies.includes(observableQuery.options.fetchPolicy) && data === undefined && partial === false) { | ||
@@ -79,2 +38,4 @@ return true; | ||
return partial; | ||
} | ||
} | ||
exports.TestingApolloClient = TestingApolloClient; |
@@ -1,14 +0,13 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.createGraphQLFactory = createGraphQLFactory; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var _graphqlController = require("./graphql-controller.js"); | ||
var graphqlController = require('./graphql-controller.js'); | ||
function createGraphQLFactory(options) { | ||
return function createGraphQL(mock) { | ||
return new _graphqlController.GraphQL(mock, options); | ||
return new graphqlController.GraphQL(mock, options); | ||
}; | ||
} | ||
} | ||
exports.createGraphQLFactory = createGraphQLFactory; |
@@ -1,54 +0,21 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.GraphQL = void 0; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js'); | ||
var apolloLink = require('apollo-link'); | ||
var apolloCacheInmemory = require('apollo-cache-inmemory'); | ||
var client = require('./client.js'); | ||
var operations = require('./operations.js'); | ||
var utilities = require('./utilities.js'); | ||
var mocks = require('./links/mocks.js'); | ||
var inflight = require('./links/inflight.js'); | ||
var _apolloLink = require("apollo-link"); | ||
var _apolloCacheInmemory = require("apollo-cache-inmemory"); | ||
var _client = require("./client.js"); | ||
var _index = require("./links/index.js"); | ||
var _operations = require("./operations.js"); | ||
var _utilities = require("./utilities.js"); | ||
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); }); }; } | ||
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
var GraphQL = /*#__PURE__*/function () { | ||
function GraphQL(mock) { | ||
var _this = this; | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref$unionOrIntersect = _ref.unionOrIntersectionTypes, | ||
unionOrIntersectionTypes = _ref$unionOrIntersect === void 0 ? [] : _ref$unionOrIntersect, | ||
_ref$cacheOptions = _ref.cacheOptions, | ||
cacheOptions = _ref$cacheOptions === void 0 ? {} : _ref$cacheOptions; | ||
_classCallCheck(this, GraphQL); | ||
class GraphQL { | ||
constructor(mock, { | ||
unionOrIntersectionTypes = [], | ||
cacheOptions = {} | ||
} = {}) { | ||
this.client = void 0; | ||
this.operations = new _operations.Operations(); | ||
this.operations = new operations.Operations(); | ||
this.pendingRequests = new Set(); | ||
@@ -58,14 +25,13 @@ this.wrappers = []; | ||
this.handleCreate = function (request) { | ||
_this.pendingRequests.add(request); | ||
this.handleCreate = request => { | ||
this.pendingRequests.add(request); | ||
}; | ||
this.handleResolve = function (request) { | ||
_this.operations.push(request.operation); | ||
_this.pendingRequests["delete"](request); | ||
this.handleResolve = request => { | ||
this.operations.push(request.operation); | ||
this.pendingRequests.delete(request); | ||
}; | ||
var cache = new _apolloCacheInmemory.InMemoryCache(_objectSpread({ | ||
fragmentMatcher: new _apolloCacheInmemory.IntrospectionFragmentMatcher({ | ||
const cache = new apolloCacheInmemory.InMemoryCache(_rollupPluginBabelHelpers.objectSpread2({ | ||
fragmentMatcher: new apolloCacheInmemory.IntrospectionFragmentMatcher({ | ||
introspectionQueryResultData: { | ||
@@ -78,98 +44,54 @@ __schema: { | ||
}, cacheOptions)); | ||
this.mockLink = new _index.MockLink(mock || defaultGraphQLMock); | ||
var link = _apolloLink.ApolloLink.from([new _index.InflightLink({ | ||
this.mockLink = new mocks.MockLink(mock || defaultGraphQLMock); | ||
const link = apolloLink.ApolloLink.from([new inflight.InflightLink({ | ||
onCreated: this.handleCreate, | ||
onResolved: this.handleResolve | ||
}), this.mockLink]); | ||
this.client = new _client.TestingApolloClient({ | ||
link: link, | ||
cache: cache | ||
this.client = new client.TestingApolloClient({ | ||
link, | ||
cache | ||
}); | ||
} | ||
_createClass(GraphQL, [{ | ||
key: "update", | ||
value: function update(mock) { | ||
if (!this.mockLink) { | ||
return; | ||
} | ||
this.mockLink.updateMock(mock); | ||
update(mock) { | ||
if (!this.mockLink) { | ||
return; | ||
} | ||
}, { | ||
key: "resolveAll", | ||
value: function () { | ||
var _resolveAll = _asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee2() { | ||
var _this2 = this; | ||
var options, | ||
finalOperationName, | ||
_args2 = arguments; | ||
return _regenerator["default"].wrap(function _callee2$(_context2) { | ||
while (1) { | ||
switch (_context2.prev = _context2.next) { | ||
case 0: | ||
options = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}; | ||
finalOperationName = (0, _utilities.operationNameFromFindOptions)(options); | ||
_context2.next = 4; | ||
return this.wrappers.reduce(function (perform, wrapper) { | ||
return function () { | ||
return wrapper(perform); | ||
}; | ||
}, /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee() { | ||
var allPendingRequests, matchingRequests; | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
allPendingRequests = Array.from(_this2.pendingRequests); | ||
matchingRequests = finalOperationName ? allPendingRequests.filter(function (_ref3) { | ||
var operationName = _ref3.operation.operationName; | ||
return operationName === finalOperationName; | ||
}) : allPendingRequests; | ||
_context.next = 4; | ||
return Promise.all(matchingRequests.map(function (_ref4) { | ||
var resolve = _ref4.resolve; | ||
return resolve(); | ||
})); | ||
this.mockLink.updateMock(mock); | ||
} | ||
case 4: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})))(); | ||
resolveAll(options = {}) { | ||
var _this = this; | ||
case 4: | ||
case "end": | ||
return _context2.stop(); | ||
} | ||
return _rollupPluginBabelHelpers.asyncToGenerator(function* () { | ||
const finalOperationName = utilities.operationNameFromFindOptions(options); | ||
yield _this.wrappers.reduce((perform, wrapper) => { | ||
return () => wrapper(perform); | ||
}, /*#__PURE__*/_rollupPluginBabelHelpers.asyncToGenerator(function* () { | ||
const allPendingRequests = Array.from(_this.pendingRequests); | ||
const matchingRequests = finalOperationName ? allPendingRequests.filter(({ | ||
operation: { | ||
operationName | ||
} | ||
}, _callee2, this); | ||
})); | ||
}) => operationName === finalOperationName) : allPendingRequests; | ||
yield Promise.all(matchingRequests.map(({ | ||
resolve | ||
}) => resolve())); | ||
}))(); | ||
})(); | ||
} | ||
function resolveAll() { | ||
return _resolveAll.apply(this, arguments); | ||
} | ||
wrap(wrapper) { | ||
this.wrappers.push(wrapper); | ||
} | ||
return resolveAll; | ||
}() | ||
}, { | ||
key: "wrap", | ||
value: function wrap(wrapper) { | ||
this.wrappers.push(wrapper); | ||
} | ||
}]); | ||
} | ||
return GraphQL; | ||
}(); | ||
function defaultGraphQLMock({ | ||
operationName | ||
}) { | ||
return new Error(`Can’t perform GraphQL operation '${operationName || ''}' because no mocks were set.`); | ||
} | ||
exports.GraphQL = GraphQL; | ||
function defaultGraphQLMock(_ref5) { | ||
var operationName = _ref5.operationName; | ||
return new Error("Can\u2019t perform GraphQL operation '".concat(operationName || '', "' because no mocks were set.")); | ||
} |
@@ -1,44 +0,11 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var _graphqlController = require("./graphql-controller.js"); | ||
var graphqlController = require('./graphql-controller.js'); | ||
var factory = require('./factory.js'); | ||
Object.keys(_graphqlController).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (key in exports && exports[key] === _graphqlController[key]) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _graphqlController[key]; | ||
} | ||
}); | ||
}); | ||
var _factory = require("./factory.js"); | ||
Object.keys(_factory).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (key in exports && exports[key] === _factory[key]) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _factory[key]; | ||
} | ||
}); | ||
}); | ||
var _types = require("./types.js"); | ||
Object.keys(_types).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (key in exports && exports[key] === _types[key]) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _types[key]; | ||
} | ||
}); | ||
}); | ||
exports.GraphQL = graphqlController.GraphQL; | ||
exports.createGraphQLFactory = factory.createGraphQLFactory; |
@@ -1,93 +0,54 @@ | ||
"use strict"; | ||
'use strict'; | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.InflightLink = void 0; | ||
var apolloLink = require('apollo-link'); | ||
var _apolloLink = require("apollo-link"); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
var InflightLink = /*#__PURE__*/function (_ApolloLink) { | ||
_inherits(InflightLink, _ApolloLink); | ||
var _super = _createSuper(InflightLink); | ||
function InflightLink(options) { | ||
var _this; | ||
_classCallCheck(this, InflightLink); | ||
_this = _super.call(this); | ||
_this.options = options; | ||
return _this; | ||
class InflightLink extends apolloLink.ApolloLink { | ||
constructor(options) { | ||
super(); | ||
this.options = options; | ||
} | ||
_createClass(InflightLink, [{ | ||
key: "request", | ||
value: function request(operation, nextLink) { | ||
var _this2 = this; | ||
request(operation, nextLink) { | ||
if (nextLink == null || !nextLink) { | ||
throw new Error('The memory link must not be a terminating link'); | ||
} | ||
if (nextLink == null || !nextLink) { | ||
throw new Error('The memory link must not be a terminating link'); | ||
let resolver; | ||
const promise = new Promise(resolve => { | ||
resolver = resolve; | ||
}); | ||
const request = { | ||
operation, | ||
resolve: () => { | ||
resolver(); | ||
this.options.onResolved(request); | ||
return promise; | ||
} | ||
}; | ||
this.options.onCreated(request); | ||
return new apolloLink.Observable(observer => { | ||
return nextLink(operation).subscribe({ | ||
complete() { | ||
const complete = observer.complete.bind(observer); | ||
promise.then(complete).catch(complete); | ||
}, | ||
var resolver; | ||
var promise = new Promise(function (resolve) { | ||
resolver = resolve; | ||
}); | ||
var request = { | ||
operation: operation, | ||
resolve: function resolve() { | ||
resolver(); | ||
next(result) { | ||
const next = observer.next.bind(observer, result); | ||
promise.then(next).catch(next); | ||
}, | ||
_this2.options.onResolved(request); | ||
error(error) { | ||
const fail = observer.error.bind(observer, error); | ||
promise.then(fail).catch(fail); | ||
} | ||
return promise; | ||
} | ||
}; | ||
this.options.onCreated(request); | ||
return new _apolloLink.Observable(function (observer) { | ||
return nextLink(operation).subscribe({ | ||
complete: function complete() { | ||
var complete = observer.complete.bind(observer); | ||
promise.then(complete)["catch"](complete); | ||
}, | ||
next: function next(result) { | ||
var next = observer.next.bind(observer, result); | ||
promise.then(next)["catch"](next); | ||
}, | ||
error: function error(_error) { | ||
var fail = observer.error.bind(observer, _error); | ||
promise.then(fail)["catch"](fail); | ||
} | ||
}); | ||
}); | ||
} | ||
}]); | ||
}); | ||
} | ||
return InflightLink; | ||
}(_apolloLink.ApolloLink); | ||
} | ||
exports.InflightLink = InflightLink; | ||
exports.InflightLink = InflightLink; |
@@ -1,114 +0,73 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.MockLink = void 0; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var _apolloLink = require("apollo-link"); | ||
var apolloLink = require('apollo-link'); | ||
var graphql = require('graphql'); | ||
var _graphql = require("graphql"); | ||
class MockLink extends apolloLink.ApolloLink { | ||
constructor(mock) { | ||
super(); | ||
this.mock = mock; | ||
} | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
updateMock(mock) { | ||
this.mock = mock; | ||
} | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
request(operation) { | ||
return new apolloLink.Observable(obs => { | ||
const { | ||
mock | ||
} = this; | ||
const { | ||
operationName = '' | ||
} = operation; | ||
let response = null; | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
if (typeof mock === 'function') { | ||
response = mock(operation); | ||
} else { | ||
const mockForOperation = mock[operationName || '']; | ||
response = typeof mockForOperation === 'function' ? mockForOperation(operation) : mockForOperation; | ||
} | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
let result; | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
if (response == null) { | ||
let message = `Can’t perform GraphQL operation '${operationName}' because no valid mocks were found`; | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
if (typeof mock === 'object') { | ||
const operationNames = Object.keys(mock); // We will provide a more helpful message when it looks like they just provided data, | ||
// not an object mapping names to fixtures. | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
var MockLink = /*#__PURE__*/function (_ApolloLink) { | ||
_inherits(MockLink, _ApolloLink); | ||
var _super = _createSuper(MockLink); | ||
function MockLink(mock) { | ||
var _this; | ||
_classCallCheck(this, MockLink); | ||
_this = _super.call(this); | ||
_this.mock = mock; | ||
return _this; | ||
} | ||
_createClass(MockLink, [{ | ||
key: "updateMock", | ||
value: function updateMock(mock) { | ||
this.mock = mock; | ||
} | ||
}, { | ||
key: "request", | ||
value: function request(operation) { | ||
var _this2 = this; | ||
return new _apolloLink.Observable(function (obs) { | ||
var mock = _this2.mock; | ||
var _operation$operationN = operation.operationName, | ||
operationName = _operation$operationN === void 0 ? '' : _operation$operationN; | ||
var response = null; | ||
if (typeof mock === 'function') { | ||
response = mock(operation); | ||
const looksLikeDataNotFixtures = operationNames.every(name => name === name.toLowerCase()); | ||
message += looksLikeDataNotFixtures ? ` (it looks like you tried to provide data directly to the mock GraphQL client. You need to provide your fixture on the key that matches its operation name. To fix this, simply change your code to read 'mockGraphQLClient({${operationName}: yourFixture}).'` : ` (you provided an object that had mocks only for the following operations: ${Object.keys(mock).join(', ')}).`; | ||
} else { | ||
var mockForOperation = mock[operationName || '']; | ||
response = typeof mockForOperation === 'function' ? mockForOperation(operation) : mockForOperation; | ||
message += ' (you provided a function that did not return a valid mock result)'; | ||
} | ||
var result; | ||
const error = new Error(message); | ||
result = error; | ||
} else if (response instanceof graphql.GraphQLError) { | ||
result = { | ||
errors: [response] | ||
}; | ||
} else if (response instanceof Error) { | ||
result = { | ||
errors: [new graphql.GraphQLError(response.message)] | ||
}; | ||
} else { | ||
result = { | ||
data: response | ||
}; | ||
} | ||
if (response == null) { | ||
var message = "Can\u2019t perform GraphQL operation '".concat(operationName, "' because no valid mocks were found"); | ||
obs.next(result); | ||
obs.complete(); | ||
}); | ||
} | ||
if (_typeof(mock) === 'object') { | ||
var operationNames = Object.keys(mock); // We will provide a more helpful message when it looks like they just provided data, | ||
// not an object mapping names to fixtures. | ||
} | ||
var looksLikeDataNotFixtures = operationNames.every(function (name) { | ||
return name === name.toLowerCase(); | ||
}); | ||
message += looksLikeDataNotFixtures ? " (it looks like you tried to provide data directly to the mock GraphQL client. You need to provide your fixture on the key that matches its operation name. To fix this, simply change your code to read 'mockGraphQLClient({".concat(operationName, ": yourFixture}).'") : " (you provided an object that had mocks only for the following operations: ".concat(Object.keys(mock).join(', '), ")."); | ||
} else { | ||
message += ' (you provided a function that did not return a valid mock result)'; | ||
} | ||
var error = new Error(message); | ||
result = error; | ||
} else if (response instanceof _graphql.GraphQLError) { | ||
result = { | ||
errors: [response] | ||
}; | ||
} else if (response instanceof Error) { | ||
result = { | ||
errors: [new _graphql.GraphQLError(response.message)] | ||
}; | ||
} else { | ||
result = { | ||
data: response | ||
}; | ||
} | ||
obs.next(result); | ||
obs.complete(); | ||
}); | ||
} | ||
}]); | ||
return MockLink; | ||
}(_apolloLink.ApolloLink); | ||
exports.MockLink = MockLink; | ||
exports.MockLink = MockLink; |
@@ -1,7 +0,7 @@ | ||
"use strict"; | ||
'use strict'; | ||
var _operations = require("./operations.js"); | ||
var operations = require('./operations.js'); | ||
expect.extend({ | ||
toHavePerformedGraphQLOperation: _operations.toHavePerformedGraphQLOperation | ||
}); | ||
toHavePerformedGraphQLOperation: operations.toHavePerformedGraphQLOperation | ||
}); |
@@ -1,40 +0,25 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.toHavePerformedGraphQLOperation = toHavePerformedGraphQLOperation; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var _jestMatcherUtils = require("jest-matcher-utils"); | ||
var jestMatcherUtils = require('jest-matcher-utils'); | ||
var utilities$1 = require('../utilities.js'); | ||
var utilities = require('./utilities.js'); | ||
var _utilities = require("../utilities.js"); | ||
var _utilities2 = require("./utilities.js"); | ||
function toHavePerformedGraphQLOperation(graphQL, document, variables) { | ||
var _this = this; | ||
(0, _utilities2.assertIsGraphQL)(graphQL, { | ||
utilities.assertIsGraphQL(graphQL, { | ||
expectation: 'toHavePerformedGraphQLOperation', | ||
isNot: this.isNot | ||
}); | ||
var foundByOperation = graphQL.operations.all({ | ||
const foundByOperation = graphQL.operations.all({ | ||
query: document | ||
}); | ||
var foundByVariables = variables == null ? foundByOperation : foundByOperation.filter(function (operation) { | ||
return Object.keys(variables).every(function (key) { | ||
return _this.equals(variables[key], operation.variables[key]); | ||
}); | ||
}); | ||
var pass = foundByVariables.length > 0; | ||
var type = (0, _utilities.operationTypeFromDocument)(document) || 'query'; | ||
var name = (0, _utilities.operationNameFromDocument)(document) || 'unnamed'; | ||
var message = pass ? function () { | ||
return "".concat((0, _jestMatcherUtils.matcherHint)('.not.toHavePerformedGraphQLOperation'), "\n\n") + "Expected not to have performed GraphQL ".concat(type, ":\n ").concat((0, _jestMatcherUtils.EXPECTED_COLOR)(name), "\n").concat(variables ? "With variables matching:\n ".concat((0, _jestMatcherUtils.printExpected)(variables), "\n") : '') + "But ".concat(foundByVariables.length, " matching ").concat(foundByVariables.length === 1 ? 'operation was' : 'operations were', " found.\n"); | ||
} : function () { | ||
return "".concat("".concat((0, _jestMatcherUtils.matcherHint)('.toHavePerformedGraphQLOperation'), "\n\n") + "Expected to have performed GraphQL ".concat(type, ":\n ").concat((0, _jestMatcherUtils.EXPECTED_COLOR)(name), "\n").concat(variables ? "With props matching:\n ".concat((0, _jestMatcherUtils.printExpected)(variables), "\n") : '')).concat(foundByVariables.length === 0 ? "But no matching operations were found.\n" : "But the ".concat(foundByVariables.length === 1 ? 'found operation has' : 'found operations have', " the following variable differences:\n\n").concat(diffs(foundByVariables, variables, _this.expand))); | ||
}; | ||
const foundByVariables = variables == null ? foundByOperation : foundByOperation.filter(operation => Object.keys(variables).every(key => this.equals(variables[key], operation.variables[key]))); | ||
const pass = foundByVariables.length > 0; | ||
const type = utilities$1.operationTypeFromDocument(document) || 'query'; | ||
const name = utilities$1.operationNameFromDocument(document) || 'unnamed'; | ||
const message = pass ? () => `${jestMatcherUtils.matcherHint('.not.toHavePerformedGraphQLOperation')}\n\n` + `Expected not to have performed GraphQL ${type}:\n ${jestMatcherUtils.EXPECTED_COLOR(name)}\n${variables ? `With variables matching:\n ${jestMatcherUtils.printExpected(variables)}\n` : ''}` + `But ${foundByVariables.length} matching ${foundByVariables.length === 1 ? 'operation was' : 'operations were'} found.\n` : () => `${`${jestMatcherUtils.matcherHint('.toHavePerformedGraphQLOperation')}\n\n` + `Expected to have performed GraphQL ${type}:\n ${jestMatcherUtils.EXPECTED_COLOR(name)}\n${variables ? `With props matching:\n ${jestMatcherUtils.printExpected(variables)}\n` : ''}`}${foundByVariables.length === 0 ? `But no matching operations were found.\n` : `But the ${foundByVariables.length === 1 ? 'found operation has' : 'found operations have'} the following variable differences:\n\n${diffs(foundByVariables, variables, this.expand)}`}`; | ||
return { | ||
pass: pass, | ||
message: message | ||
pass, | ||
message | ||
}; | ||
@@ -44,19 +29,18 @@ } | ||
function diffs(operations, variables, expand) { | ||
return operations.reduce(function (diffs, operation, index) { | ||
return "".concat(diffs).concat(index === 0 ? '' : '\n\n').concat(normalizedDiff(operation, variables, { | ||
expand: expand, | ||
showLegend: index === 0 | ||
})); | ||
}, ''); | ||
return operations.reduce((diffs, operation, index) => `${diffs}${index === 0 ? '' : '\n\n'}${normalizedDiff(operation, variables, { | ||
expand, | ||
showLegend: index === 0 | ||
})}`, ''); | ||
} | ||
function normalizedDiff(operation, variables, _ref) { | ||
var _ref$expand = _ref.expand, | ||
expand = _ref$expand === void 0 ? false : _ref$expand, | ||
_ref$showLegend = _ref.showLegend, | ||
showLegend = _ref$showLegend === void 0 ? false : _ref$showLegend; | ||
var result = (0, _utilities2.diffVariablesForOperation)(operation, variables, { | ||
expand: expand | ||
function normalizedDiff(operation, variables, { | ||
expand = false, | ||
showLegend = false | ||
}) { | ||
const result = utilities.diffVariablesForOperation(operation, variables, { | ||
expand | ||
}) || ''; | ||
return showLegend ? result : result.split('\n\n')[1]; | ||
} | ||
} | ||
exports.toHavePerformedGraphQLOperation = toHavePerformedGraphQLOperation; |
@@ -1,51 +0,36 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.assertIsGraphQL = assertIsGraphQL; | ||
exports.diffVariablesForOperation = diffVariablesForOperation; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var _jestMatcherUtils = require("jest-matcher-utils"); | ||
var jestMatcherUtils = require('jest-matcher-utils'); | ||
var graphqlController = require('../graphql-controller.js'); | ||
var _graphqlController = require("../graphql-controller.js"); | ||
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function assertIsGraphQL(graphQL, _ref) { | ||
var expectation = _ref.expectation, | ||
isNot = _ref.isNot; | ||
if (!(graphQL instanceof _graphqlController.GraphQL)) { | ||
throw new Error((0, _jestMatcherUtils.matcherErrorMessage)((0, _jestMatcherUtils.matcherHint)(".".concat(expectation), undefined, undefined, { | ||
isNot: isNot | ||
}), "".concat((0, _jestMatcherUtils.RECEIVED_COLOR)('received'), " value must be a @shopify/graphql-testing GraphQL object"), (0, _jestMatcherUtils.printWithType)('Received', graphQL, _jestMatcherUtils.printReceived))); | ||
function assertIsGraphQL(graphQL, { | ||
expectation, | ||
isNot | ||
}) { | ||
if (!(graphQL instanceof graphqlController.GraphQL)) { | ||
throw new Error(jestMatcherUtils.matcherErrorMessage(jestMatcherUtils.matcherHint(`.${expectation}`, undefined, undefined, { | ||
isNot | ||
}), `${jestMatcherUtils.RECEIVED_COLOR('received')} value must be a @shopify/graphql-testing GraphQL object`, jestMatcherUtils.printWithType('Received', graphQL, jestMatcherUtils.printReceived))); | ||
} | ||
} | ||
function diffVariablesForOperation(operation, variables, _ref2) { | ||
var _ref2$expand = _ref2.expand, | ||
expand = _ref2$expand === void 0 ? false : _ref2$expand; | ||
return (0, _jestMatcherUtils.diff)(variables, getObjectSubset(operation.variables, variables), { | ||
expand: expand | ||
function diffVariablesForOperation(operation, variables, { | ||
expand = false | ||
}) { | ||
return jestMatcherUtils.diff(variables, getObjectSubset(operation.variables, variables), { | ||
expand | ||
}); | ||
} // Original from https://github.com/facebook/jest/blob/master/packages/expect/src/utils.ts#L107 | ||
function getObjectSubset(object, subset) { | ||
if (Array.isArray(object)) { | ||
if (Array.isArray(subset) && subset.length === object.length) { | ||
return subset.map(function (sub, i) { | ||
return getObjectSubset(object[i], sub); | ||
}); | ||
return subset.map((sub, i) => getObjectSubset(object[i], sub)); | ||
} | ||
} else if (object instanceof Date) { | ||
return object; | ||
} else if (_typeof(object) === 'object' && object !== null && _typeof(subset) === 'object' && subset !== null) { | ||
var trimmed = {}; | ||
Object.keys(subset).filter(function (key) { | ||
return Reflect.has(object, key); | ||
}).forEach(function (key) { | ||
return trimmed[key] = getObjectSubset(object[key], subset[key]); | ||
}); | ||
} else if (typeof object === 'object' && object !== null && typeof subset === 'object' && subset !== null) { | ||
const trimmed = {}; | ||
Object.keys(subset).filter(key => Reflect.has(object, key)).forEach(key => trimmed[key] = getObjectSubset(object[key], subset[key])); | ||
@@ -58,2 +43,5 @@ if (Object.keys(trimmed).length > 0) { | ||
return object; | ||
} | ||
} | ||
exports.assertIsGraphQL = assertIsGraphQL; | ||
exports.diffVariablesForOperation = diffVariablesForOperation; |
@@ -1,88 +0,49 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.Operations = void 0; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var _utilities = require("./utilities.js"); | ||
var utilities = require('./utilities.js'); | ||
var _Symbol$iterator; | ||
let _Symbol$iterator; | ||
_Symbol$iterator = Symbol.iterator; | ||
class Operations { | ||
constructor(operations) { | ||
this.operations = []; | ||
this.operations = operations ? [...operations] : []; | ||
} | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
[_Symbol$iterator]() { | ||
return this.operations[Symbol.iterator](); | ||
} | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
push(...operations) { | ||
this.operations.push(...operations); | ||
} | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
all(options) { | ||
return this.filterWhere(options); | ||
} | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); } | ||
first(options) { | ||
return this.nth(0, options); | ||
} | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
last(options) { | ||
return this.nth(-1, options); | ||
} | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
nth(index, options) { | ||
const found = this.filterWhere(options); | ||
return index < 0 ? found[found.length + index] : found[index]; | ||
} | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
_Symbol$iterator = Symbol.iterator; | ||
var Operations = /*#__PURE__*/function () { | ||
function Operations(operations) { | ||
_classCallCheck(this, Operations); | ||
this.operations = []; | ||
this.operations = operations ? _toConsumableArray(operations) : []; | ||
filterWhere(options = {}) { | ||
const finalOperationName = utilities.operationNameFromFindOptions(options); | ||
return finalOperationName ? this.operations.filter(({ | ||
operationName | ||
}) => operationName === finalOperationName) : this.operations; | ||
} | ||
_createClass(Operations, [{ | ||
key: _Symbol$iterator, | ||
value: function value() { | ||
return this.operations[Symbol.iterator](); | ||
} | ||
}, { | ||
key: "push", | ||
value: function push() { | ||
var _this$operations; | ||
} | ||
(_this$operations = this.operations).push.apply(_this$operations, arguments); | ||
} | ||
}, { | ||
key: "all", | ||
value: function all(options) { | ||
return this.filterWhere(options); | ||
} | ||
}, { | ||
key: "first", | ||
value: function first(options) { | ||
return this.nth(0, options); | ||
} | ||
}, { | ||
key: "last", | ||
value: function last(options) { | ||
return this.nth(-1, options); | ||
} | ||
}, { | ||
key: "nth", | ||
value: function nth(index, options) { | ||
var found = this.filterWhere(options); | ||
return index < 0 ? found[found.length + index] : found[index]; | ||
} | ||
}, { | ||
key: "filterWhere", | ||
value: function filterWhere() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var finalOperationName = (0, _utilities.operationNameFromFindOptions)(options); | ||
return finalOperationName ? this.operations.filter(function (_ref) { | ||
var operationName = _ref.operationName; | ||
return operationName === finalOperationName; | ||
}) : this.operations; | ||
} | ||
}]); | ||
return Operations; | ||
}(); | ||
exports.Operations = Operations; | ||
exports.Operations = Operations; |
@@ -1,28 +0,12 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.operationNameFromFindOptions = operationNameFromFindOptions; | ||
exports.operationNameFromDocument = operationNameFromDocument; | ||
exports.operationTypeFromDocument = operationTypeFromDocument; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function operationNameFromFindOptions({ | ||
query, | ||
mutation, | ||
operationName | ||
}) { | ||
const passedOptions = [query, mutation, operationName].filter(Boolean); | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) return; var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function operationNameFromFindOptions(_ref) { | ||
var query = _ref.query, | ||
mutation = _ref.mutation, | ||
operationName = _ref.operationName; | ||
var passedOptions = [query, mutation, operationName].filter(Boolean); | ||
if (passedOptions.length === 0) { | ||
@@ -36,7 +20,5 @@ return undefined; | ||
} | ||
function operationNameFromDocument(document) { | ||
return 'resolver' in document && document.resolver.resolved != null ? operationNameFromDocumentNode(document.resolver.resolved) : operationNameFromDocumentNode(document); | ||
} | ||
function operationTypeFromDocument(document) { | ||
@@ -47,9 +29,5 @@ return 'resolver' in document && document.resolver.resolved != null ? operationTypeFromDocumentNode(document.resolver.resolved) : operationTypeFromDocumentNode(document); | ||
function operationNameFromDocumentNode(document) { | ||
var _ref2 = document.definitions.filter(function (_ref4) { | ||
var kind = _ref4.kind; | ||
return kind === 'OperationDefinition'; | ||
}), | ||
_ref3 = _slicedToArray(_ref2, 1), | ||
operation = _ref3[0]; | ||
const [operation] = document.definitions.filter(({ | ||
kind | ||
}) => kind === 'OperationDefinition'); | ||
return operation && operation.name && operation.name.value; | ||
@@ -59,10 +37,10 @@ } | ||
function operationTypeFromDocumentNode(document) { | ||
var _ref5 = document.definitions.filter(function (_ref7) { | ||
var kind = _ref7.kind; | ||
return kind === 'OperationDefinition'; | ||
}), | ||
_ref6 = _slicedToArray(_ref5, 1), | ||
operation = _ref6[0]; | ||
const [operation] = document.definitions.filter(({ | ||
kind | ||
}) => kind === 'OperationDefinition'); | ||
return operation && operation.operation; | ||
} | ||
return operation && operation.operation; | ||
} | ||
exports.operationNameFromDocument = operationNameFromDocument; | ||
exports.operationNameFromFindOptions = operationNameFromFindOptions; | ||
exports.operationTypeFromDocument = operationTypeFromDocument; |
@@ -10,2 +10,8 @@ # Changelog | ||
## 5.0.0 - 2021-05-21 | ||
### Breaking Change | ||
- Update minimum supported node version to 12.14.0. Add engines field to help enforce usage of this version. [#1906](https://github.com/Shopify/quilt/pull/1906) | ||
## 4.4.4 - 2021-04-13 | ||
@@ -12,0 +18,0 @@ |
{ | ||
"name": "@shopify/graphql-testing", | ||
"version": "4.4.7", | ||
"version": "5.0.0", | ||
"license": "MIT", | ||
@@ -23,2 +23,5 @@ "description": "Utilities to create mock GraphQL factories", | ||
"homepage": "https://github.com/Shopify/quilt/blob/main/packages/graphql-testing/README.md", | ||
"engines": { | ||
"node": ">=12.14.0" | ||
}, | ||
"dependencies": { | ||
@@ -32,4 +35,4 @@ "apollo-cache-inmemory": ">=1.0.0 <2.0.0", | ||
"devDependencies": { | ||
"@shopify/useful-types": "^2.4.2", | ||
"graphql-typed": "^0.7.2" | ||
"@shopify/useful-types": "^3.0.0", | ||
"graphql-typed": "^1.0.0" | ||
}, | ||
@@ -63,3 +66,3 @@ "files": [ | ||
}, | ||
"gitHead": "4324f27f72ae7b1800ec6bde9087af4ed89b3833" | ||
"gitHead": "40de4af181104f298cbab42d2d3d68e228a9a31a" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
86643
86
1388