-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Closed
Labels
Description
Issue Description
I'd like to resurrect #11168 since issue got stale and closed.
As you can see in the graphql spec, the errors returned by the server are not required to specify e.g. extensions key.
However,
import type { GraphQLError, GraphQLErrorExtensions } from "graphql";
...
export type GraphQLErrors = ReadonlyArray<GraphQLError>;
export class ApolloError extends Error {
...
public graphQLErrors: GraphQLErrors;if you look at the GraphQLError class, the extensions field is not optional
/**
* Extension fields to add to the formatted error.
*/
readonly extensions: GraphQLErrorExtensions;That is achieved by taking server response and routing it through GraphQLError class' constructor:
this.extensions = extensions ?? originalExtensions ?? Object.create(null);So that implies that using GraphQLError[] as a type for ApolloError.graphQLErrors is wrong since the server data were not manipulated and may not comply with the GraphQLError interface.
Link to Reproduction
https://spec.graphql.org/October2021/#sec-Errors.Error-result-format
Reproduction Steps
No response
@apollo/client version
3.9.1
tomas-c and izumin5210