Resource-specific properties set by resource service subclass#67
Open
Resource-specific properties set by resource service subclass#67
Conversation
added 2 commits
January 11, 2018 12:47
…specific properties of the request
Codecov Report
@@ Coverage Diff @@
## master #67 +/- ##
==========================================
+ Coverage 86.12% 86.28% +0.15%
==========================================
Files 22 22
Lines 346 350 +4
Branches 30 30
==========================================
+ Hits 298 302 +4
Misses 48 48 |
| testService.fetch(resource: mockResource) { _ in } | ||
| XCTAssertEqual(mockSession.capturedRequest!.allHTTPHeaderFields!, resourceHTTPHeaderFields) | ||
| let expectedHeaderFields = [commonKey: "resource", resourceNameKey: mockResourceName] | ||
| XCTAssertEqual(mockSession.capturedRequest!.allHTTPHeaderFields!, expectedHeaderFields) |
Contributor
There was a problem hiding this comment.
If you wanted to avoid the force unwraps here you could use optional chaining with a default value?
mockSession.capturedRequest?.allHTTPHeaderFields ?? [:] should work? It'll still fail but won't crash the tests
Contributor
Author
There was a problem hiding this comment.
good point @KaneCheshire. i just modified what was already there. didn't even notice the force unwraps.
| */ | ||
| func urlRequest() -> URLRequest? | ||
|
|
||
| func urlRequest(with: [URLQueryItem]) -> URLRequest? |
There was a problem hiding this comment.
can you also please include additionalQueryParameters in the function signature as the parameter name just to go w/ the comment above.
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.
🛠 Description & Reasoning
Adding a
resourceargument to the "additional" functions of the resource service - the functions that are intended to be overridden by subclasses.Providing the subclass with the resource gives that subclass an opportunity to set parameters of the URL request based on the resource. This is different to the resource providing those parameters itself, e.g. the resource could implement the
httpHeaderFieldsandqueryItemsproperties.Consider a subclass that adds the requirement that its resources must conform to a protocol
GraphQLResouce. TheGraphQLResouceprotocol requires a propertyqueryName: Stringto be implemented by its conformers.The
NetworkDataResourceServicecan now add in thequeryNameto either the HTTP header fields or the URL query items. It would be unreliable to expect all resources to implement thequeryItemsandhttpHeaderFieldsto add thequeryNamekey/value.This PR modifies the
NetworkDataResourceService.additionalHeaderFieldsfunction by adding an argument to the function. This function is overridden (not invoked explicitly), which is why we cannot provide a default argument value. For this reason, this is an API-breaking change.✨ Other Changes
The addition of the
NetworkDataResourceService.additionalQueryParametersfunction. This serves the same purpose as theadditionalHeaderFieldsfunction, but for URL query parameters.