Skip to content

Commit 39b4668

Browse files
fix: fix fetchError persisting across different fetchers (#2653)
* fix: fix fetchError persisting across different fetchers * Update packages/graphiql-react/src/schema.tsx Co-authored-by: Thomas Heyenbrock <thomas.heyenbrock@gmail.com> * review comments and added a changeset Co-authored-by: Thomas Heyenbrock <thomas.heyenbrock@gmail.com>
1 parent ad9488f commit 39b4668

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'graphiql': patch
3+
'@graphiql/react': patch
4+
---
5+
6+
Fix `fetchError` not being cleared when a new `fetcher` is used

packages/graphiql-react/src/schema.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ export function SchemaContextProvider(props: SchemaContextProviderProps) {
227227
}
228228

229229
setIsFetching(true);
230+
setFetchError(null);
230231

231232
let result = await fetch;
232233

packages/graphiql/src/components/__tests__/GraphiQL.spec.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,31 @@ describe('GraphiQL', () => {
9999
expect(secondCalled).toEqual(true);
100100
});
101101

102+
it('should refresh schema with new fetcher after a fetchError', async () => {
103+
function firstFetcher() {
104+
return Promise.reject('Schema Error');
105+
}
106+
function secondFetcher() {
107+
return Promise.resolve(simpleIntrospection);
108+
}
109+
110+
// Use a bad fetcher for our initial render
111+
const { rerender, container } = render(<GraphiQL fetcher={firstFetcher} />);
112+
await wait();
113+
114+
expect(
115+
container.querySelector('.doc-explorer-contents .error-container'),
116+
).toBeTruthy();
117+
118+
// Re-render with valid fetcher
119+
rerender(<GraphiQL fetcher={secondFetcher} />);
120+
await wait();
121+
122+
expect(
123+
container.querySelector('.doc-explorer-contents .error-container'),
124+
).not.toBeTruthy();
125+
});
126+
102127
it('should not throw error if schema missing and query provided', () => {
103128
expect(() =>
104129
render(<GraphiQL fetcher={noOpFetcher} query="{}" />),

0 commit comments

Comments
 (0)