@shopify/graphql-testing
Advanced tools
Comparing version 2.0.3 to 3.0.0
@@ -10,4 +10,11 @@ # Changelog | ||
### Added | ||
## [3.0.0] - 2019-04-01 | ||
- `@shopify/graphql-testing` package - next generation of `jest-mock-apollo` with rename of the package | ||
### Changed | ||
- `createGraphQLFactory` is now a named export, not the default export ([#623](https://github.com/Shopify/quilt/pull/623/)) | ||
- Simplified much of the external workings of the library, including removing the custom subclass of `ApolloClient` ([#623](https://github.com/Shopify/quilt/pull/623/)) | ||
## [1.0.0] | ||
Initial release. |
@@ -0,4 +1,6 @@ | ||
/// <reference types="node" /> | ||
import { ApolloReducerConfig } from 'apollo-cache-inmemory'; | ||
import MemoryApolloClient from './MemoryApolloClient'; | ||
import Operations from './Operations'; | ||
import { ApolloClient } from 'apollo-client'; | ||
import { EventEmitter } from 'events'; | ||
import { Operations } from './utilities'; | ||
import { GraphQLMock } from './types'; | ||
@@ -9,11 +11,13 @@ export interface Options { | ||
} | ||
declare class GraphQL { | ||
client: MemoryApolloClient; | ||
export declare class GraphQL extends EventEmitter { | ||
readonly client: ApolloClient<unknown>; | ||
readonly operations: Operations; | ||
private afterResolver; | ||
private pendingRequests; | ||
constructor(mock: GraphQLMock, { unionOrIntersectionTypes, cacheOptions }?: Options); | ||
afterResolve(resolver: () => void): void; | ||
on(event: 'pre-resolve', handler: () => void): this; | ||
on(event: 'post-resolve', handler: () => void): this; | ||
resolveAll(): Promise<void>; | ||
private handleCreate; | ||
private handleResolve; | ||
} | ||
export default function createGraphQLFactory(options?: Options): (mock?: GraphQLMock) => GraphQL; | ||
export {}; | ||
export declare function createGraphQLFactory(options?: Options): (mock?: GraphQLMock) => GraphQL; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var tslib_1 = require("tslib"); | ||
var apollo_link_1 = require("apollo-link"); | ||
var apollo_cache_inmemory_1 = require("apollo-cache-inmemory"); | ||
var MemoryApolloClient_1 = tslib_1.__importDefault(require("./MemoryApolloClient")); | ||
var MockApolloLink_1 = tslib_1.__importDefault(require("./MockApolloLink")); | ||
function defaultGraphQLMock(_a) { | ||
var operationName = _a.operationName; | ||
return new Error("Can\u2019t perform GraphQL operation '" + (operationName || | ||
'') + "' because no mocks were set."); | ||
} | ||
var GraphQL = /** @class */ (function () { | ||
var apollo_client_1 = require("apollo-client"); | ||
var events_1 = require("events"); | ||
var links_1 = require("./links"); | ||
var utilities_1 = require("./utilities"); | ||
var GraphQL = /** @class */ (function (_super) { | ||
tslib_1.__extends(GraphQL, _super); | ||
function GraphQL(mock, _a) { | ||
var _b = _a === void 0 ? {} : _a, _c = _b.unionOrIntersectionTypes, unionOrIntersectionTypes = _c === void 0 ? [] : _c, _d = _b.cacheOptions, cacheOptions = _d === void 0 ? {} : _d; | ||
var _this = _super.call(this) || this; | ||
_this.operations = new utilities_1.Operations(); | ||
_this.pendingRequests = new Set(); | ||
_this.handleCreate = function (request) { | ||
_this.pendingRequests.add(request); | ||
}; | ||
_this.handleResolve = function (request) { | ||
_this.operations.push(request.operation); | ||
_this.pendingRequests.delete(request); | ||
}; | ||
var cache = new apollo_cache_inmemory_1.InMemoryCache(tslib_1.__assign({ fragmentMatcher: new apollo_cache_inmemory_1.IntrospectionFragmentMatcher({ | ||
@@ -22,23 +31,33 @@ introspectionQueryResultData: { | ||
}) }, cacheOptions)); | ||
var mockApolloClientOptions = { | ||
link: new MockApolloLink_1.default(mock), | ||
var link = apollo_link_1.ApolloLink.from([ | ||
new links_1.InflightLink({ | ||
onCreated: _this.handleCreate, | ||
onResolved: _this.handleResolve, | ||
}), | ||
new links_1.MockLink(mock), | ||
]); | ||
_this.client = new apollo_client_1.ApolloClient({ | ||
link: link, | ||
cache: cache, | ||
}; | ||
var memoryApolloClient = new MemoryApolloClient_1.default(mockApolloClientOptions); | ||
this.client = memoryApolloClient; | ||
this.operations = memoryApolloClient.operations; | ||
}); | ||
return _this; | ||
} | ||
GraphQL.prototype.afterResolve = function (resolver) { | ||
this.afterResolver = resolver; | ||
GraphQL.prototype.on = function (event, handler) { | ||
return _super.prototype.on.call(this, event, handler); | ||
}; | ||
GraphQL.prototype.resolveAll = function () { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var promise; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: return [4 /*yield*/, this.client.resolveAll()]; | ||
case 0: | ||
promise = Promise.all(Array.from(this.pendingRequests).map(function (_a) { | ||
var resolve = _a.resolve; | ||
return resolve(); | ||
})); | ||
this.emit('pre-resolve'); | ||
return [4 /*yield*/, promise]; | ||
case 1: | ||
_a.sent(); | ||
if (this.afterResolver) { | ||
this.afterResolver(); | ||
} | ||
this.emit('post-resolve'); | ||
return [2 /*return*/]; | ||
@@ -50,5 +69,11 @@ } | ||
return GraphQL; | ||
}()); | ||
}(events_1.EventEmitter)); | ||
exports.GraphQL = GraphQL; | ||
function defaultGraphQLMock(_a) { | ||
var operationName = _a.operationName; | ||
return new Error("Can\u2019t perform GraphQL operation '" + (operationName || | ||
'') + "' because no mocks were set."); | ||
} | ||
function createGraphQLFactory(options) { | ||
return function createGraphQLClient(mock) { | ||
return function createGraphQL(mock) { | ||
if (mock === void 0) { mock = defaultGraphQLMock; } | ||
@@ -58,2 +83,2 @@ return new GraphQL(mock, options); | ||
} | ||
exports.default = createGraphQLFactory; | ||
exports.createGraphQLFactory = createGraphQLFactory; |
@@ -1,2 +0,2 @@ | ||
export { default } from './createGraphQLFactory'; | ||
export * from './createGraphQLFactory'; | ||
export * from './types'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var createGraphQLFactory_1 = require("./createGraphQLFactory"); | ||
exports.default = createGraphQLFactory_1.default; | ||
var tslib_1 = require("tslib"); | ||
tslib_1.__exportStar(require("./createGraphQLFactory"), exports); |
{ | ||
"name": "@shopify/graphql-testing", | ||
"version": "2.0.3", | ||
"version": "3.0.0", | ||
"license": "MIT", | ||
@@ -5,0 +5,0 @@ "description": "Utilities to create mock graphql factory.", |
@@ -61,3 +61,3 @@ # `@shopify/graphql-testing` | ||
import {ApolloProvider} from 'react-apollo'; | ||
import createGraphQLFactory from '@shopify/graphql-testing'; | ||
import {createGraphQLFactory} from '@shopify/graphql-testing'; | ||
@@ -98,3 +98,3 @@ export const createGraphQL = createGraphQLFactory(); | ||
import {trigger} from '@shopify/enzyme-utilities'; | ||
import createGraphQLFactory from '@shopify/graphql-testing'; | ||
import {createGraphQLFactory} from '@shopify/graphql-testing'; | ||
@@ -101,0 +101,0 @@ export const createGraphQL = createGraphQLFactory(); |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
21081
402
1