Skip to content

Commit

Permalink
Merge pull request #35 from intuit/vsuram_fixOperationCheck
Browse files Browse the repository at this point in the history
fixes operation check - minor refactor
  • Loading branch information
vamshisuram committed Jan 29, 2024
2 parents 19026b2 + 3dc6208 commit 4130ad1
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/mocker.js
@@ -1,5 +1,4 @@

import { ApolloLink, Observable } from 'apollo-link';
import { ApolloLink, Observable } from "apollo-link";

export class MockLink extends ApolloLink {
constructor(mockLinkConfig) {
Expand All @@ -9,8 +8,8 @@ export class MockLink extends ApolloLink {

request(operation, forward) {
const { enableMock, targetOperations } = this.config;
const isOperationMocked = targetOperations.find(
(query) => query === operation.operationName
const isOperationMocked = targetOperations.includes(
operation.operationName
);
if (enableMock && isOperationMocked) {
return new Observable((observer) => {
Expand All @@ -33,14 +32,22 @@ export class MockLink extends ApolloLink {
* mockData - data config for success / error responses
* createCustomLinkObj - to create link object as per user's links structure
*/
export const injectMock = ({ links, enableMock = true, targetOperations, mockData, createCustomLinkObj }) => {
export const injectMock = ({
links,
enableMock = true,
targetOperations,
mockData,
createCustomLinkObj,
}) => {
const mockLink = new MockLink({
enableMock,
mockData,
targetOperations
targetOperations,
});

const mockLinkObj = createCustomLinkObj ? createCustomLinkObj(mockLink) : mockLink;
const mockLinkObj = createCustomLinkObj
? createCustomLinkObj(mockLink)
: mockLink;

links.splice(links.length - 1, 0, mockLinkObj);
}
};

0 comments on commit 4130ad1

Please sign in to comment.