// Custom link that adds a header
const authLink = (op, next) => {
op.config.headers = { ...op.config.headers, Authorization: "Bearer token" };
return next(op);
};
// Custom link that logs timing
const timingLink = async (op, next) => {
const start = Date.now();
const res = await next(op);
console.log(`Query took ${Date.now() - start}ms`);
return res;
};
const client = new GraphQLClient({
url: "https://api.example.com/graphql",
links: [authLink, timingLink],
});
GraphQL middleware link - similar to Relay-style middleware.
Links form a chain where each link can:
nextnextreturnsnext