Skip to content
Open
Show file tree
Hide file tree
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
28 changes: 18 additions & 10 deletions Sources/MoveSingleAPISwift/GraphQL/GraphQLClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ public enum GraphQLEnvironment {
}

protocol GraphQLClient {
func configure(apiKey: String, environment: GraphQLEnvironment, certificates: [Data]?)
func configure(apiKey: String, environment: GraphQLEnvironment, certificates: [Data]?, deviceLabel: String)
func registerForNotifications(clientID: String, events: [NotificationEvents]) async throws -> MoveSingleGraphQL.WebhookEndpointMutation.Data.UpsertWebhookEndpoint
func createFile(type: String, metadata: String) async throws -> MoveSingleGraphQL.CreateFileMutation.Data.File
func getFile(id: String) async throws -> MoveSingleGraphQL.FileQuery.Data.File
func createTake(videoFileId: String, moveFileId: String, metadata: String) async throws -> MoveSingleGraphQL.CreateTakeMutation.Data.Take
func createTake(videoFileId: String, moveFileId: String, metadata: String) async throws -> MoveSingleGraphQL.CreateSingleCamTakeMutation.Data.Take
func getTake(id: String) async throws -> MoveSingleGraphQL.TakeQuery.Data.Take
func createJob(takeId: String, metadata: String) async throws -> MoveSingleGraphQL.CreateJobMutation.Data.Job
func createJob(takeId: String, metadata: String) async throws -> MoveSingleGraphQL.CreateSingleCamJobMutation.Data.Job
func getJob(id: String) async throws -> MoveSingleGraphQL.JobQuery.Data.Job
func generateShareCode(fileId: String) async throws -> MoveSingleGraphQL.GenerateShareCodeMutation.Data.ShareCode
}

extension GraphQLClient {
func configure(apiKey: String, environment: GraphQLEnvironment = .production, certificates: [Data]?) {
configure(apiKey: apiKey, environment: environment, certificates: certificates)
func configure(apiKey: String, environment: GraphQLEnvironment = .production, certificates: [Data]?, deviceLabel: String) {
configure(apiKey: apiKey, environment: environment, certificates: certificates, deviceLabel: deviceLabel)
}
}

Expand All @@ -57,10 +57,12 @@ final class GraphQLClientImpl: GraphQLClient {
private var apollo: ApolloClient?
private var apikey: String?
private var environment: GraphQLEnvironment?
private var deviceLabel: String?

func configure(apiKey: String, environment: GraphQLEnvironment, certificates: [Data]?) {
func configure(apiKey: String, environment: GraphQLEnvironment, certificates: [Data]?, deviceLabel: String) {
self.apikey = apiKey
self.environment = environment
self.deviceLabel = deviceLabel
let client = SessionClient(certificates: certificates)
let cache = InMemoryNormalizedCache()
let store = ApolloStore(cache: cache)
Expand Down Expand Up @@ -136,10 +138,16 @@ final class GraphQLClientImpl: GraphQLClient {
}
}

func createTake(videoFileId: String, moveFileId: String, metadata: String) async throws -> MoveSingleGraphQL.CreateTakeMutation.Data.Take {
func createTake(videoFileId: String, moveFileId: String, metadata: String) async throws -> MoveSingleGraphQL.CreateSingleCamTakeMutation.Data.Take {
return try await withCheckedThrowingContinuation { continuation in
guard let apollo = apollo else { continuation.resume(throwing: GraphQLClientError.notConfigured); return }
apollo.perform(mutation: MoveSingleGraphQL.CreateTakeMutation(videoFileId: videoFileId, moveFileId: moveFileId, metadata: metadata)) { result in

let sources: [MoveSingleGraphQL.SourceInput]? = [
MoveSingleGraphQL.SourceInput(deviceLabel: deviceLabel ?? "", fileId: videoFileId, format: .case(.mp4)),
MoveSingleGraphQL.SourceInput(deviceLabel: deviceLabel ?? "", fileId: moveFileId, format: .case(.move))
]

apollo.perform(mutation: MoveSingleGraphQL.CreateSingleCamTakeMutation(sources: sources.gqlWrapped, metadata: metadata)) { result in
switch result {
case .success(let result):
if let take = result.data?.take {
Expand Down Expand Up @@ -176,10 +184,10 @@ final class GraphQLClientImpl: GraphQLClient {
}
}

func createJob(takeId: String, metadata: String = "") async throws -> MoveSingleGraphQL.CreateJobMutation.Data.Job {
func createJob(takeId: String, metadata: String = "") async throws -> MoveSingleGraphQL.CreateSingleCamJobMutation.Data.Job {
return try await withCheckedThrowingContinuation { continuation in
guard let apollo = apollo else { continuation.resume(throwing: GraphQLClientError.notConfigured); return }
apollo.perform(mutation: MoveSingleGraphQL.CreateJobMutation(takeId: takeId, metadata: metadata)) { result in
apollo.perform(mutation: MoveSingleGraphQL.CreateSingleCamJobMutation(takeId: takeId, metadata: metadata)) { result in
switch result {
case .success(let result):
if let job = result.data?.job {
Expand Down
20 changes: 20 additions & 0 deletions Sources/MoveSingleAPISwift/GraphQL/Utils/Optionals+GraphQL.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// File.swift
//
//
// Created by Move.ai on 18/07/2024.
//

import Foundation
import AppClip

extension Optional {
var gqlWrapped: GraphQLNullable<Wrapped> {
switch self {
case .none:
return .null
case .some(let wrapped):
return .some(wrapped)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
@_exported import ApolloAPI

extension MoveSingleGraphQL {
class CreateJobMutation: GraphQLMutation {
static let operationName: String = "CreateJob"
class CreateSingleCamJobMutation: GraphQLMutation {
static let operationName: String = "CreateSingleCamJob"
static let operationDocument: ApolloAPI.OperationDocument = .init(
definition: .init(
#"mutation CreateJob($takeId: String!, $metadata: AWSJSON!) { job: createJob(takeId: $takeId, metadata: $metadata) { __typename id state } }"#
#"mutation CreateSingleCamJob($takeId: String!, $metadata: AWSJSON!) { job: createSingleCamJob(takeId: $takeId, metadata: $metadata) { __typename id state } }"#
))

public var takeId: String
Expand All @@ -33,7 +33,7 @@ extension MoveSingleGraphQL {

static var __parentType: ApolloAPI.ParentType { MoveSingleGraphQL.Objects.Mutation }
static var __selections: [ApolloAPI.Selection] { [
.field("createJob", alias: "job", Job.self, arguments: [
.field("createSingleCamJob", alias: "job", Job.self, arguments: [
"takeId": .variable("takeId"),
"metadata": .variable("metadata")
]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,26 @@
@_exported import ApolloAPI

extension MoveSingleGraphQL {
class CreateTakeMutation: GraphQLMutation {
static let operationName: String = "CreateTake"
class CreateSingleCamTakeMutation: GraphQLMutation {
static let operationName: String = "CreateSingleCamTake"
static let operationDocument: ApolloAPI.OperationDocument = .init(
definition: .init(
#"mutation CreateTake($videoFileId: String!, $moveFileId: String!, $metadata: AWSJSON!) { take: createTake( videoFileId: $videoFileId additionalFileIds: [{key: MOVE, fileId: $moveFileId}] metadata: $metadata ) { __typename id } }"#
#"mutation CreateSingleCamTake($sources: [SourceInput!], $metadata: AWSJSON!) { take: createSingleCamTake(sources: $sources, metadata: $metadata) { __typename id } }"#
))

public var videoFileId: String
public var moveFileId: String
public var sources: GraphQLNullable<[SourceInput]>
public var metadata: AWSJSON

public init(
videoFileId: String,
moveFileId: String,
sources: GraphQLNullable<[SourceInput]>,
metadata: AWSJSON
) {
self.videoFileId = videoFileId
self.moveFileId = moveFileId
self.sources = sources
self.metadata = metadata
}

public var __variables: Variables? { [
"videoFileId": videoFileId,
"moveFileId": moveFileId,
"sources": sources,
"metadata": metadata
] }

Expand All @@ -37,17 +33,13 @@ extension MoveSingleGraphQL {

static var __parentType: ApolloAPI.ParentType { MoveSingleGraphQL.Objects.Mutation }
static var __selections: [ApolloAPI.Selection] { [
.field("createTake", alias: "take", Take.self, arguments: [
"videoFileId": .variable("videoFileId"),
"additionalFileIds": [[
"key": "MOVE",
"fileId": .variable("moveFileId")
]],
.field("createSingleCamTake", alias: "take", Take.self, arguments: [
"sources": .variable("sources"),
"metadata": .variable("metadata")
]),
] }

/// Create a take from an existing file.
/// Create take from a single camera.
var take: Take { __data["take"] }

/// Take
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ extension MoveSingleGraphQL {
static var __parentType: ApolloAPI.ParentType { MoveSingleGraphQL.Objects.AdditionalFile }
static var __selections: [ApolloAPI.Selection] { [
.field("__typename", String.self),
.field("key", String.self),
.field("key", String?.self),
.field("file", File.self),
] }

/// Type of additional file
var key: String { __data["key"] }
var key: String? { __data["key"] }
/// Reference to the additional file object
var file: File { __data["file"] }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ extension MoveSingleGraphQL {
.field("getTake", alias: "take", Take.self, arguments: ["takeId": .variable("takeId")]),
] }

/// Get a take with give id.
/// Get a take with given id.
var take: Take { __data["take"] }

/// Take
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// @generated
// This file was automatically generated and should not be edited.

import ApolloAPI

extension MoveSingleGraphQL {
enum SourceFormat: String, EnumType {
case move = "MOVE"
case mp4 = "MP4"
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// @generated
// This file was automatically generated and should not be edited.

import ApolloAPI

extension MoveSingleGraphQL {
/// The camera settings for the source input.
struct CameraSettingsInput: InputObject {
private(set) var __data: InputDict

init(_ data: InputDict) {
__data = data
}

init(
lens: String
) {
__data = InputDict([
"lens": lens
])
}

/// The name of the lens that was used to create the capture inputs.
var lens: String {
get { __data["lens"] }
set { __data["lens"] = newValue }
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// @generated
// This file was automatically generated and should not be edited.

import ApolloAPI

extension MoveSingleGraphQL {
/// The start and end time of the clip window that should be processed. startTime should be before endTime.
struct ClipWindowInput: InputObject {
private(set) var __data: InputDict

init(_ data: InputDict) {
__data = data
}

init(
endTime: Double,
startTime: Double
) {
__data = InputDict([
"endTime": endTime,
"startTime": startTime
])
}

/// The end time of the clip window to be processed.
var endTime: Double {
get { __data["endTime"] }
set { __data["endTime"] = newValue }
}

/// The start time of the clip window to be processed.
var startTime: Double {
get { __data["startTime"] }
set { __data["startTime"] = newValue }
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// @generated
// This file was automatically generated and should not be edited.

import ApolloAPI

extension MoveSingleGraphQL {
/// The source device, file and camera settings to use for a take.
struct SourceInput: InputObject {
private(set) var __data: InputDict

init(_ data: InputDict) {
__data = data
}

init(
cameraSettings: GraphQLNullable<CameraSettingsInput> = nil,
clipWindow: GraphQLNullable<ClipWindowInput> = nil,
deviceLabel: String,
fileId: String,
format: GraphQLEnum<SourceFormat>
) {
__data = InputDict([
"cameraSettings": cameraSettings,
"clipWindow": clipWindow,
"deviceLabel": deviceLabel,
"fileId": fileId,
"format": format
])
}

/// Settings for the camera that was used to capture this source.
var cameraSettings: GraphQLNullable<CameraSettingsInput> {
get { __data["cameraSettings"] }
set { __data["cameraSettings"] = newValue }
}

/// The clip window that should be processed. If not provided the entire source will be processed.
var clipWindow: GraphQLNullable<ClipWindowInput> {
get { __data["clipWindow"] }
set { __data["clipWindow"] = newValue }
}

/// A user defined label for the device this source input was captured on.
var deviceLabel: String {
get { __data["deviceLabel"] }
set { __data["deviceLabel"] = newValue }
}

/// Reference to the file object of this source.
var fileId: String {
get { __data["fileId"] }
set { __data["fileId"] = newValue }
}

/// The file format of the source.
var format: GraphQLEnum<SourceFormat> {
get { __data["format"] }
set { __data["format"] = newValue }
}
}

}
3 changes: 2 additions & 1 deletion Sources/MoveSingleAPISwift/MoveSingleAPISwift.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ public final class Move {
apiKey: String,
environment: GraphQLEnvironment = .production,
outputDirectory: String = "",
deviceLabel: String,
graphQLCertificates: [Data]? = nil,
fileStorageCertificates: [Data]? = nil
) {
sessionClient.configure(certificates: fileStorageCertificates)
fileStorage.configure(outputDirectory: outputDirectory)
graphQLClient.configure(apiKey: apiKey, environment: environment, certificates: graphQLCertificates)
graphQLClient.configure(apiKey: apiKey, environment: environment, certificates: graphQLCertificates, deviceLabel: deviceLabel)
}

public func createTake(
Expand Down
4 changes: 2 additions & 2 deletions Sources/MoveSingleAPISwift/Take/Job.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ public actor Job {
if state == .finished {
var files: [FileType: File] = [:]
for output in jobResult.outputs ?? [] {
if let output = output,
let type = FileType(from: output.key) {
if let output = output, let key = output.key,
let type = FileType(from: key) {
let file = File(type: type, remoteID: output.file.id)
files[type] = file
}
Expand Down
Loading
Loading