Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix fetchError persisting across different fetchers #2653

Merged
merged 3 commits into from
Sep 9, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/graphiql-react/src/schema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,8 @@ export function SchemaContextProvider(props: SchemaContextProviderProps) {
}

setIsFetching(true);
// clear any previous fetch errors
dylanowen marked this conversation as resolved.
Show resolved Hide resolved
setFetchError(null);

let result = await fetch;

Expand Down
25 changes: 25 additions & 0 deletions packages/graphiql/src/components/__tests__/GraphiQL.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,31 @@ describe('GraphiQL', () => {
expect(secondCalled).toEqual(true);
});

it('should refetch schema after a fetchError', async () => {
thomasheyenbrock marked this conversation as resolved.
Show resolved Hide resolved
function firstFetcher() {
return Promise.reject('Schema Error');
}
function secondFetcher() {
return Promise.resolve(simpleIntrospection);
}

// Use a bad fetcher for our initial render
const { rerender, container } = render(<GraphiQL fetcher={firstFetcher} />);
await wait();

expect(
container.querySelector('.doc-explorer-contents .error-container'),
).toBeTruthy();

// Re-render with valid fetcher
rerender(<GraphiQL fetcher={secondFetcher} />);
await wait();

expect(
container.querySelector('.doc-explorer-contents .error-container'),
).not.toBeTruthy();
});

it('should not throw error if schema missing and query provided', () => {
expect(() =>
render(<GraphiQL fetcher={noOpFetcher} query="{}" />),
Expand Down