Skip to content

Commit

Permalink
Squashed 'apollo-ios/' changes from 39bf0726..c17bddf2
Browse files Browse the repository at this point in the history
c17bddf2 fix: Multipart chunk content type (#572)
a94ebd7a Update ROADMAP.md

git-subtree-dir: apollo-ios
git-subtree-split: c17bddf2f9ec626c70890fe203c382bd470749ec
  • Loading branch information
gh-action-runner authored and gh-action-runner committed Jan 8, 2025
1 parent ad06fa0 commit eea1230
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 31 deletions.
10 changes: 1 addition & 9 deletions ROADMAP.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# 🔮 Apollo iOS Roadmap

**Last updated: 2024-12-10**
**Last updated: 2025-01-07**

For up to date release notes, refer to the project's [Changelog](https://github.com/apollographql/apollo-ios/blob/main/CHANGELOG.md).

Expand Down Expand Up @@ -56,14 +56,6 @@ _Status: In design phase. Current RFC for design is available [here](https://git
-[`ExistentialAny` upcoming feature](https://github.com/apollographql/apollo-ios/issues/3205)
- (in progress) [`Sendable` types and `async/await` APIs](https://github.com/apollographql/apollo-ios/issues/3291)

### `@oneOf` Input Object Support

_Status: Code complete. Will be included in the next minor version release (1.16.0)._

For more information on this feature, see the [RFC](https://github.com/graphql/graphql-spec/pull/825) for its addition to the GraphQL specification.

Support for this feature is considered experimental and subject to change until the RFC is approved and merged into the GraphQL specification.

### [Reduce generated schema types](https://github.com/apollographql/apollo-ios/milestone/71)

_Status: API Design in progress_
Expand Down
18 changes: 6 additions & 12 deletions Sources/Apollo/MultipartResponseDeferParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ struct MultipartResponseDeferParser: MultipartResponseSpecificationParser {
}

private enum DataLine {
case contentHeader(type: String)
case contentHeader(directives: [String])
case json(object: JSONObject)
case unknown

Expand All @@ -32,14 +32,8 @@ struct MultipartResponseDeferParser: MultipartResponseSpecificationParser {
}

private static func parse(_ dataLine: String) -> DataLine {
var contentTypeHeader: StaticString { "content-type:" }

if dataLine.starts(with: contentTypeHeader.description) {
let contentType = (dataLine
.components(separatedBy: ":").last ?? dataLine
).trimmingCharacters(in: .whitespaces)

return .contentHeader(type: contentType)
if let directives = dataLine.parseContentTypeDirectives() {
return .contentHeader(directives: directives)
}

if
Expand All @@ -58,9 +52,9 @@ struct MultipartResponseDeferParser: MultipartResponseSpecificationParser {
static func parse(_ chunk: String) -> Result<Data?, any Error> {
for dataLine in chunk.components(separatedBy: Self.dataLineSeparator.description) {
switch DataLine(dataLine.trimmingCharacters(in: .newlines)) {
case let .contentHeader(type):
guard type == "application/json" else {
return .failure(ParsingError.unsupportedContentType(type: type))
case let .contentHeader(directives):
guard directives.contains("application/json") else {
return .failure(ParsingError.unsupportedContentType(type: directives.joined(separator: ";")))
}

case let .json(object):
Expand Down
12 changes: 12 additions & 0 deletions Sources/Apollo/MultipartResponseParsingInterceptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,4 +182,16 @@ extension String {

return nil
}

func parseContentTypeDirectives() -> [String]? {
var lowercasedContentTypeHeader: StaticString { "content-type:" }

guard lowercased().starts(with: lowercasedContentTypeHeader.description) else {
return nil
}

return dropFirst(lowercasedContentTypeHeader.description.count)
.components(separatedBy: ";")
.map({ $0.trimmingCharacters(in: .whitespaces) })
}
}
16 changes: 6 additions & 10 deletions Sources/Apollo/MultipartResponseSubscriptionParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct MultipartResponseSubscriptionParser: MultipartResponseSpecificationParser

private enum DataLine {
case heartbeat
case contentHeader(type: String)
case contentHeader(directives: [String])
case json(object: JSONObject)
case unknown

Expand All @@ -46,12 +46,8 @@ struct MultipartResponseSubscriptionParser: MultipartResponseSpecificationParser
return .heartbeat
}

if dataLine.lowercased().starts(with: contentTypeHeader.description) {
let contentType = (dataLine
.components(separatedBy: ":").last ?? dataLine
).trimmingCharacters(in: .whitespaces)

return .contentHeader(type: contentType)
if let directives = dataLine.parseContentTypeDirectives() {
return .contentHeader(directives: directives)
}

if
Expand All @@ -74,9 +70,9 @@ struct MultipartResponseSubscriptionParser: MultipartResponseSpecificationParser
// Periodically sent by the router - noop
break

case let .contentHeader(type):
guard type == "application/json" else {
return .failure(ParsingError.unsupportedContentType(type: type))
case let .contentHeader(directives):
guard directives.contains("application/json") else {
return .failure(ParsingError.unsupportedContentType(type: directives.joined(separator: ";")))
}

case let .json(object):
Expand Down

0 comments on commit eea1230

Please sign in to comment.