Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Apr 13, 2023. It is now read-only.

Commit 92cba32

Browse files
committed
Add graphQL errors to Mutation component state
Fixes the broken unit test introduced by previous commit
1 parent f31a7a6 commit 92cba32

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/Mutation.tsx

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,14 @@ class Mutation<TData = any, TVariables = OperationVariables> extends React.Compo
248248
}
249249
const { onCompleted, ignoreResults } = this.props;
250250

251-
const data = response.data as TData;
251+
const { data, errors } = response;
252+
const error =
253+
errors && errors.length > 0 ? new ApolloError({ graphQLErrors: errors }) : undefined;
252254

253-
const callOncomplete = () => (onCompleted ? onCompleted(data) : null);
255+
const callOncomplete = () => (onCompleted ? onCompleted(data as TData) : null);
254256

255257
if (this.isMostRecentMutation(mutationId) && !ignoreResults) {
256-
this.setState({ loading: false, data }, callOncomplete);
258+
this.setState({ loading: false, data, error }, callOncomplete);
257259
} else {
258260
callOncomplete();
259261
}

0 commit comments

Comments
 (0)