forked from apollographql/apollo-ios
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApolloSchemaOptions.swift
More file actions
70 lines (58 loc) · 2.37 KB
/
ApolloSchemaOptions.swift
File metadata and controls
70 lines (58 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import Foundation
/// Options for running the Apollo Schema Downloader.
public struct ApolloSchemaOptions {
/// The type of schema file to download
public enum SchemaFileType: String {
case json
case schemaDefinitionLanguage = "graphql"
}
let apiKey: String?
let endpointURL: URL
let header: String?
let outputURL: URL
let downloadTimeout: Double
/// Designated Initializer
///
/// - Parameters:
/// - schemaFileName: The name, without an extension, for your schema file. Defaults to `"schema"`
/// - schemaFileType: The `SchemaFileType` to download the schema as. Defaults to `.json`.
/// - apiKey: [optional] The API key to use when retrieving your schema. Defaults to nil.
/// - endpointURL: The endpoint to hit to download your schema.
/// - header: [optional] Any additional headers to include when retrieving your schema. Defaults to nil
/// - outputFolderURL: The URL of the folder in which the downloaded schema should be written
/// - downloadTimeout: The maximum time to wait before indicating that the download timed out, in seconds. Defaults to 30 seconds.
public init(schemaFileName: String = "schema",
schemaFileType: SchemaFileType = .json,
apiKey: String? = nil,
endpointURL: URL,
header: String? = nil,
outputFolderURL: URL,
downloadTimeout: Double = 30.0) {
self.apiKey = apiKey
self.header = header
self.endpointURL = endpointURL
self.outputURL = outputFolderURL.appendingPathComponent("\(schemaFileName).\(schemaFileType.rawValue)")
self.downloadTimeout = downloadTimeout
}
var arguments: [String] {
var arguments = [
"client:download-schema",
"--endpoint=\(self.endpointURL.absoluteString)"
]
if let key = self.apiKey {
arguments.append("--key=\(key)")
}
arguments.append("'\(outputURL.path)'")
// Header argument must be last in the CLI command due to an underlying issue in the Oclif framework.
// See: https://github.com/apollographql/apollo-tooling/issues/844#issuecomment-547143805
if let header = self.header {
arguments.append("--header='\(header)'")
}
return arguments
}
}
extension ApolloSchemaOptions: CustomDebugStringConvertible {
public var debugDescription: String {
self.arguments.joined(separator: "\n")
}
}