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

Conversation

martijnwalraven
Copy link
Contributor

This fixes #1255 by adding an extension method to Optional that implements GraphQLInputValue.evaluate(with:) by invoking that same method on the wrapped value. Without it, we'd be treating an optional GraphQLVariable as an optional JSONEncodable, which leads to a runtime crash because GraphQLVariable does not in fact conform to JSONEncodable.

All this should really be cleaned up by adopting conditional conformances (which weren't available when this was originally written), but that turns out to lead to quite the rabbit hole of issues so that'll have to wait.

This fixes apollographql#1255 by adding an extension method to `Optional` that implements `GraphQLInputValue.evaluate(with:)` by invoking that same method on the wrapped value. Without it, we'd be treating an optional `GraphQLVariable` as an optional `JSONEncodable`, which leads to a runtime crash because `GraphQLVariable` does not in fact conform to `JSONEncodable`.

All this should really be cleaned up by adopting conditional conformances (which weren't available when this was originally written), but that turns out to lead to quite the rabbit hole of issues so that'll have to wait.
@designatednerd
Copy link
Contributor

You're the best @martijnwalraven!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fatal error: Optional is only JSONEncodable if Wrapped is
2 participants