I am writing to report a possible issue with the Apollo package types. When using the ApolloError
object, TypeScript allows me to access the extensions
property directly, even when the graphQLErrors
array may be empty, which can result in a “Cannot read property ‘extensions’ of undefined” error at runtime.
It is possible that the types defined in the Apollo package are inaccurate or incomplete, leading to this error. I suggest reviewing and updating the types to prevent this issue from occurring.
Example:
import { ApolloError } from "@apollo/client";
const handleError = (err: ApolloError) => {
if (err.graphQLErrors[0].extensions?.code !== "CONFLICT") {
console.log("Error occurred");
}
};