Skip to content
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

Avoid crash when evaluating optional variables #1262

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Sources/Apollo/GraphQLInputValue.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,19 @@ extension JSONEncodable {
}
}

extension Optional: GraphQLInputValue {
public func evaluate(with variables: [String: JSONEncodable]?) throws -> JSONValue {
switch self {
case .none:
return NSNull()
case .some(let wrapped as GraphQLInputValue):
return try wrapped.evaluate(with: variables)
default:
fatalError("Optional is only GraphQLInputValue if Wrapped is")
}
}
}

extension Dictionary: GraphQLInputValue {
public func evaluate(with variables: [String: JSONEncodable]?) throws -> JSONValue {
return try evaluate(with: variables) as JSONObject
Expand Down