Major Changes
-
#12809
e2a0be8Thanks @jerelmiller! -operation.getContextnow returns aReadonly<OperationContext>type. -
#12809
e2a0be8Thanks @jerelmiller! - TheApolloLink.Request(i.e.GraphQLRequest) passed toApolloLink.executeno longer acceptsoperationNameandoperationTypeoptions. These properties are derived from thequeryand set on the returnedApolloLink.Operationtype. -
#12808
8e31a23Thanks @phryneas! - HTTP Multipart handling will now throw an error if the connection closed before the final boundary has been received.
Data after the final boundary will be ignored. -
#12809
e2a0be8Thanks @jerelmiller! -operation.operationTypeis now a non-nullOperationTypeNode. It is now safe to compare this value without having to check forundefined. -
#12809
e2a0be8Thanks @jerelmiller! -operation.operationNameis now set asstring | undefinedwhereundefinedrepresents an anonymous query. PreviouslyoperationNamewould return an empty string as theoperationNamefor anonymous queries. -
#12809
e2a0be8Thanks @jerelmiller! - Theconcat,from, andsplitfunctions onApollLinkno longer support a plain request handler function. Please wrap the request handler withnew ApolloLink.const link = new ApolloLink(/* ... */); link.concat( - (operation, forward) => forward(operation), + new ApolloLink((operation, forward) => forward(operation)), );
-
#12809
e2a0be8Thanks @jerelmiller! -transformOperationandvalidateOperationhave been removed and are no longer exported from@apollo/client/link/utils. These utilities have been merged into the implementation ofcreateOperation. As a result,createOperationnow returns a well-formedOperationobject. PreviouslycreateOperationrelied on an external call totransformOperationto provide a well-formedOperationtype. If you usecreateOperationdirectly, remove the calls totransformOperationandvalidateOperationand pass the request directly. -
#12809
e2a0be8Thanks @jerelmiller! - The request handler provided toApolloLinkmust now return anObservable.nullis no longer supported as a valid return value. If you rely onnullso thatApolloLinkprovides an empty observable, use theEMPTYobservable from RxJS instead:import { ApolloLink } from "@apollo/client"; + import { EMPTY } from "rxjs"; const link = new ApolloLink((operation, forward) => { - return null; + return EMPTY; });If you have a custom link that overrides the
requestmethod, removenullfrom the return signature:class MyCustomLink extends ApolloLink { request( operation: ApolloLink.Operation, forward: ApolloLink.ForwardFunction, - ): Observable<ApolloLink.Result> | null { + ): Observable<ApolloLink.Result> { // implementation } } -
#12809
e2a0be8Thanks @jerelmiller! -createOperationno longer acceptscontextas the first argument. Instead make surecontextis set as thecontextproperty on the request passed tocreateOperation.createOperation( - startingContext, - { query }, + { query, context: startingContext }, { client } );
-
#12809
e2a0be8Thanks @jerelmiller! - Remove theTVariablesgeneric argument on theGraphQLRequesttype. -
#12809
e2a0be8Thanks @jerelmiller! - The context object returned fromoperation.getContext()is now frozen to prevent mutable changes to the object which could result in subtle bugs. This applies to thepreviousContextobject passed to theoperation.setContext()callback as well. -
#12809
e2a0be8Thanks @jerelmiller! - Theforwardfunction passed to the request handler is now always provided torequestand no longer optional. If you create custom links by subclassingApolloLink, theforwardfunction no longer needs to be optional:class CustomLink extends ApolloLink { request( operation: ApolloLink.Operation, // This no longer needs to be typed as optional forward: ApolloLink.ForwardFunction ) { // ... } }
As a result of this change,
ApolloLinkno longer detects terminating links by checking function arity on the request handler. This means using methods such asconcaton a terminating link no longer emit a warning. On the flip side, if the terminating link calls theforwardfunction, a warning is emitted and an observable that immediately completes is returned which will result in an error from Apollo Client.
Minor Changes
-
#12809
e2a0be8Thanks @jerelmiller! -ApolloLink'sconcatmethod now accepts multiple links to concatenate together.const first = new ApolloLink(); const link = first.concat(second, third, fouth);
-
#12809
e2a0be8Thanks @jerelmiller! - Many of the types exported from@apollo/client/linknow live on theApolloLinknamespace. The old types are now deprecated in favor of the namespaced types.FetchResult->ApolloLink.ResultGraphQLRequest->ApolloLink.RequestNextLink->ApolloLink.ForwardFunctionOperation->ApolloLink.OperationRequestHandler->ApolloLink.RequestHandler
-
#12809
e2a0be8Thanks @jerelmiller! - The staticApolloLink.concatmethod is now deprecated in favor ofApolloLink.from.ApolloLink.concatis now an alias forApolloLink.fromso preferApolloLink.frominstead.
Patch Changes
-
#12809
e2a0be8Thanks @jerelmiller! - The individualempty,concat,fromandsplitfunctions exported from@apollo/client/linkare now deprecated in favor of using the static functions instead.import { ApolloLink, - concat, - empty, - from, - split, } from "@apollo/client/link"; - concat(first, second); + ApolloLink.concat(first, second); - empty(); + ApolloLink.empty(); - from([first, second]); + ApolloLink.from([first, second]); - split( + ApolloLink.split( (operation) => /* */, first, second );