Skip to content

Commit

Permalink
Merge pull request #1962 from nsivertsen/nsivertsen/httpheader-public…
Browse files Browse the repository at this point in the history
…-initializer

Make initializer for ApolloSchemaDownloadConfiguration.HTTPHeader public
  • Loading branch information
designatednerd authored Sep 24, 2021
2 parents 4efd35f + a3e72bf commit d898967
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 34 deletions.
12 changes: 8 additions & 4 deletions Apollo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
9BAEEC01234BB8FD00808306 /* ApolloCodegenLib.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9B7B6F47233C26D100F32205 /* ApolloCodegenLib.framework */; };
9BAEEC10234BB95B00808306 /* FileManagerExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BAEEC0D234BB95B00808306 /* FileManagerExtensionsTests.swift */; };
9BAEEC15234C132600808306 /* CLIExtractorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BAEEC14234C132600808306 /* CLIExtractorTests.swift */; };
9BAEEC17234C275600808306 /* ApolloSchemaTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BAEEC16234C275600808306 /* ApolloSchemaTests.swift */; };
9BAEEC17234C275600808306 /* ApolloSchemaPublicTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BAEEC16234C275600808306 /* ApolloSchemaPublicTests.swift */; };
9BAEEC19234C297800808306 /* ApolloCodegenTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BAEEC18234C297800808306 /* ApolloCodegenTests.swift */; };
9BC139A424EDCA6C00876D29 /* InterceptorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BC139A224EDCA4400876D29 /* InterceptorTests.swift */; };
9BC139A624EDCAD900876D29 /* BlindRetryingTestInterceptor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9BC139A524EDCAD900876D29 /* BlindRetryingTestInterceptor.swift */; };
Expand Down Expand Up @@ -250,6 +250,7 @@
DED46051261CEAD20086EF63 /* StarWarsAPI.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9FCE2CFA1E6C213D00E34457 /* StarWarsAPI.framework */; };
E616B6D126C3335600DB049E /* ExecutionTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E616B6D026C3335600DB049E /* ExecutionTests.swift */; };
E61DD76526D60C1800C41614 /* SQLiteDotSwiftDatabaseBehaviorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E61DD76426D60C1800C41614 /* SQLiteDotSwiftDatabaseBehaviorTests.swift */; };
E657CDBA26FD01D4005834D6 /* ApolloSchemaInternalTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E657CDB926FD01D4005834D6 /* ApolloSchemaInternalTests.swift */; };
E6630B8C26F0639B002D9E41 /* MockNetworkSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6D79AB926EC05290094434A /* MockNetworkSession.swift */; };
E6630B8E26F071F9002D9E41 /* SchemaRegistryApolloSchemaDownloaderTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = E6630B8D26F071F9002D9E41 /* SchemaRegistryApolloSchemaDownloaderTests.swift */; };
E6C4267B26F16CB400904AD2 /* introspection_response.json in Resources */ = {isa = PBXBuildFile; fileRef = E6C4267A26F16CB400904AD2 /* introspection_response.json */; };
Expand Down Expand Up @@ -639,7 +640,7 @@
9BAEEC0D234BB95B00808306 /* FileManagerExtensionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileManagerExtensionsTests.swift; sourceTree = "<group>"; };
9BAEEC11234BBA9200808306 /* CodegenTestHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodegenTestHelper.swift; sourceTree = "<group>"; };
9BAEEC14234C132600808306 /* CLIExtractorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CLIExtractorTests.swift; sourceTree = "<group>"; };
9BAEEC16234C275600808306 /* ApolloSchemaTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApolloSchemaTests.swift; sourceTree = "<group>"; };
9BAEEC16234C275600808306 /* ApolloSchemaPublicTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApolloSchemaPublicTests.swift; sourceTree = "<group>"; };
9BAEEC18234C297800808306 /* ApolloCodegenTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApolloCodegenTests.swift; sourceTree = "<group>"; };
9BB4F5B12581AA50004F0BD6 /* CacheDependentInterceptorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CacheDependentInterceptorTests.swift; sourceTree = "<group>"; };
9BC139A224EDCA4400876D29 /* InterceptorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InterceptorTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -818,6 +819,7 @@
DED45FB3261CDEC60086EF63 /* Apollo-CodegenTestPlan.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Apollo-CodegenTestPlan.xctestplan"; sourceTree = "<group>"; };
E616B6D026C3335600DB049E /* ExecutionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExecutionTests.swift; sourceTree = "<group>"; };
E61DD76426D60C1800C41614 /* SQLiteDotSwiftDatabaseBehaviorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SQLiteDotSwiftDatabaseBehaviorTests.swift; sourceTree = "<group>"; };
E657CDB926FD01D4005834D6 /* ApolloSchemaInternalTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApolloSchemaInternalTests.swift; sourceTree = "<group>"; };
E6630B8D26F071F9002D9E41 /* SchemaRegistryApolloSchemaDownloaderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SchemaRegistryApolloSchemaDownloaderTests.swift; sourceTree = "<group>"; };
E6C4267A26F16CB400904AD2 /* introspection_response.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = introspection_response.json; sourceTree = "<group>"; };
E6D79AB626E97D0D0094434A /* URLDownloaderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLDownloaderTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1241,7 +1243,8 @@
9F1A96AE258F367100A06EEB /* Frontend */,
9B8110A623A1994000688AC4 /* SourcePackages */,
E6BE04ED26F11B3500CF858D /* Resources */,
9BAEEC16234C275600808306 /* ApolloSchemaTests.swift */,
E657CDB926FD01D4005834D6 /* ApolloSchemaInternalTests.swift */,
9BAEEC16234C275600808306 /* ApolloSchemaPublicTests.swift */,
9BAEEC18234C297800808306 /* ApolloCodegenTests.swift */,
9B518C88235F8AD4004C426D /* CLIDownloaderTests.swift */,
9BAEEC14234C132600808306 /* CLIExtractorTests.swift */,
Expand Down Expand Up @@ -2524,13 +2527,14 @@
buildActionMask = 2147483647;
files = (
9BAEEC10234BB95B00808306 /* FileManagerExtensionsTests.swift in Sources */,
9BAEEC17234C275600808306 /* ApolloSchemaTests.swift in Sources */,
9BAEEC17234C275600808306 /* ApolloSchemaPublicTests.swift in Sources */,
9F62DFAE2590557F00E6E808 /* DocumentParsingAndValidationTests.swift in Sources */,
9F62E0102590728000E6E808 /* CompilationTests.swift in Sources */,
9F62DFBF2590560000E6E808 /* Helpers.swift in Sources */,
9B8C3FB5248DA3E000707B13 /* URLExtensionsTests.swift in Sources */,
9B518C8D235F8B9E004C426D /* CLIDownloaderTests.swift in Sources */,
9FDE0731258F3AA100DC0CA5 /* SchemaLoadingTests.swift in Sources */,
E657CDBA26FD01D4005834D6 /* ApolloSchemaInternalTests.swift in Sources */,
E6D79AB826E9D59C0094434A /* URLDownloaderTests.swift in Sources */,
9F62DF8E2590539A00E6E808 /* SchemaIntrospectionTests.swift in Sources */,
9B68F0552416B33300E97318 /* LineByLineComparison.swift in Sources */,
Expand Down
13 changes: 9 additions & 4 deletions Sources/ApolloCodegenLib/ApolloSchemaDownloadConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,21 @@ public struct ApolloSchemaDownloadConfiguration {
public var debugDescription: String {
"\(key): \(value)"
}

public init(key: String, value: String) {
self.key = key
self.value = value
}
}

/// How to download your schema. Supports the Apollo Registry and GraphQL Introspection methods.
let downloadMethod: DownloadMethod
public let downloadMethod: DownloadMethod
/// The maximum time to wait before indicating that the download timed out, in seconds. Defaults to 30 seconds.
let downloadTimeout: Double
public let downloadTimeout: Double
/// Any additional headers to include when retrieving your schema. Defaults to nil.
let headers: [HTTPHeader]
public let headers: [HTTPHeader]
/// The URL of the folder in which the downloaded schema should be written.
let outputURL: URL
public let outputURL: URL

/// Designated Initializer
///
Expand Down
31 changes: 31 additions & 0 deletions Tests/ApolloCodegenTests/ApolloSchemaInternalTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import XCTest
import ApolloTestSupport
import ApolloCodegenTestSupport
@testable import ApolloCodegenLib

class ApolloSchemaInternalTests: XCTestCase {
func testFormatConversion_givenIntrospectionJSON_shouldOutputValidSDL() throws {
let bundle = Bundle(for: type(of: self))
guard let jsonURL = bundle.url(forResource: "introspection_response", withExtension: "json") else {
throw XCTFailure("Missing resource file!", file: #file, line: #line)
}

try FileManager.default.apollo.createFolderIfNeeded(at: CodegenTestHelper.outputFolderURL())
let configuration = ApolloSchemaDownloadConfiguration(using: .introspection(endpointURL: TestURL.mockPort8080.url),
outputFolderURL: CodegenTestHelper.outputFolderURL())

try ApolloSchemaDownloader.convertFromIntrospectionJSONToSDLFile(jsonFileURL: jsonURL, configuration: configuration)
XCTAssertTrue(FileManager.default.apollo.fileExists(at: configuration.outputURL))

let frontend = try ApolloCodegenFrontend()
let source = try frontend.makeSource(from: configuration.outputURL)
let schema = try frontend.loadSchemaFromSDL(source)

let authorType = try schema.getType(named: "Author")
XCTAssertEqual(authorType?.name, "Author")

let postType = try schema.getType(named: "Post")
XCTAssertEqual(postType?.name, "Post")
}
}

Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import XCTest
import ApolloTestSupport
import ApolloCodegenTestSupport
@testable import ApolloCodegenLib
import ApolloCodegenLib

class ApolloSchemaTests: XCTestCase {
class ApolloSchemaPublicTests: XCTestCase {
private var defaultOutputURL: URL {
return CodegenTestHelper.outputFolderURL()
.appendingPathComponent("schema.graphqls")
Expand Down Expand Up @@ -51,29 +51,5 @@ class ApolloSchemaTests: XCTestCase {
let expectedOutputURL = sourceRoot.appendingPathComponent("\(schemaFileName).graphqls")
XCTAssertEqual(configuration.outputURL, expectedOutputURL)
}

func testFormatConversion_givenIntrospectionJSON_shouldOutputValidSDL() throws {
let bundle = Bundle(for: type(of: self))
guard let jsonURL = bundle.url(forResource: "introspection_response", withExtension: "json") else {
throw XCTFailure("Missing resource file!", file: #file, line: #line)
}

try FileManager.default.apollo.createFolderIfNeeded(at: CodegenTestHelper.outputFolderURL())
let configuration = ApolloSchemaDownloadConfiguration(using: .introspection(endpointURL: TestURL.mockPort8080.url),
outputFolderURL: CodegenTestHelper.outputFolderURL())

try ApolloSchemaDownloader.convertFromIntrospectionJSONToSDLFile(jsonFileURL: jsonURL, configuration: configuration)
XCTAssertTrue(FileManager.default.apollo.fileExists(at: configuration.outputURL))

let frontend = try ApolloCodegenFrontend()
let source = try frontend.makeSource(from: configuration.outputURL)
let schema = try frontend.loadSchemaFromSDL(source)

let authorType = try schema.getType(named: "Author")
XCTAssertEqual(authorType?.name, "Author")

let postType = try schema.getType(named: "Post")
XCTAssertEqual(postType?.name, "Post")
}
}

0 comments on commit d898967

Please sign in to comment.