Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Support AngularHttpContext for use in interceptors#2374

Unanswered
stephenlautier asked this question inIdeas
Discussion options

Currently, Apollo Angular does not appear to support passing Angular’s HttpContext when making GraphQL requests. This limits the ability to leverage Angular interceptors that rely on HttpContext for custom metadata, such as feature flags, request tracing, or conditional logic.

You must be logged in to vote

Replies: 2 comments 1 reply

Comment options

I figured out it should actually be fairly easy to addHttpContext support. For that I monkey-patched the package with a few additions:

diff --git a/node_modules/apollo-angular/fesm2022/apollo-angular-http.mjs b/node_modules/apollo-angular/fesm2022/apollo-angular-http.mjsindex 74fc216..a347773 100644--- a/node_modules/apollo-angular/fesm2022/apollo-angular-http.mjs+++ b/node_modules/apollo-angular/fesm2022/apollo-angular-http.mjs@@ -148,7 +148,7 @@ class HttpBatchLinkHandler extends ApolloLink {             return new Observable((observer) => {                 const body = this.createBody(operations);                 const headers = this.createHeaders(operations);-                const { method, uri, withCredentials } = this.createOptions(operations);+                const { method, uri, withCredentials, context } = this.createOptions(operations);                 if (typeof uri === 'function') {                     throw new Error(`Option 'uri' is a function, should be a string`);                 }@@ -159,6 +159,7 @@ class HttpBatchLinkHandler extends ApolloLink {                     options: {                         withCredentials,                         headers,+                        context                     },                 };                 const sub = fetch(req, this.httpClient, () => {@@ -192,6 +193,7 @@ class HttpBatchLinkHandler extends ApolloLink {             method: pick(context, this.options, 'method'),             uri: pick(context, this.options, 'uri'),             withCredentials: pick(context, this.options, 'withCredentials'),+            context: context.httpContext         };     }     createBody(operations) {@@ -292,6 +294,7 @@ class HttpLinkHandler extends ApolloLink {                     withCredentials,                     useMultipart,                     headers: this.options.headers,+                    context: context.httpContext,                 },             };             if (includeExtensions) {diff --git a/node_modules/apollo-angular/http/types.d.ts b/node_modules/apollo-angular/http/types.d.tsindex 8235501..d120206 100644--- a/node_modules/apollo-angular/http/types.d.ts+++ b/node_modules/apollo-angular/http/types.d.ts@@ -1,5 +1,5 @@ import { DocumentNode } from 'graphql';-import { HttpHeaders } from '@angular/common/http';+import { HttpContext, HttpHeaders } from '@angular/common/http'; import { ApolloLink } from '@apollo/client'; declare module '@apollo/client' {     interface DefaultContext extends Context {@@ -9,6 +9,7 @@ export type HttpRequestOptions = {     headers?: HttpHeaders;     withCredentials?: boolean;     useMultipart?: boolean;+    httpContext?: HttpContext; }; export type URIFunction = (operation: ApolloLink.Operation) => string; export type FetchOptions = {

Btw. there's already a previously create but still unhandled open feature request:#2129

So, as it looks like there's a demand amongst other developers using this great package, I'd highly appreciate, if this useful feature could be added in a future release!

You must be logged in to vote
0 replies
Comment options

@PowerKiKi , if I'd volunteer for opening a PR, would you be willing to accept it?

You must be logged in to vote
1 reply
@PowerKiKi
Comment options

Yes, I would merge a PR that HttpContext support and related unit tests.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Category
Ideas
Labels
None yet
3 participants
@stephenlautier@PowerKiKi@vz-tl

[8]ページ先頭

©2009-2025 Movatter.jp