Repository navigation
feat(json-api-nestjs-sdk): let the Angular config carry an HttpContext - #128
Merged
Merged
Conversation
…lient in the Angular providers
Angular's HttpClient was injected as HttpInnerClient directly, with an `as any`
hiding that the two disagree about argument positions.
delete is the one that cost something: HttpInnerClient takes the body second,
HttpClient reads that position as options and expects the body inside them. So
deleteRelationships handed `{ data: [...] }` to a slot meant for headers,
params and context, and the body never reached the request. The fetch client
reads the same argument as a body, so this only ever went wrong under Angular.
post and patch were harmless but equally misaligned -- their options come third
for HttpClient, and HttpInnerClient has no slot for them at all, which is why
nothing could be attached to a request until now.
An adapter in the Angular file translates the four verbs. It sits where
HttpClient is already imported, so the fetch and axios adapters are untouched.
The spec imports @angular/compiler first: loading @angular/common/http outside
an AOT build leaves its providers to be JIT-compiled.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
A provider built inside a nested component gets its own SDK config while the interceptors stay global, and until now nothing told them apart: every request looked the same whichever provider made it. The config may now carry an HttpContext, attached to every request the SDK sends, which is the channel interceptors already read through req.context.get(TOKEN). HttpContext stays out of JsonSdkConfig -- the core keeps no Angular types, or it would reach the fetch and axios builds where it means nothing. The Angular file extends it instead, as JsonSdkAngularConfig. The config is resolved once now, behind an internal token. Three providers read it, and a config factory called once per provider would have handed JsonApiSdkService and AtomicFactory two different HttpContext objects. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
View your CI Pipeline Execution ↗ for commit e5f513d
💡 Verify your cache is correct by running tasks in a sandbox. Read docs ↗ ☁️ Nx Cloud last updated this comment at |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A provider built inside a nested component gets its own SDK config while the
interceptors stay global, and nothing told them apart — every request looked the
same whichever provider made it. The config may now carry an
HttpContext.A global interceptor then reads
req.context.get(SCOPE)as usual.Two commits
97f9ce0— the translation, and a bug it was hiding. Angular'sHttpClientwas injected as
HttpInnerClientdirectly, with anas anypapering over thefact that the two disagree about argument positions:
HttpInnerClientHttpClientget(url, { params })(url, options)post/patch(url, body)(url, body, options)delete(url, body?)(url, options)— body goes insidedeleteis the one that cost something:deleteRelationshipshanded{ data: [...] }to the slot meant for headers, params and context, so the bodynever reached the request. The fetch client reads that argument as a body, so it
only ever went wrong under Angular.
post/patchwere harmless but equallymisaligned — which is also why nothing could be attached to a request until now.
An adapter in the Angular file translates the four verbs, leaving the fetch and
axios adapters untouched.
e5f513d— the context. Attached to every verb, in whichever argument thatverb keeps its options in.
Shape
HttpContextstays out ofJsonSdkConfig: the core keeps no Angular types, orit would reach the fetch and axios builds where it means nothing. The Angular
file extends it as
JsonSdkAngularConfiginstead.The config is now resolved once, behind an internal token. Three providers
read it, and a config factory called once per provider would have handed
JsonApiSdkServiceandAtomicFactorytwo differentHttpContextobjects —the exact thing this feature exists to make comparable.
Tests
Written first, red before each commit. They assert the arguments the adapter
hands to
HttpClient, verb by verb: that a delete body arrives as{ body },that
post/patchkeep the body in its own argument, that the context reachesall four, that
paramsandbodysurvive alongside it, and that a configwithout a context adds nothing.
The spec imports
@angular/compilerfirst — loading@angular/common/httpoutside an AOT build leaves its providers to be JIT-compiled, and without it the
import fails.
Verified green: unit across 9 projects, ts-test, e2e 137/137 on both MikroORM
and TypeORM.
json-api-front:build:productionfails on a CSS budget, as onmaster.
🤖 Generated with Claude Code