diff --git a/Apollo.xcodeproj/project.pbxproj b/Apollo.xcodeproj/project.pbxproj index 36935d4cd7..1461ff5f5c 100644 --- a/Apollo.xcodeproj/project.pbxproj +++ b/Apollo.xcodeproj/project.pbxproj @@ -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 */; }; @@ -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 */; }; @@ -639,7 +640,7 @@ 9BAEEC0D234BB95B00808306 /* FileManagerExtensionsTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = FileManagerExtensionsTests.swift; sourceTree = ""; }; 9BAEEC11234BBA9200808306 /* CodegenTestHelper.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodegenTestHelper.swift; sourceTree = ""; }; 9BAEEC14234C132600808306 /* CLIExtractorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CLIExtractorTests.swift; sourceTree = ""; }; - 9BAEEC16234C275600808306 /* ApolloSchemaTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApolloSchemaTests.swift; sourceTree = ""; }; + 9BAEEC16234C275600808306 /* ApolloSchemaPublicTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApolloSchemaPublicTests.swift; sourceTree = ""; }; 9BAEEC18234C297800808306 /* ApolloCodegenTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ApolloCodegenTests.swift; sourceTree = ""; }; 9BB4F5B12581AA50004F0BD6 /* CacheDependentInterceptorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CacheDependentInterceptorTests.swift; sourceTree = ""; }; 9BC139A224EDCA4400876D29 /* InterceptorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = InterceptorTests.swift; sourceTree = ""; }; @@ -818,6 +819,7 @@ DED45FB3261CDEC60086EF63 /* Apollo-CodegenTestPlan.xctestplan */ = {isa = PBXFileReference; lastKnownFileType = text; path = "Apollo-CodegenTestPlan.xctestplan"; sourceTree = ""; }; E616B6D026C3335600DB049E /* ExecutionTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ExecutionTests.swift; sourceTree = ""; }; E61DD76426D60C1800C41614 /* SQLiteDotSwiftDatabaseBehaviorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SQLiteDotSwiftDatabaseBehaviorTests.swift; sourceTree = ""; }; + E657CDB926FD01D4005834D6 /* ApolloSchemaInternalTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ApolloSchemaInternalTests.swift; sourceTree = ""; }; E6630B8D26F071F9002D9E41 /* SchemaRegistryApolloSchemaDownloaderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SchemaRegistryApolloSchemaDownloaderTests.swift; sourceTree = ""; }; E6C4267A26F16CB400904AD2 /* introspection_response.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = introspection_response.json; sourceTree = ""; }; E6D79AB626E97D0D0094434A /* URLDownloaderTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = URLDownloaderTests.swift; sourceTree = ""; }; @@ -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 */, @@ -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 */, diff --git a/Sources/ApolloCodegenLib/ApolloSchemaDownloadConfiguration.swift b/Sources/ApolloCodegenLib/ApolloSchemaDownloadConfiguration.swift index 08a0802928..04ec1789df 100644 --- a/Sources/ApolloCodegenLib/ApolloSchemaDownloadConfiguration.swift +++ b/Sources/ApolloCodegenLib/ApolloSchemaDownloadConfiguration.swift @@ -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 /// diff --git a/Tests/ApolloCodegenTests/ApolloSchemaInternalTests.swift b/Tests/ApolloCodegenTests/ApolloSchemaInternalTests.swift new file mode 100644 index 0000000000..6c40d45bb4 --- /dev/null +++ b/Tests/ApolloCodegenTests/ApolloSchemaInternalTests.swift @@ -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") + } +} + diff --git a/Tests/ApolloCodegenTests/ApolloSchemaTests.swift b/Tests/ApolloCodegenTests/ApolloSchemaPublicTests.swift similarity index 69% rename from Tests/ApolloCodegenTests/ApolloSchemaTests.swift rename to Tests/ApolloCodegenTests/ApolloSchemaPublicTests.swift index 7fac755591..5bb084669c 100644 --- a/Tests/ApolloCodegenTests/ApolloSchemaTests.swift +++ b/Tests/ApolloCodegenTests/ApolloSchemaPublicTests.swift @@ -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") @@ -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") - } }