react-apollo
react-apollo copied to clipboard
call to onMutationCompleted is throwing an error
Intended outcome: No error is thrown
Actual outcome: An error is thrown because of the call to "onMutationCompleted" have an undefined response as the first argument https://github.com/apollographql/react-apollo/blob/master/packages/hooks/src/data/MutationData.ts#L69
How to reproduce the issue:
Version
System: OS: macOS 10.14 Binaries: Node: 8.16.0 - /usr/local/opt/node@8/bin/node Yarn: 1.16.0 - ~/code/sweepbright/webapp/node_modules/.bin/yarn npm: 6.4.1 - /usr/local/opt/node@8/bin/npm Browsers: Chrome: 76.0.3809.132 Safari: 12.0 npmPackages: apollo: ^2.11.1 => 2.11.1 apollo-boost: ^0.3.1 => 0.3.1 apollo-cache-inmemory: 1.6.2 => 1.6.2 apollo-client: ^2.6.3 => 2.6.3 apollo-link: 1.2.12 => 1.2.12 apollo-link-error: ^1.1.10 => 1.1.10 apollo-link-http: ^1.5.14 => 1.5.14 apollo-server-express: ^2.5.0 => 2.5.0 apollo-server-testing: ^2.6.1 => 2.6.1 apollo-utilities: 1.3.2 => 1.3.2 react-apollo: ^2.5.5 => 2.5.5
Same issue with React Apollo 2.5.2 when running a simple test:
const responses = [{
request: {
query: gql`
mutation createFoo($data: CreateFooDataInput!) {
createFoo(data: $data) {
data {
hello
__typename
}
__typename
}
}
`,
variables: {
data: { "hello": "world" }
}
},
result: {
createFoo: {
data: foo
},
}
}];
const wrapper = mount(
<MockedProvider mocks={responses}>
<CreateComponent /> // defined previously using graphql (nothing fancy)
</MockedProvider>
);
// ...
await wrapper.find('UnderlyingComponent').prop('createFoo')({ data: "someFoo" }) // will fail
I can't figure why this response argument is undefined on mutation completion. The issue might be related to Apollo Client that does not return a response on mutate.
Edit: this happens with newer versions (@apollo/react-testing 3.1.0 + apollo-client 2.6.2) too.
Seems related: https://stackoverflow.com/questions/54198589/handling-apollo-server-errors-on-client
This error seems to mean that there is actually an underlying failure, eg if your results are not correctly set. In my example I missed an additionnal data field.
The actual error does not appear in Mocha's report, either client side or server side, which initially prevented me from debugging this issue correctly. Only the client side console gives me the correct error.
So the issue is an error not being thrown correctly, somehow, or maybe in a promise or smth
@eric-burel @krvajal For my instance of the error "TypeError: Cannot read property 'data' of undefined at Mutation._this.onMutationCompleted", the issue was with the example I followed for setting up a middleware link for authentication.
This was the example I followed that resulted in the error: https://www.apollographql.com/docs/link/links/http/#upgrade-apollo-client-10
The correct example to follow that avoided this error completely for a middleware link is the following: https://www.apollographql.com/docs/react/networking/authentication/#header
Hope this helps!
Have the same error with react-apollo version 3.1.3