-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Add GraphQL network observers matching FTAPIKit pattern #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
This change updates the minimum macOS version required for the package to macOS 11.
samoilyk
reviewed
Jan 13, 2026
samoilyk
approved these changes
Jan 13, 2026
jmarek41
approved these changes
Jan 13, 2026
Introduce GraphQLNetworkObserver protocol following FTAPIKit pattern. Observers receive lifecycle callbacks (willSendRequest, didReceiveResponse, didFail) without ability to modify requests - safer than interceptors.
Replace custom GraphQLOperationContext with URLRequest for observer API, matching FTAPIKit's NetworkObserver pattern exactly. Use closure capture pattern in ObserverInterceptor for type erasure without locks. - Remove GraphQLOperationContext and GraphQLRequestToken - Add ObserverInterceptor with generic init for type erasure - Use closure capture pattern (no locks needed) - Add factory pattern in NetworkInterceptorProvider - Simplify GraphQLAPIAdapter (observer handling now in interceptor) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Ensures observers see URLRequest with all headers applied (defaultHeaders and additionalHeaders from context). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add GraphQLAPIAdapterIntegrationTests with MockURLProtocol to verify: - Observer receives default headers - Observer receives context headers (RequestHeaders) - Observer receives both default and context headers - Multiple observers all receive same headers - Observer sees Apollo-added headers (X-APOLLO-OPERATION-NAME, etc.) Also add unit tests for header capture in GraphQLNetworkObserverTests: - testObserverReceivesHeadersFromURLRequest - testMultipleObserversReceiveSameHeaders - testInterceptorChainOrderPlacesObserversAfterHeaders Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Change didReceiveResponse signature from HTTPURLResponse? to URLResponse? to match FTAPIKit's NetworkObserver protocol exactly. This allows a single class to conform to both protocols without method signature conflicts. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Refactor network observer integration to allow state sharing between pre-network-request and post-network-response/error phases using an `ObserverContextStore` actor. This enables observers to maintain a consistent context throughout a single network operation. Also, update macOS deployment target to v12. # Conflicts: # Package.swift
Extracted `NetworkInterceptorProvider` and `RequestHeaderInterceptor` into their own files and relocated `ObserverInterceptor` to a new `Interceptors` directory for better modularity.
…ency and simplified memory management The ObserverInterceptor has been refactored from a class to a struct. This change enhances Sendable conformance, eliminates potential reference cycles, and removes the need for explicit weak self captures within asynchronous blocks.
…ork observer Streamlines `ObserverInterceptor` creation, enhances `NetworkObserver` protocol conformance, and unifies `ObserverContextStore` operations into robust test cases.
…edUnfairLock The ObserverContextStore was converted from an actor to a final class, utilizing OSAllocatedUnfairLock for thread-safe synchronous access. This simplifies the ObserverInterceptor by removing unnecessary Task wrappers and associated await calls. The minimum macOS deployment target was also updated to v13.
Replaced `urlRequest.hashValue.description` with `ObjectIdentifier(request).debugDescription` for stable request tracking by observers, addressing potential inconsistencies with hash values.
… observers This introduces a new initializer for `GraphQLAPIAdapter` that leverages Swift 5.9's variadic generics, allowing multiple `GraphQLNetworkObserver` instances to be passed directly without being wrapped in an array. This improves API ergonomics and simplifies usage. The `swift-tools-version` has been updated to 5.9 accordingly.
3407612 to
f6c8707
Compare
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.
Summary
GraphQLNetworkObserverprotocol for passive observation of GraphQL network requestsNetworkObserverfor API consistencyOSAllocatedUnfairLockfor thread-safe synchronous context storageChanges
GraphQLNetworkObserverprotocol withwillSendRequest,didReceiveResponse, anddidFailcallbacksObserverInterceptorstruct for integrating observers into Apollo's interceptor chainObserverContextStoreclass withOSAllocatedUnfairLockfor thread-safe context managementObjectIdentifierfor stable request correlation across interceptor chainOSAllocatedUnfairLock)Test plan
🤖 Generated with Claude Code