Skip to content

Commit

Permalink
remove redundant catch statement (#3033)
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaMachina authored Mar 4, 2023
1 parent 9c6042d commit 2d5c60e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .changeset/good-cooks-collect.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@graphiql/react': patch
---

remove redundant `catch` statement
27 changes: 12 additions & 15 deletions packages/graphiql-react/src/execution.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,13 @@ export type ExecutionContextProviderProps = Pick<
operationName?: string;
};

export function ExecutionContextProvider(props: ExecutionContextProviderProps) {
if (!props.fetcher) {
export function ExecutionContextProvider({
fetcher,
getDefaultFieldNames,
children,
operationName,
}: ExecutionContextProviderProps) {
if (!fetcher) {
throw new TypeError(
'The `ExecutionContextProvider` component requires a `fetcher` function to be passed as prop.',
);
Expand All @@ -86,7 +91,7 @@ export function ExecutionContextProvider(props: ExecutionContextProviderProps) {
} = useEditorContext({ nonNull: true, caller: ExecutionContextProvider });
const history = useHistoryContext();
const autoCompleteLeafs = useAutoCompleteLeafs({
getDefaultFieldNames: props.getDefaultFieldNames,
getDefaultFieldNames,
caller: ExecutionContextProvider,
});
const [isFetching, setIsFetching] = useState(false);
Expand All @@ -99,7 +104,6 @@ export function ExecutionContextProvider(props: ExecutionContextProviderProps) {
setSubscription(null);
}, [subscription]);

const { fetcher, children, operationName } = props;
const run = useCallback<ExecutionContextType['run']>(async () => {
if (!queryEditor || !responseEditor) {
return;
Expand Down Expand Up @@ -282,18 +286,11 @@ export function ExecutionContextProvider(props: ExecutionContextProviderProps) {
setSubscription({
unsubscribe: () => value[Symbol.asyncIterator]().return?.(),
});

try {
for await (const result of value) {
handleResponse(result);
}
setIsFetching(false);
setSubscription(null);
} catch (error) {
setIsFetching(false);
setResponse(formatError(error));
setSubscription(null);
for await (const result of value) {
handleResponse(result);
}
setIsFetching(false);
setSubscription(null);
} else {
handleResponse(value);
}
Expand Down

0 comments on commit 2d5c60e

Please sign in to comment.