Skip to content

Commit c2e01c5

Browse files
committed
Bring back onError behavior
1 parent 09959f9 commit c2e01c5

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

packages/plugins/graphql-jit/src/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const useGraphQlJit = (
3434
/**
3535
* Callback triggered in case of GraphQL Jit compilation error.
3636
*/
37-
onError?: (r: ExecutionResult) => void;
37+
onError?: (r: ExecutionResult<any>) => void;
3838
/**
3939
* Custom cache instance
4040
*/
@@ -73,6 +73,9 @@ export const useGraphQlJit = (
7373

7474
if (!compiledQuery) {
7575
compiledQuery = compileQuery(schema, document, operationName, compilerOptions);
76+
if (!isCompiledQuery(compiledQuery)) {
77+
pluginOptions?.onError?.(compiledQuery);
78+
}
7679
jitCache.set(cacheKey, compiledQuery);
7780
}
7881

packages/plugins/graphql-jit/test/graphql-jit.spec.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ describe('useGraphQlJit', () => {
144144
});
145145

146146
it('Should use the provided cache instance', async () => {
147-
const cache = lru();
147+
const cache = new Map();
148148
jest.spyOn(cache, 'set');
149149
jest.spyOn(cache, 'get');
150150

@@ -161,8 +161,9 @@ describe('useGraphQlJit', () => {
161161
);
162162

163163
await testInstance.execute(`query { test }`);
164-
expect(cache.get).toHaveBeenCalled();
165-
expect(cache.set).toHaveBeenCalled();
164+
await testInstance.execute(`query { test }`);
165+
expect(cache.get).toHaveBeenCalledTimes(4);
166+
expect(cache.set).toHaveBeenCalledTimes(1);
166167
});
167168

168169
it('Should throw validation errors if compilation fails', async () => {

0 commit comments

Comments
 (0)