Skip to content

Instantly share code, notes, and snippets.

View andr3a88's full-sized avatar

Andrea Stevanato andr3a88

View GitHub Profile
@andr3a88
andr3a88 / AnyEncodable.swift
Created February 27, 2024 17:51
Using array of mixed Encodable types (in Swift)
import UIKit
/// A type eraser to erase the concrete types of your encodable objects
struct AnyEncodable: Encodable {
private let encodeClosure: (Encoder) throws -> Void
init<T: Encodable>(_ value: T) {
encodeClosure = { encoder in
try value.encode(to: encoder)
}
@andr3a88
andr3a88 / AppSyncRequestBodyCreator.swift
Last active August 30, 2024 09:59
Apollo iOS with AppSync custom body request: AppSyncRequestBodyCreator
/// Creates an AWS AppSync-compatible RequestBody `payload` for subscriptions.
/// This is necessary due to the different payload used by Apollo
/// Credit to:
/// - https://community.apollographql.com/t/using-apollo-with-appsync-directly-on-ios/324/4
/// - https://docs.aws.amazon.com/appsync/latest/devguide/real-time-websocket-client.html#header-parameter-format-based-on-appsync-api-authorization-mode
/// - https://github.com/lingfengmarskey/NetworkSample
///
/// AppSync payload:
/// {
/// "id": "subscriptionId",