diff --git a/Sources/AnimalKingdomAPI/animalkingdom-graphql/AnimalSchema.graphqls b/Sources/AnimalKingdomAPI/animalkingdom-graphql/AnimalSchema.graphqls index a5e76de07..5d238c7fb 100644 --- a/Sources/AnimalKingdomAPI/animalkingdom-graphql/AnimalSchema.graphqls +++ b/Sources/AnimalKingdomAPI/animalkingdom-graphql/AnimalSchema.graphqls @@ -27,6 +27,7 @@ input PetAdoptionInput { favoriteToy: String! isSpayedOrNeutered: Boolean! = false measurements: MeasurementsInput + adoptionDate: CustomDate } input MeasurementsInput { @@ -54,6 +55,7 @@ interface Pet @typePolicy(keyFields: "id") { humanName: String favoriteToy: String! owner: Human + adoptionDate: CustomDate } interface HousePet implements Animal & Pet { @@ -68,7 +70,8 @@ interface HousePet implements Animal & Pet { bestFriend: Pet rival: Pet livesWith: ClassroomPet - birthdate: CustomDate + adoptionDate: CustomDate + birthdate: CustomDate! } interface WarmBlooded implements Animal { @@ -110,6 +113,7 @@ type Cat implements Animal & Pet & WarmBlooded { humanName: String favoriteToy: String! owner: Human + adoptionDate: CustomDate bodyTemperature: Int! laysEggs: Boolean! isJellicle: Boolean! @@ -124,12 +128,13 @@ type Dog implements Animal & Pet & HousePet & WarmBlooded { humanName: String favoriteToy: String! owner: Human + adoptionDate: CustomDate bodyTemperature: Int! laysEggs: Boolean! bestFriend: HousePet rival: Cat livesWith: Bird - birthdate: CustomDate + birthdate: CustomDate! houseDetails: Object } @@ -142,6 +147,7 @@ type Bird implements Animal & Pet & WarmBlooded { humanName: String favoriteToy: String! owner: Human + adoptionDate: CustomDate bodyTemperature: Int! laysEggs: Boolean! wingspan: Float! @@ -156,6 +162,7 @@ type Fish implements Animal & Pet { humanName: String favoriteToy: String! owner: Human + adoptionDate: CustomDate } type Rat implements Animal & Pet { @@ -167,6 +174,7 @@ type Rat implements Animal & Pet { humanName: String favoriteToy: String! owner: Human + adoptionDate: CustomDate } type Crocodile implements Animal { @@ -184,6 +192,7 @@ type PetRock implements Pet { humanName: String favoriteToy: String! owner: Human + adoptionDate: CustomDate } union ClassroomPet = Cat | Bird | Rat | PetRock diff --git a/Sources/AnimalKingdomAPI/animalkingdom-graphql/PetDetailsMutation.graphql b/Sources/AnimalKingdomAPI/animalkingdom-graphql/PetDetailsMutation.graphql index e3e719b06..3a8ddfab4 100644 --- a/Sources/AnimalKingdomAPI/animalkingdom-graphql/PetDetailsMutation.graphql +++ b/Sources/AnimalKingdomAPI/animalkingdom-graphql/PetDetailsMutation.graphql @@ -2,4 +2,5 @@ fragment PetDetailsMutation on Pet @apollo_client_ios_localCacheMutation { owner { firstName } + adoptionDate } diff --git a/Tests/ApolloCodegenTests/CodeGeneration/Templates/MockObjectTemplateTests.swift b/Tests/ApolloCodegenTests/CodeGeneration/Templates/MockObjectTemplateTests.swift index 039b828be..ae7a9e251 100644 --- a/Tests/ApolloCodegenTests/CodeGeneration/Templates/MockObjectTemplateTests.swift +++ b/Tests/ApolloCodegenTests/CodeGeneration/Templates/MockObjectTemplateTests.swift @@ -482,7 +482,7 @@ class MockObjectTemplateTests: XCTestCase { public extension Mock where O == Dog { convenience init( - customScalar: TestSchema.CustomScalar = try! .init(_jsonValue: ""), + customScalar: TestSchema.CustomScalar = .defaultMockValue, customScalarList: [TestSchema.CustomScalar]? = nil, customScalarOptionalList: [TestSchema.CustomScalar?]? = nil, enumList: [GraphQLEnum]? = nil, @@ -580,7 +580,7 @@ class MockObjectTemplateTests: XCTestCase { public extension Mock where O == Dog { convenience init( - customScalar: TestSchema.CustomScalar = try! .init(_jsonValue: ""), + customScalar: TestSchema.CustomScalar = .defaultMockValue, customScalarList: [TestSchema.CustomScalar] = [], enumList: [GraphQLEnum] = [], enumType: GraphQLEnum = .case(.foo), diff --git a/Tests/TestCodeGenConfigurations/CodegenXCFramework/test-project.sh b/Tests/TestCodeGenConfigurations/CodegenXCFramework/test-project.sh index 9abe59253..dad5b94f2 100755 --- a/Tests/TestCodeGenConfigurations/CodegenXCFramework/test-project.sh +++ b/Tests/TestCodeGenConfigurations/CodegenXCFramework/test-project.sh @@ -1,5 +1,10 @@ #!/bin/bash -xcodebuild archive -configuration Release -project "CodegenXCFramework.xcodeproj" -scheme "CodegenXCFramework" -destination 'generic/platform=iOS Simulator' -archivePath "./build/iphonesimulator.xcarchive" SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES | xcbeautify -xcodebuild archive -configuration Release -project "CodegenXCFramework.xcodeproj" -scheme "CodegenXCFramework" -destination 'generic/platform=iOS' -archivePath "./build/iphoneos.xcarchive" SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=YES | xcbeautify -xcodebuild -create-xcframework -output ./build/CodegenXCFramework.xcframework -framework ./build/iphonesimulator.xcarchive/Products/Library/Frameworks/CodegenXCFramework.framework -framework ./build/iphoneos.xcarchive/Products/Library/Frameworks/CodegenXCFramework.framework | xcbeautify +set -o pipefail # Fail if any command in a pipeline fails + +# Clean up previous build artifacts +rm -rf ./build + +xcodebuild archive -configuration Release -project "CodegenXCFramework.xcodeproj" -scheme "CodegenXCFramework" -destination 'generic/platform=macOS' -archivePath "./build/macOS.xcarchive" SKIP_INSTALL=NO BUILD_LIBRARY_FOR_DISTRIBUTION=NO | xcbeautify + +xcodebuild -create-xcframework -allow-internal-distribution -output ./build/CodegenXCFramework.xcframework -framework ./build/macOS.xcarchive/Products/Library/Frameworks/CodegenXCFramework.framework | xcbeautify diff --git a/Tests/TestCodeGenConfigurations/EmbeddedInTarget-InSchemaModule/Sources/TestApp/AnimalKingdomAPI/Schema/SchemaConfiguration.swift b/Tests/TestCodeGenConfigurations/EmbeddedInTarget-InSchemaModule/Sources/TestApp/AnimalKingdomAPI/Schema/SchemaConfiguration.swift index 8e6a2dafc..3926da37d 100644 --- a/Tests/TestCodeGenConfigurations/EmbeddedInTarget-InSchemaModule/Sources/TestApp/AnimalKingdomAPI/Schema/SchemaConfiguration.swift +++ b/Tests/TestCodeGenConfigurations/EmbeddedInTarget-InSchemaModule/Sources/TestApp/AnimalKingdomAPI/Schema/SchemaConfiguration.swift @@ -8,7 +8,8 @@ import ApolloAPI enum SchemaConfiguration: ApolloAPI.SchemaConfiguration { - static func cacheKeyInfo(for type: Object, object: ObjectData) -> CacheKeyInfo? { - try? CacheKeyInfo(jsonValue: object["id"]) + static func cacheKeyInfo(for type: ApolloAPI.Object, object: ApolloAPI.ObjectData) -> CacheKeyInfo? { + // Implement this function to configure cache key resolution for your schema types. + return try? CacheKeyInfo(jsonValue: object["id"]) } } diff --git a/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/DefaultMockValueProviding.swift b/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/DefaultMockValueProviding.swift index 9173d39ec..0a54ab66a 100644 --- a/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/DefaultMockValueProviding.swift +++ b/apollo-ios-codegen/Sources/ApolloCodegenLib/FileGenerators/DefaultMockValueProviding.swift @@ -38,7 +38,7 @@ extension GraphQLScalarType: DefaultMockValueProviding { case "Boolean": return "false" default: - return "try! .init(_jsonValue: \"\")" + return ".defaultMockValue" } } } diff --git a/apollo-ios/CLI/apollo-ios-cli.tar.gz b/apollo-ios/CLI/apollo-ios-cli.tar.gz index 5bfae3d47..49f978ded 100644 Binary files a/apollo-ios/CLI/apollo-ios-cli.tar.gz and b/apollo-ios/CLI/apollo-ios-cli.tar.gz differ diff --git a/apollo-ios/Sources/ApolloTestSupport/ScalarType+DefaultMockValue.swift b/apollo-ios/Sources/ApolloTestSupport/ScalarType+DefaultMockValue.swift new file mode 100644 index 000000000..9532c5d5f --- /dev/null +++ b/apollo-ios/Sources/ApolloTestSupport/ScalarType+DefaultMockValue.swift @@ -0,0 +1,13 @@ +@_spi(Internal) import ApolloAPI + +public extension ScalarType { + static var defaultMockValue: Self { + try! .init(_jsonValue: "") + } +} + +public extension CustomScalarType { + static var defaultMockValue: Self { + try! .init(_jsonValue: "") + } +} diff --git a/scripts/run-test-codegen-configurations.sh b/scripts/run-test-codegen-configurations.sh index f2a28ddc9..4271c6dce 100755 --- a/scripts/run-test-codegen-configurations.sh +++ b/scripts/run-test-codegen-configurations.sh @@ -24,17 +24,27 @@ for dir in `ls $CodeGenConfigsDirectory`; do echo "-- Generating code for project: $dir --" (cd apollo-ios-codegen && swift run apollo-ios-cli generate -p ../$CodeGenConfigsDirectory/$dir/apollo-codegen-config.json) + + if [ $? -ne 0 ]; then + echo "Error: Code generation failed for $dir" + exit 1 + fi if [ "$test_projects" = true ] then echo -e "-- Testing project: $dir --" cd $CodeGenConfigsDirectory/$dir - if /bin/bash ./test-project.sh; then - echo -e "\n" - cd - > /dev/null - else + /bin/bash ./test-project.sh + test_exit_code=$? + + cd - > /dev/null + + if [ $test_exit_code -ne 0 ]; then + echo "Error: Test failed for $dir" exit 1 fi + + echo -e "\n" fi done