Major Changes
-
#12809
e2a0be8
Thanks @jerelmiller! -operation.getContext
now returns aReadonly<OperationContext>
type. -
#12809
e2a0be8
Thanks @jerelmiller! - TheApolloLink.Request
(i.e.GraphQLRequest
) passed toApolloLink.execute
no longer acceptsoperationName
andoperationType
options. These properties are derived from thequery
and set on the returnedApolloLink.Operation
type. -
#12808
8e31a23
Thanks @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
e2a0be8
Thanks @jerelmiller! -operation.operationType
is now a non-nullOperationTypeNode
. It is now safe to compare this value without having to check forundefined
. -
#12809
e2a0be8
Thanks @jerelmiller! -operation.operationName
is now set asstring | undefined
whereundefined
represents an anonymous query. PreviouslyoperationName
would return an empty string as theoperationName
for anonymous queries. -
#12809
e2a0be8
Thanks @jerelmiller! - Theconcat
,from
, andsplit
functions onApollLink
no 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
e2a0be8
Thanks @jerelmiller! -transformOperation
andvalidateOperation
have been removed and are no longer exported from@apollo/client/link/utils
. These utilities have been merged into the implementation ofcreateOperation
. As a result,createOperation
now returns a well-formedOperation
object. PreviouslycreateOperation
relied on an external call totransformOperation
to provide a well-formedOperation
type. If you usecreateOperation
directly, remove the calls totransformOperation
andvalidateOperation
and pass the request directly. -
#12809
e2a0be8
Thanks @jerelmiller! - The request handler provided toApolloLink
must now return anObservable
.null
is no longer supported as a valid return value. If you rely onnull
so thatApolloLink
provides an empty observable, use theEMPTY
observable 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
request
method, removenull
from the return signature:class MyCustomLink extends ApolloLink { request( operation: ApolloLink.Operation, forward: ApolloLink.ForwardFunction, - ): Observable<ApolloLink.Result> | null { + ): Observable<ApolloLink.Result> { // implementation } }
-
#12809
e2a0be8
Thanks @jerelmiller! -createOperation
no longer acceptscontext
as the first argument. Instead make surecontext
is set as thecontext
property on the request passed tocreateOperation
.createOperation( - startingContext, - { query }, + { query, context: startingContext }, { client } );
-
#12809
e2a0be8
Thanks @jerelmiller! - Remove theTVariables
generic argument on theGraphQLRequest
type. -
#12809
e2a0be8
Thanks @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 thepreviousContext
object passed to theoperation.setContext()
callback as well. -
#12809
e2a0be8
Thanks @jerelmiller! - Theforward
function passed to the request handler is now always provided torequest
and no longer optional. If you create custom links by subclassingApolloLink
, theforward
function 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,
ApolloLink
no longer detects terminating links by checking function arity on the request handler. This means using methods such asconcat
on a terminating link no longer emit a warning. On the flip side, if the terminating link calls theforward
function, a warning is emitted and an observable that immediately completes is returned which will result in an error from Apollo Client.
Minor Changes
-
#12809
e2a0be8
Thanks @jerelmiller! -ApolloLink
'sconcat
method now accepts multiple links to concatenate together.const first = new ApolloLink(); const link = first.concat(second, third, fouth);
-
#12809
e2a0be8
Thanks @jerelmiller! - Many of the types exported from@apollo/client/link
now live on theApolloLink
namespace. The old types are now deprecated in favor of the namespaced types.FetchResult
->ApolloLink.Result
GraphQLRequest
->ApolloLink.Request
NextLink
->ApolloLink.ForwardFunction
Operation
->ApolloLink.Operation
RequestHandler
->ApolloLink.RequestHandler
-
#12809
e2a0be8
Thanks @jerelmiller! - The staticApolloLink.concat
method is now deprecated in favor ofApolloLink.from
.ApolloLink.concat
is now an alias forApolloLink.from
so preferApolloLink.from
instead.
Patch Changes
-
#12809
e2a0be8
Thanks @jerelmiller! - The individualempty
,concat
,from
andsplit
functions exported from@apollo/client/link
are 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 );