Skip to content

Fatal error: Optional is only JSONEncodable if Wrapped #1536

@ruizmarc

Description

@ruizmarc

Bug report

Everything was working fine in 0.36 but after updating to 0.37 this error message appears:

Fatal error: Optional is only JSONEncodable if Wrapped is: file Apollo/JSONStandardTypeConversions.swift, line 109

Versions

Please fill in the versions you're currently using:

  • apollo-ios SDK version: 0.37
  • Xcode version: 12.2
  • Swift version: 5.3
  • Package manager: Swift Package Manager

Steps to reproduce

Schema:

type Query {
  translations(language: String!, platforms: [TranslationPlatform]!, version: String): JSON
}

Typealias for JSON

public typealias JSON = [String: Any?]

Query:

query getTranslations($language: String!, $platforms: [TranslationPlatform]!, $version: String) {
      translations(language: $language, platforms: $platforms, version: $version)
  }

Response Handling:

ApolloService.shared.apollo.fetch(query: translations, cachePolicy: .fetchIgnoringCacheData) { (result) in
        switch result {
        case .success(let result):
          if result.errors == nil {
            guard let dictionary = result.data?.jsonObject["translations"] as? [String: String] else {
              return callback()
            }
      ....
   }
}

Response format

{
    "data": {
        "translations": {
            "CANCEL": "Cancel",
            "CLOSE": "Close",
            "CREATE": "Create"
            ....
       }
}

It crashes when executing jsonObject. With previous versions, everything was working fine.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions