@shopify/graphql-testing
Advanced tools
Comparing version 0.0.0-snapshot-20240412140044 to 0.0.0-snapshot-20240531073328
@@ -21,7 +21,5 @@ 'use strict'; | ||
this.mockLink = null; | ||
this.handleCreate = request => { | ||
this.pendingRequests.add(request); | ||
}; | ||
this.handleResolve = request => { | ||
@@ -31,3 +29,2 @@ this.operations.push(request.operation); | ||
}; | ||
const cache = new client.InMemoryCache(cacheOptions); | ||
@@ -46,3 +43,2 @@ this.mockLink = new mocks.MockLink(mock); | ||
} | ||
update(mock) { | ||
@@ -52,6 +48,4 @@ if (!this.mockLink) { | ||
} | ||
this.mockLink.updateMock(mock); | ||
} | ||
async resolveNext(options = {}) { | ||
@@ -64,6 +58,4 @@ await this.withWrapper(async () => { | ||
} | ||
async resolveAll(options = {}) { | ||
await this.resolveNext(options); | ||
while (this.getMatchingRequests(options).length > 0) { | ||
@@ -73,3 +65,2 @@ await this.resolveNext(options); | ||
} | ||
async waitForQueryUpdates() { | ||
@@ -83,7 +74,5 @@ // queryManager is an internal implementation detail that is a TS-private | ||
} | ||
wrap(wrapper) { | ||
this.wrappers.push(wrapper); | ||
} | ||
getMatchingRequests(options) { | ||
@@ -100,3 +89,2 @@ const requestFilter = Object.keys(options).length ? ({ | ||
} | ||
async withWrapper(cb) { | ||
@@ -109,5 +97,4 @@ await this.wrappers.reduce((perform, wrapper) => { | ||
} | ||
} | ||
exports.GraphQL = GraphQL; |
@@ -12,3 +12,2 @@ 'use strict'; | ||
} | ||
request(operation, nextLink) { | ||
@@ -18,3 +17,2 @@ if (nextLink == null || !nextLink) { | ||
} | ||
let resolver; | ||
@@ -39,3 +37,2 @@ const promise = new Promise(resolve => { | ||
}, | ||
next(result) { | ||
@@ -45,3 +42,2 @@ const next = observer.next.bind(observer, result); | ||
}, | ||
error(error) { | ||
@@ -51,9 +47,7 @@ const fail = observer.error.bind(observer, error); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
exports.InflightLink = InflightLink; |
@@ -13,7 +13,5 @@ 'use strict'; | ||
} | ||
updateMock(mock) { | ||
this.mock = mock; | ||
} | ||
request(operation) { | ||
@@ -28,3 +26,2 @@ return new client.Observable(obs => { | ||
let response = null; | ||
if (typeof mock === 'function') { | ||
@@ -36,15 +33,11 @@ response = mock(operation); | ||
} | ||
let result; | ||
if (response == null || typeof response === 'function') { | ||
let message = `Can’t perform GraphQL operation '${operationName}' because no valid mocks were found`; | ||
if (typeof mock === 'object') { | ||
const operationNames = Object.keys(mock); | ||
const hasOperations = operationNames.length > 0; // We will provide a more helpful message when it looks like they just provided data, | ||
const hasOperations = operationNames.length > 0; | ||
// We will provide a more helpful message when it looks like they just provided data, | ||
// not an object mapping names to fixtures. | ||
const looksLikeDataNotFixtures = hasOperations && operationNames.every(name => name === name.toLowerCase()); | ||
if (typeof response === 'function') { | ||
@@ -63,3 +56,2 @@ message += ' (it looks like you tried to provide a function that returned a function, but the mock should be either an object or a function that retuns an object)'; | ||
} | ||
obs.error(new Error(message)); | ||
@@ -80,3 +72,2 @@ return; | ||
} | ||
obs.next(result); | ||
@@ -86,5 +77,4 @@ obs.complete(); | ||
} | ||
} | ||
exports.MockLink = MockLink; |
@@ -27,3 +27,2 @@ 'use strict'; | ||
} | ||
function diffs(operations, variables, expand) { | ||
@@ -35,3 +34,2 @@ return operations.reduce((diffs, operation, index) => `${diffs}${index === 0 ? '' : '\n\n'}${normalizedDiff(operation, variables, { | ||
} | ||
function normalizedDiff(operation, variables, { | ||
@@ -38,0 +36,0 @@ expand = false, |
@@ -24,4 +24,5 @@ 'use strict'; | ||
}); | ||
} // Original from https://github.com/facebook/jest/blob/master/packages/expect/src/utils.ts#L107 | ||
} | ||
// Original from https://github.com/facebook/jest/blob/master/packages/expect/src/utils.ts#L107 | ||
function getObjectSubset(object, subset) { | ||
@@ -37,3 +38,2 @@ if (Array.isArray(object)) { | ||
Object.keys(subset).filter(key => Reflect.has(object, key)).forEach(key => trimmed[key] = getObjectSubset(object[key], subset[key])); | ||
if (Object.keys(trimmed).length > 0) { | ||
@@ -43,3 +43,2 @@ return trimmed; | ||
} | ||
return object; | ||
@@ -46,0 +45,0 @@ } |
@@ -7,4 +7,2 @@ 'use strict'; | ||
let _Symbol$iterator; | ||
_Symbol$iterator = Symbol.iterator; | ||
class Operations { | ||
@@ -15,23 +13,17 @@ constructor(operations) { | ||
} | ||
[_Symbol$iterator]() { | ||
[Symbol.iterator]() { | ||
return this.operations[Symbol.iterator](); | ||
} | ||
push(...operations) { | ||
this.operations.push(...operations); | ||
} | ||
all(options) { | ||
return this.filterWhere(options); | ||
} | ||
first(options) { | ||
return this.nth(0, options); | ||
} | ||
last(options) { | ||
return this.nth(-1, options); | ||
} | ||
nth(index, options) { | ||
@@ -41,3 +33,2 @@ const found = this.filterWhere(options); | ||
} | ||
filterWhere(options = {}) { | ||
@@ -49,5 +40,4 @@ const finalOperationName = utilities.operationNameFromFindOptions(options); | ||
} | ||
} | ||
exports.Operations = Operations; |
@@ -10,3 +10,2 @@ 'use strict'; | ||
const passedOptions = [query, mutation].filter(Boolean); | ||
if (passedOptions.length === 0) { | ||
@@ -17,3 +16,2 @@ return undefined; | ||
} | ||
return operationNameFromDocument(query || mutation); | ||
@@ -27,3 +25,2 @@ } | ||
} | ||
function operationNameFromDocumentNode(document) { | ||
@@ -35,3 +32,2 @@ const [operation] = document.definitions.filter(({ | ||
} | ||
function operationTypeFromDocumentNode(document) { | ||
@@ -38,0 +34,0 @@ const [operation] = document.definitions.filter(({ |
@@ -1,2 +0,2 @@ | ||
import type { DocumentNode } from 'graphql'; | ||
import type { DocumentNode, ExecutionResult } from 'graphql'; | ||
import type { GraphQLRequest, Operation } from '@apollo/client'; | ||
@@ -11,3 +11,3 @@ export interface FindOptions { | ||
} | ||
export type MockGraphQLResponse = Error | object; | ||
export type MockGraphQLResponse = Error | ExecutionResult['data']; | ||
export type MockGraphQLFunction = (request: GraphQLRequest) => MockGraphQLResponse; | ||
@@ -14,0 +14,0 @@ export type GraphQLMock = { |
{ | ||
"name": "@shopify/graphql-testing", | ||
"version": "0.0.0-snapshot-20240412140044", | ||
"version": "0.0.0-snapshot-20240531073328", | ||
"license": "MIT", | ||
@@ -34,7 +34,7 @@ "description": "Utilities to create mock GraphQL factories", | ||
"dependencies": { | ||
"graphql": ">=14.5.0 <16.0.0", | ||
"graphql": ">=14.5.0 <17.0.0", | ||
"jest-matcher-utils": "^26.6.2" | ||
}, | ||
"devDependencies": { | ||
"graphql-typed": "^2.0.2" | ||
"graphql-typed": "0.0.0-snapshot-20240531073328" | ||
}, | ||
@@ -41,0 +41,0 @@ "peerDependencies": { |
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
62484
+ Addedgraphql@16.10.0(transitive)
- Removedgraphql@15.9.0(transitive)
Updatedgraphql@>=14.5.0 <17.0.0