According to the docs: here in graphql-errors
The correct way to test a pretend error is:
const dogMock = {
// ...
result: {
errors: [new GraphQLError("Error!")],
},
};
Indeed the following used to work when I used a previous version of apollo client: (@apollo/client@3.3.15). However as of the latest version 3.7.15 the following results in a typescript error. MockedResponse does not expect ‘errors’ to be populated with anything but undefined
.
export function getCheckItemAvailabilityMock(zipCode = '91234'): MockedResponse {
const variables: CheckItemAvailabilityVariables = {
input: { zipCode },
};
return {
request: {
query: checkItemAvailability,
variables,
},
result: {
errors: [new GraphQLError('unauthorized')],
},
};
}
Type ‘GraphQLError’ is not assignable to type ‘undefined’.
For me to pass with the example/documentation code I’d need to type the array of GraphQLErrors as undefined.
const dogMock = {
// ...
result: {
errors: [new GraphQLError("Error!")] as unknown as undefined,
},
};
Is the documentation outdated or is there some other way in which I can test the errors behavior?