In tutorial
there is presented new HttpLink
syntax, but in official docs
function createHttpLink
is applied.
None of these two sources describes the differences between these methods.
In tutorial
there is presented new HttpLink
syntax, but in official docs
function createHttpLink
is applied.
None of these two sources describes the differences between these methods.
There is no fundamental difference between the two.
If you look at the apollo-link-http
package source here, you can see that the exported createHttpLink
method returns a new instance of the ApolloLink
class initialized with the options you passed to createHttpLink
(lines 62-194).
At the end of the same file, you can see that the package also exports the HttpLink
class, which extends the ApolloLink
class (lines 256-261):
export class HttpLink extends ApolloLink {
public requester: RequestHandler;
constructor(opts?: HttpLink.Options) {
super(createHttpLink(opts).request);
}
}
As you can see from the code above, when you create an apollo http link by creating a new instance of the HttpLink
class, the options you pass to the constructor are internally passed on to createHttpLink
, which returns an instance of ApolloLink
as mentioned above, and that instance's RequestHandler
is passed on to (i.e. copied) to the new HttpLink
instance's parent, which is also an instance of ApolloLink
(see lines 96-124 here for a peek at ApolloLink
's own constructor).
Note that the apollo-link-http
package's own docs do NOT mention the new HttpLink
syntax, so I would stick to the createHttpLink
syntax for future compatibility.
© 2022 - 2024 — McMap. All rights reserved.