diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 935b487cf05..c242b0146e0 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -87,7 +87,15 @@ jobs: with: name: tests-integration.zip path: diagnostics.zip - + ios-tests: + runs-on: macos-14 + steps: + - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 #v4.1.7 + - uses: actions/setup-java@99b8673ff64fbf99d8d325f52d9a5bdedb8483e9 #v4.2.1 + with: + distribution: 'temurin' + java-version: 17 + - run: /Applications/Xcode_16.2.0.app/Contents/Developer/usr/bin/xcodebuild -allowProvisioningUpdates -project tests/com.apollographql.iostest/com.apollographql.iostest.xcodeproj -configuration Debug -scheme com.apollographql.iostest -sdk iphoneos -destination name='iPhone 16' test -test-timeouts-enabled YES intellij-plugin: if: "!startsWith(github.head_ref, 'release-')" name: Build IntelliJ Plugin diff --git a/libraries/apollo-runtime/src/appleMain/kotlin/com/apollographql/apollo/network/http/DefaultHttpEngine.apple.kt b/libraries/apollo-runtime/src/appleMain/kotlin/com/apollographql/apollo/network/http/DefaultHttpEngine.apple.kt index d2321c9a2b6..6224b0a9e09 100644 --- a/libraries/apollo-runtime/src/appleMain/kotlin/com/apollographql/apollo/network/http/DefaultHttpEngine.apple.kt +++ b/libraries/apollo-runtime/src/appleMain/kotlin/com/apollographql/apollo/network/http/DefaultHttpEngine.apple.kt @@ -11,6 +11,7 @@ import kotlinx.atomicfu.locks.withLock import kotlinx.cinterop.alloc import kotlinx.cinterop.nativeHeap import kotlinx.cinterop.ptr +import kotlinx.coroutines.CancellationException import kotlinx.coroutines.suspendCancellableCoroutine import okio.Buffer import okio.BufferedSource diff --git a/libraries/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo/network/http/HttpEngine.kt b/libraries/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo/network/http/HttpEngine.kt index 69ce1c1a961..7a892419372 100644 --- a/libraries/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo/network/http/HttpEngine.kt +++ b/libraries/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo/network/http/HttpEngine.kt @@ -9,6 +9,7 @@ import com.apollographql.apollo.api.http.HttpMethod import com.apollographql.apollo.api.http.HttpRequest import com.apollographql.apollo.api.http.HttpResponse import com.apollographql.apollo.exception.ApolloNetworkException +import kotlinx.coroutines.CancellationException import okio.Closeable /** @@ -23,6 +24,7 @@ interface HttpEngine : Closeable { * * @throws [ApolloNetworkException] if a network error happens */ + @Throws(ApolloNetworkException::class, CancellationException::class) suspend fun execute(request: HttpRequest): HttpResponse @ApolloDeprecatedSince(v4_0_0) diff --git a/libraries/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo/network/http/HttpInterceptor.kt b/libraries/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo/network/http/HttpInterceptor.kt index bd4a508addd..8a30829f6c3 100644 --- a/libraries/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo/network/http/HttpInterceptor.kt +++ b/libraries/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo/network/http/HttpInterceptor.kt @@ -2,16 +2,28 @@ package com.apollographql.apollo.network.http import com.apollographql.apollo.api.http.HttpRequest import com.apollographql.apollo.api.http.HttpResponse +import com.apollographql.apollo.exception.ApolloException import com.apollographql.apollo.exception.ApolloNetworkException +import kotlinx.coroutines.CancellableContinuation +import kotlinx.coroutines.CancellationException interface HttpInterceptorChain { /** - * @throws [ApolloNetworkException] if a network error happens + * Continues with the request and call all downstream interceptors. */ + @Throws(Throwable::class) suspend fun proceed(request: HttpRequest): HttpResponse } interface HttpInterceptor { + /** + * Intercepts the request and returns a response. + * Implementation may throw in case of error. Those errors are typically + * caught by the network transport and subsequently exposed in `ApolloResponse.exception`. + * If the exception is not an instance of [ApolloException], it will be wrapped in an + * instance of [ApolloNetworkException]. + */ + @Throws(Throwable::class) suspend fun intercept(request: HttpRequest, chain: HttpInterceptorChain): HttpResponse // TODO: remove dispose diff --git a/libraries/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo/network/http/HttpNetworkTransport.kt b/libraries/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo/network/http/HttpNetworkTransport.kt index 159d349c463..4dfa8417439 100644 --- a/libraries/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo/network/http/HttpNetworkTransport.kt +++ b/libraries/apollo-runtime/src/commonMain/kotlin/com/apollographql/apollo/network/http/HttpNetworkTransport.kt @@ -29,6 +29,7 @@ import com.apollographql.apollo.mpp.currentTimeMillis import com.apollographql.apollo.network.NetworkTransport import com.benasher44.uuid.Uuid import com.benasher44.uuid.uuid4 +import kotlinx.coroutines.CancellationException import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.catch import kotlinx.coroutines.flow.emitAll @@ -62,20 +63,23 @@ private constructor( ): Flow> { return flow { val millisStart = currentTimeMillis() - var apolloException: ApolloException? = null + var throwable: Throwable? = null val httpResponse: HttpResponse? = try { DefaultHttpInterceptorChain( interceptors = interceptors + engineInterceptor, index = 0 ).proceed(httpRequest) - } catch (e: ApolloException) { - apolloException = e + } catch (t: Throwable) { + if (t is CancellationException) { + throw t + } + throwable = t null } val responses = when { httpResponse == null -> { - flowOf(errorResponse(request.operation, apolloException!!)) + flowOf(errorResponse(request.operation, throwable!!)) } httpResponse.statusCode !in 200..299 && !httpResponse.isGraphQLResponse -> { @@ -212,11 +216,11 @@ private constructor( if (jsonMerger == null) { jsonMerger = DeferredJsonMerger() } - val merged = jsonMerger!!.merge(part) - val deferredFragmentIds = jsonMerger!!.mergedFragmentIds - val isLast = !jsonMerger!!.hasNext + val merged = jsonMerger.merge(part) + val deferredFragmentIds = jsonMerger.mergedFragmentIds + val isLast = !jsonMerger.hasNext - if (jsonMerger!!.isEmptyPayload) { + if (jsonMerger.isEmptyPayload) { null } else { @Suppress("DEPRECATION") diff --git a/tests/com.apollographql.iostest/com.apollographql.iostest.xcodeproj/project.pbxproj b/tests/com.apollographql.iostest/com.apollographql.iostest.xcodeproj/project.pbxproj new file mode 100644 index 00000000000..c2c9502c344 --- /dev/null +++ b/tests/com.apollographql.iostest/com.apollographql.iostest.xcodeproj/project.pbxproj @@ -0,0 +1,475 @@ +// !$*UTF8*$! +{ + archiveVersion = 1; + classes = { + }; + objectVersion = 77; + objects = { + +/* Begin PBXContainerItemProxy section */ + 61452ED82D7734FE00E526F3 /* PBXContainerItemProxy */ = { + isa = PBXContainerItemProxy; + containerPortal = 61452EBF2D7734FA00E526F3 /* Project object */; + proxyType = 1; + remoteGlobalIDString = 61452EC62D7734FA00E526F3; + remoteInfo = com.apollographql.iostest; + }; +/* End PBXContainerItemProxy section */ + +/* Begin PBXFileReference section */ + 61452EC72D7734FA00E526F3 /* com.apollographql.iostest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = com.apollographql.iostest.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 61452ED72D7734FE00E526F3 /* com.apollographql.iostestTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = com.apollographql.iostestTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; +/* End PBXFileReference section */ + +/* Begin PBXFileSystemSynchronizedRootGroup section */ + 61452EC92D7734FA00E526F3 /* com.apollographql.iostest */ = { + isa = PBXFileSystemSynchronizedRootGroup; + path = com.apollographql.iostest; + sourceTree = ""; + }; + 61452EDA2D7734FE00E526F3 /* com.apollographql.iostestTests */ = { + isa = PBXFileSystemSynchronizedRootGroup; + path = com.apollographql.iostestTests; + sourceTree = ""; + }; +/* End PBXFileSystemSynchronizedRootGroup section */ + +/* Begin PBXFrameworksBuildPhase section */ + 61452EC42D7734FA00E526F3 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 61452ED42D7734FE00E526F3 /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXFrameworksBuildPhase section */ + +/* Begin PBXGroup section */ + 61452EBE2D7734FA00E526F3 = { + isa = PBXGroup; + children = ( + 61452EC92D7734FA00E526F3 /* com.apollographql.iostest */, + 61452EDA2D7734FE00E526F3 /* com.apollographql.iostestTests */, + 61452EC82D7734FA00E526F3 /* Products */, + ); + sourceTree = ""; + }; + 61452EC82D7734FA00E526F3 /* Products */ = { + isa = PBXGroup; + children = ( + 61452EC72D7734FA00E526F3 /* com.apollographql.iostest.app */, + 61452ED72D7734FE00E526F3 /* com.apollographql.iostestTests.xctest */, + ); + name = Products; + sourceTree = ""; + }; +/* End PBXGroup section */ + +/* Begin PBXNativeTarget section */ + 61452EC62D7734FA00E526F3 /* com.apollographql.iostest */ = { + isa = PBXNativeTarget; + buildConfigurationList = 61452EEB2D7734FE00E526F3 /* Build configuration list for PBXNativeTarget "com.apollographql.iostest" */; + buildPhases = ( + 61452EF42D7737F400E526F3 /* Compile Kotlin Framework */, + 61452EC32D7734FA00E526F3 /* Sources */, + 61452EC42D7734FA00E526F3 /* Frameworks */, + 61452EC52D7734FA00E526F3 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + ); + fileSystemSynchronizedGroups = ( + 61452EC92D7734FA00E526F3 /* com.apollographql.iostest */, + ); + name = com.apollographql.iostest; + packageProductDependencies = ( + ); + productName = com.apollographql.iostest; + productReference = 61452EC72D7734FA00E526F3 /* com.apollographql.iostest.app */; + productType = "com.apple.product-type.application"; + }; + 61452ED62D7734FE00E526F3 /* com.apollographql.iostestTests */ = { + isa = PBXNativeTarget; + buildConfigurationList = 61452EEE2D7734FE00E526F3 /* Build configuration list for PBXNativeTarget "com.apollographql.iostestTests" */; + buildPhases = ( + 61452ED32D7734FE00E526F3 /* Sources */, + 61452ED42D7734FE00E526F3 /* Frameworks */, + 61452ED52D7734FE00E526F3 /* Resources */, + ); + buildRules = ( + ); + dependencies = ( + 61452ED92D7734FE00E526F3 /* PBXTargetDependency */, + ); + fileSystemSynchronizedGroups = ( + 61452EDA2D7734FE00E526F3 /* com.apollographql.iostestTests */, + ); + name = com.apollographql.iostestTests; + packageProductDependencies = ( + ); + productName = com.apollographql.iostestTests; + productReference = 61452ED72D7734FE00E526F3 /* com.apollographql.iostestTests.xctest */; + productType = "com.apple.product-type.bundle.unit-test"; + }; +/* End PBXNativeTarget section */ + +/* Begin PBXProject section */ + 61452EBF2D7734FA00E526F3 /* Project object */ = { + isa = PBXProject; + attributes = { + BuildIndependentTargetsInParallel = 1; + LastSwiftUpdateCheck = 1620; + LastUpgradeCheck = 1620; + TargetAttributes = { + 61452EC62D7734FA00E526F3 = { + CreatedOnToolsVersion = 16.2; + }; + 61452ED62D7734FE00E526F3 = { + CreatedOnToolsVersion = 16.2; + TestTargetID = 61452EC62D7734FA00E526F3; + }; + }; + }; + buildConfigurationList = 61452EC22D7734FA00E526F3 /* Build configuration list for PBXProject "com.apollographql.iostest" */; + developmentRegion = en; + hasScannedForEncodings = 0; + knownRegions = ( + en, + Base, + ); + mainGroup = 61452EBE2D7734FA00E526F3; + minimizedProjectReferenceProxies = 1; + packageReferences = ( + ); + preferredProjectObjectVersion = 77; + productRefGroup = 61452EC82D7734FA00E526F3 /* Products */; + projectDirPath = ""; + projectRoot = ""; + targets = ( + 61452EC62D7734FA00E526F3 /* com.apollographql.iostest */, + 61452ED62D7734FE00E526F3 /* com.apollographql.iostestTests */, + ); + }; +/* End PBXProject section */ + +/* Begin PBXResourcesBuildPhase section */ + 61452EC52D7734FA00E526F3 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 61452ED52D7734FE00E526F3 /* Resources */ = { + isa = PBXResourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXResourcesBuildPhase section */ + +/* Begin PBXShellScriptBuildPhase section */ + 61452EF42D7737F400E526F3 /* Compile Kotlin Framework */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = "Compile Kotlin Framework"; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "cd \"$SRCROOT/..\"\n./gradlew :shared-framework:embedAndSignAppleFrameworkForXcode\n"; + }; +/* End PBXShellScriptBuildPhase section */ + +/* Begin PBXSourcesBuildPhase section */ + 61452EC32D7734FA00E526F3 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; + 61452ED32D7734FE00E526F3 /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + runOnlyForDeploymentPostprocessing = 0; + }; +/* End PBXSourcesBuildPhase section */ + +/* Begin PBXTargetDependency section */ + 61452ED92D7734FE00E526F3 /* PBXTargetDependency */ = { + isa = PBXTargetDependency; + target = 61452EC62D7734FA00E526F3 /* com.apollographql.iostest */; + targetProxy = 61452ED82D7734FE00E526F3 /* PBXContainerItemProxy */; + }; +/* End PBXTargetDependency section */ + +/* Begin XCBuildConfiguration section */ + 61452EE92D7734FE00E526F3 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = dwarf; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; + GCC_OPTIMIZATION_LEVEL = 0; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 18.2; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE; + MTL_FAST_MATH = YES; + ONLY_ACTIVE_ARCH = YES; + SDKROOT = iphoneos; + SWIFT_ACTIVE_COMPILATION_CONDITIONS = "DEBUG $(inherited)"; + SWIFT_OPTIMIZATION_LEVEL = "-Onone"; + }; + name = Debug; + }; + 61452EEA2D7734FE00E526F3 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = YES; + CLANG_ANALYZER_NONNULL = YES; + CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; + CLANG_CXX_LANGUAGE_STANDARD = "gnu++20"; + CLANG_ENABLE_MODULES = YES; + CLANG_ENABLE_OBJC_ARC = YES; + CLANG_ENABLE_OBJC_WEAK = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; + CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; + CLANG_WARN_DOCUMENTATION_COMMENTS = YES; + CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; + CLANG_WARN_UNREACHABLE_CODE = YES; + CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; + COPY_PHASE_STRIP = NO; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + ENABLE_NS_ASSERTIONS = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_USER_SCRIPT_SANDBOXING = YES; + GCC_C_LANGUAGE_STANDARD = gnu17; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; + GCC_WARN_UNDECLARED_SELECTOR = YES; + GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; + GCC_WARN_UNUSED_FUNCTION = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 18.2; + LOCALIZATION_PREFERS_STRING_CATALOGS = YES; + MTL_ENABLE_DEBUG_INFO = NO; + MTL_FAST_MATH = YES; + SDKROOT = iphoneos; + SWIFT_COMPILATION_MODE = wholemodule; + VALIDATE_PRODUCT = YES; + }; + name = Release; + }; + 61452EEC2D7734FE00E526F3 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"com.apollographql.iostest/Preview Content\""; + ENABLE_PREVIEWS = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = "com.apollographql.com-apollographql-iostest"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Debug; + }; + 61452EED2D7734FE00E526F3 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; + ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + DEVELOPMENT_ASSET_PATHS = "\"com.apollographql.iostest/Preview Content\""; + ENABLE_PREVIEWS = YES; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + GENERATE_INFOPLIST_FILE = YES; + INFOPLIST_KEY_UIApplicationSceneManifest_Generation = YES; + INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents = YES; + INFOPLIST_KEY_UILaunchScreen_Generation = YES; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPad = "UIInterfaceOrientationPortrait UIInterfaceOrientationPortraitUpsideDown UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + INFOPLIST_KEY_UISupportedInterfaceOrientations_iPhone = "UIInterfaceOrientationPortrait UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight"; + LD_RUNPATH_SEARCH_PATHS = ( + "$(inherited)", + "@executable_path/Frameworks", + ); + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = "com.apollographql.com-apollographql-iostest"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = YES; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + }; + name = Release; + }; + 61452EEF2D7734FE00E526F3 /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + GENERATE_INFOPLIST_FILE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 18.2; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = "com.apollographql.com-apollographql-iostestTests"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/com.apollographql.iostest.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/com.apollographql.iostest"; + }; + name = Debug; + }; + 61452EF02D7734FE00E526F3 /* Release */ = { + isa = XCBuildConfiguration; + buildSettings = { + BUNDLE_LOADER = "$(TEST_HOST)"; + CODE_SIGN_STYLE = Automatic; + CURRENT_PROJECT_VERSION = 1; + ENABLE_USER_SCRIPT_SANDBOXING = NO; + GENERATE_INFOPLIST_FILE = YES; + IPHONEOS_DEPLOYMENT_TARGET = 18.2; + MARKETING_VERSION = 1.0; + PRODUCT_BUNDLE_IDENTIFIER = "com.apollographql.com-apollographql-iostestTests"; + PRODUCT_NAME = "$(TARGET_NAME)"; + SWIFT_EMIT_LOC_STRINGS = NO; + SWIFT_VERSION = 5.0; + TARGETED_DEVICE_FAMILY = "1,2"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/com.apollographql.iostest.app/$(BUNDLE_EXECUTABLE_FOLDER_PATH)/com.apollographql.iostest"; + }; + name = Release; + }; +/* End XCBuildConfiguration section */ + +/* Begin XCConfigurationList section */ + 61452EC22D7734FA00E526F3 /* Build configuration list for PBXProject "com.apollographql.iostest" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 61452EE92D7734FE00E526F3 /* Debug */, + 61452EEA2D7734FE00E526F3 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 61452EEB2D7734FE00E526F3 /* Build configuration list for PBXNativeTarget "com.apollographql.iostest" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 61452EEC2D7734FE00E526F3 /* Debug */, + 61452EED2D7734FE00E526F3 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; + 61452EEE2D7734FE00E526F3 /* Build configuration list for PBXNativeTarget "com.apollographql.iostestTests" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 61452EEF2D7734FE00E526F3 /* Debug */, + 61452EF02D7734FE00E526F3 /* Release */, + ); + defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; + }; +/* End XCConfigurationList section */ + }; + rootObject = 61452EBF2D7734FA00E526F3 /* Project object */; +} diff --git a/tests/com.apollographql.iostest/com.apollographql.iostest/Assets.xcassets/AccentColor.colorset/Contents.json b/tests/com.apollographql.iostest/com.apollographql.iostest/Assets.xcassets/AccentColor.colorset/Contents.json new file mode 100644 index 00000000000..eb878970081 --- /dev/null +++ b/tests/com.apollographql.iostest/com.apollographql.iostest/Assets.xcassets/AccentColor.colorset/Contents.json @@ -0,0 +1,11 @@ +{ + "colors" : [ + { + "idiom" : "universal" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/tests/com.apollographql.iostest/com.apollographql.iostest/Assets.xcassets/AppIcon.appiconset/Contents.json b/tests/com.apollographql.iostest/com.apollographql.iostest/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 00000000000..2305880107d --- /dev/null +++ b/tests/com.apollographql.iostest/com.apollographql.iostest/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,35 @@ +{ + "images" : [ + { + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "dark" + } + ], + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + }, + { + "appearances" : [ + { + "appearance" : "luminosity", + "value" : "tinted" + } + ], + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/tests/com.apollographql.iostest/com.apollographql.iostest/Assets.xcassets/Contents.json b/tests/com.apollographql.iostest/com.apollographql.iostest/Assets.xcassets/Contents.json new file mode 100644 index 00000000000..73c00596a7f --- /dev/null +++ b/tests/com.apollographql.iostest/com.apollographql.iostest/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/tests/com.apollographql.iostest/com.apollographql.iostest/ContentView.swift b/tests/com.apollographql.iostest/com.apollographql.iostest/ContentView.swift new file mode 100644 index 00000000000..5d256bd079d --- /dev/null +++ b/tests/com.apollographql.iostest/com.apollographql.iostest/ContentView.swift @@ -0,0 +1,24 @@ +// +// ContentView.swift +// com.apollographql.iostest +// +// Created by Martin Bonnin on 04/03/2025. +// + +import SwiftUI + +struct ContentView: View { + var body: some View { + VStack { + Image(systemName: "globe") + .imageScale(.large) + .foregroundStyle(.tint) + Text("Hello, world!") + } + .padding() + } +} + +#Preview { + ContentView() +} diff --git a/tests/com.apollographql.iostest/com.apollographql.iostest/Preview Content/Preview Assets.xcassets/Contents.json b/tests/com.apollographql.iostest/com.apollographql.iostest/Preview Content/Preview Assets.xcassets/Contents.json new file mode 100644 index 00000000000..73c00596a7f --- /dev/null +++ b/tests/com.apollographql.iostest/com.apollographql.iostest/Preview Content/Preview Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "author" : "xcode", + "version" : 1 + } +} diff --git a/tests/com.apollographql.iostest/com.apollographql.iostest/com_apollographql_iostestApp.swift b/tests/com.apollographql.iostest/com.apollographql.iostest/com_apollographql_iostestApp.swift new file mode 100644 index 00000000000..0180e47ebd1 --- /dev/null +++ b/tests/com.apollographql.iostest/com.apollographql.iostest/com_apollographql_iostestApp.swift @@ -0,0 +1,17 @@ +// +// com_apollographql_iostestApp.swift +// com.apollographql.iostest +// +// Created by Martin Bonnin on 04/03/2025. +// + +import SwiftUI + +@main +struct com_apollographql_iostestApp: App { + var body: some Scene { + WindowGroup { + ContentView() + } + } +} diff --git a/tests/com.apollographql.iostest/com.apollographql.iostestTests/com_apollographql_iostestTests.swift b/tests/com.apollographql.iostest/com.apollographql.iostestTests/com_apollographql_iostestTests.swift new file mode 100644 index 00000000000..793966197ee --- /dev/null +++ b/tests/com.apollographql.iostest/com.apollographql.iostestTests/com_apollographql_iostestTests.swift @@ -0,0 +1,24 @@ +import Testing +import shared_framework +@testable import com_apollographql_iostest + +struct com_apollographql_iostestTests { + + final class AuthenticationInterceptor: Apollo_runtimeHttpInterceptor { + + func intercept(request: HttpRequest, chain: Apollo_runtimeHttpInterceptorChain) async throws -> HttpResponse { + throw NSError(domain: "interceptor error", code: 42, userInfo: ["foo": "bar"]) + } + + func dispose() { + // No op + } + } + + + + @Test func example() async throws { + try MainKt.testInterceptor(interceptor: AuthenticationInterceptor()) + } +} + diff --git a/tests/shared-framework/build.gradle.kts b/tests/shared-framework/build.gradle.kts new file mode 100644 index 00000000000..c78358bafb6 --- /dev/null +++ b/tests/shared-framework/build.gradle.kts @@ -0,0 +1,35 @@ +plugins { + id("org.jetbrains.kotlin.multiplatform") + id("com.apollographql.apollo") +} + +apolloTest(withJs = false, appleTargets = setOf("iosSimulatorArm64")) + +kotlin { + iosSimulatorArm64 { + binaries { + framework { + export(libs.apollo.api) + } + } + } + sourceSets { + findByName("commonMain")?.apply { + dependencies { + api(libs.apollo.runtime) + implementation(libs.apollo.mockserver) + } + } + + findByName("commonTest")?.apply { + dependencies { + } + } + } +} + +apollo { + service("service") { + packageName.set("com.example") + } +} \ No newline at end of file diff --git a/tests/shared-framework/src/commonMain/graphql/operation.graphql b/tests/shared-framework/src/commonMain/graphql/operation.graphql new file mode 100644 index 00000000000..677f8bc7c95 --- /dev/null +++ b/tests/shared-framework/src/commonMain/graphql/operation.graphql @@ -0,0 +1,3 @@ +query GetFoo { + foo +} \ No newline at end of file diff --git a/tests/shared-framework/src/commonMain/graphql/schema.graphqls b/tests/shared-framework/src/commonMain/graphql/schema.graphqls new file mode 100644 index 00000000000..188503bc3ec --- /dev/null +++ b/tests/shared-framework/src/commonMain/graphql/schema.graphqls @@ -0,0 +1,4 @@ + +type Query { + foo: Int! +} \ No newline at end of file diff --git a/tests/shared-framework/src/commonMain/kotlin/Main.kt b/tests/shared-framework/src/commonMain/kotlin/Main.kt new file mode 100644 index 00000000000..8ddb02c344a --- /dev/null +++ b/tests/shared-framework/src/commonMain/kotlin/Main.kt @@ -0,0 +1,26 @@ +import com.apollographql.apollo.ApolloClient +import com.apollographql.apollo.network.http.HttpInterceptor +import com.apollographql.mockserver.MockServer +import com.apollographql.mockserver.enqueueError +import com.example.GetFooQuery +import kotlinx.coroutines.runBlocking +import okio.use + +@Throws(Exception::class) +fun testInterceptor(interceptor: HttpInterceptor) { + runBlocking { + MockServer().use { mockServer -> + mockServer.enqueueError(500) + ApolloClient.Builder() + .serverUrl(mockServer.url()) + .addHttpInterceptor(interceptor) + .build() + .use { apolloClient -> + apolloClient.query(GetFooQuery()).execute().apply { + println("exception: ${exception!!.cause!!.message}") + check(exception!!.cause!!.message!!.contains("interceptor error")) + } + } + } + } +} diff --git a/tests/shared-framework/src/jvm/kotlin/test/JvmTest.kt b/tests/shared-framework/src/jvm/kotlin/test/JvmTest.kt new file mode 100644 index 00000000000..4ddc67ec1f4 --- /dev/null +++ b/tests/shared-framework/src/jvm/kotlin/test/JvmTest.kt @@ -0,0 +1,23 @@ +package test + +import com.apollographql.apollo.api.http.HttpRequest +import com.apollographql.apollo.api.http.HttpResponse +import com.apollographql.apollo.exception.DefaultApolloException +import com.apollographql.apollo.network.http.HttpInterceptor +import com.apollographql.apollo.network.http.HttpInterceptorChain +import testInterceptor +import kotlin.test.Test + +class JvmTest { + @Test + fun throwingInInterceptorIsExposedInResponse() { + testInterceptor(object : HttpInterceptor { + override suspend fun intercept( + request: HttpRequest, + chain: HttpInterceptorChain, + ): HttpResponse { + throw Exception("interceptor error") + } + }) + } +}