Skip to content
Merged
Changes from 2 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
33 changes: 31 additions & 2 deletions Sources/Apollo/RequestCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,22 @@ public protocol RequestCreator {
}

extension RequestCreator {
/// Creates a `GraphQLMap` out of the passed-in operation
///
/// - Parameters:
/// - operation: The operation to use
/// - Returns: The created `GraphQLMap`
public func requestBody<Operation: GraphQLOperation>(for operation: Operation) -> GraphQLMap {
return requestBody(for: operation, sendOperationIdentifiers: false)
Comment thread
designatednerd marked this conversation as resolved.
Outdated
}

/// Creates a `GraphQLMap` out of the passed-in operation
///
/// - Parameters:
/// - operation: The operation to use
/// - sendOperationIdentifiers: Whether or not to send operation identifiers. Defaults to false.
/// - Returns: The created `GraphQLMap`
public func requestBody<Operation: GraphQLOperation>(for operation: Operation, sendOperationIdentifiers: Bool = false) -> GraphQLMap {
public func requestBody<Operation: GraphQLOperation>(for operation: Operation, sendOperationIdentifiers: Bool) -> GraphQLMap {
var body: GraphQLMap = [
"variables": operation.variables,
"operationName": operation.operationName,
Expand All @@ -52,6 +61,26 @@ extension RequestCreator {
return body
}

/// Creates multi-part form data to send with a request
///
/// - Parameters:
/// - operation: The operation to create the data for.
/// - files: An array of files to use.
/// - sendOperationIdentifiers: True if operation identifiers should be sent, false if not.
/// - serializationFormat: The format to use to serialize data.
/// - Returns: The created form data
/// - Throws: Errors creating or loading the form data
public func requestMultipartFormData<Operation: GraphQLOperation>(for operation: Operation,
files: [GraphQLFile],
sendOperationIdentifiers: Bool,
serializationFormat: JSONSerializationFormat.Type) throws -> MultipartFormData {
return try requestMultipartFormData(for: operation,
files: files,
sendOperationIdentifiers: sendOperationIdentifiers,
serializationFormat: serializationFormat,
manualBoundary: nil)
Comment thread
designatednerd marked this conversation as resolved.
Outdated
}

/// Creates multi-part form data to send with a request
///
/// - Parameters:
Expand All @@ -66,7 +95,7 @@ extension RequestCreator {
files: [GraphQLFile],
sendOperationIdentifiers: Bool,
serializationFormat: JSONSerializationFormat.Type,
manualBoundary: String? = nil) throws -> MultipartFormData {
manualBoundary: String?) throws -> MultipartFormData {
let formData: MultipartFormData

if let boundary = manualBoundary {
Expand Down