Skip to content

Commit 674da60

Browse files
committed
chore: add withMocks function
1 parent d476674 commit 674da60

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/handlers.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,25 @@ function createHandlerFromSchema<TResolvers>(
146146
});
147147
}
148148

149+
function withMocks(mocks: IMocks<TResolvers>) {
150+
const oldSchema = testSchema;
151+
152+
testSchema = addMocksToSchema({
153+
schema: oldSchema,
154+
mocks: mocks,
155+
});
156+
157+
function restore() {
158+
testSchema = oldSchema;
159+
}
160+
161+
return Object.assign(restore, {
162+
[Symbol.dispose]() {
163+
restore();
164+
},
165+
});
166+
}
167+
149168
function replaceDelay(newDelay: Delay) {
150169
const oldDelay = _delay;
151170
_delay = newDelay;
@@ -269,6 +288,7 @@ function createHandlerFromSchema<TResolvers>(
269288
replaceSchema,
270289
replaceDelay,
271290
withResolvers,
291+
withMocks,
272292
},
273293
);
274294
}

0 commit comments

Comments
 (0)