[solved] Need help accessing test mocks using generated Swift package

Hi all,

We’re in the process of updating our Apollo library from v0.53.0 (!) to v1.x and running into an issue accessing the generated TestMocks. We’ve generated a Swift package and added it as a local package to our run target, included the package in our project target’s Frameworks and Libraries. Addeding import BFF in all the files as necessary in that target allows it to compile.

However, we are unable to find an import for the unit test target. Here is the testMocks section in output of the config.json file:

"testMocks": {
    "swiftPackage": {
        "targetName": "MyTestMocks"
    }
},

We’ve tried with and without including a "targetName". The documentation states if ‘no target name is provided, the target name defaults to “(schemaName)TestMocks”’, but BFFTestMocks is not present. Also on that page: ‘Generated test mock files will be included in a target defined in the generated Package.swift file that is suitable for linking the generated test mock files to your test target using Swift Package Manager.’

That last sentence implies there should be a target that includes these mock files but our Package.swift file always looks like the following and we don’t see any reference to TestMocks:

// swift-tools-version:5.7

import PackageDescription

let package = Package(
  name: "BFF",
  platforms: [
    .iOS(.v12),
    .macOS(.v10_14),
    .tvOS(.v12),
    .watchOS(.v5),
  ],
  products: [
    .library(name: "BFF", targets: ["BFF"]),
  ],
  dependencies: [
    .package(url: "https://github.com/apollographql/apollo-ios.git", from: "1.0.0"),
  ],
  targets: [
    .target(
      name: "BFF",
      dependencies: [
        .product(name: "ApolloAPI", package: "apollo-ios"),
      ],
      path: "./Sources"
    ),
  ]
)

We’ve tried both v1.0.7 and v1.1.2 of apollo-ios. Is there a configuration option we are missing? Maybe something additional that needs to happen in the Xcode project configuration?

Here is our complete apollo-codegen-config.json

{
    "schemaName": "BFF",
    "input": {
        "operationSearchPaths": [
            "./Common/Common/**/*.graphql"
        ],
        "schemaSearchPaths": [
            "./Common/Common/**/*.graphqls"
        ]
    },
    "output": {
        "testMocks": {
            "swiftPackage": {
                "targetName": "MyTestMocks"
            }
        },
        "schemaTypes": {
            "path": "./BFF",
            "moduleType": {
                "swiftPackageManager": {}
            }
        },
        "operations": {
            "inSchemaModule": {}
        },
        "options": {
            "queryStringLiteralFormat": "multiline",
            "deprecatedEnumCases": "include",
            "warningsOnDeprecatedUsage": "include",
            "conversionStrategies": {
                "enumCases": "camelCase"
            },
            "pruneGeneratedFiles": false,
            "selectionSetInitializers" : {
                "localCacheMutations" : true,
                "namedFragments" : true,
                "operations" : true
            }
        }
    }
}

TIA!

Jim

Nothing to see here

So sorry. I somehow managed to include an apollo-codegen-config.json from outside the project and that’s why none of the changes I was making made no difference to my codegen. After fixing that issue, the codegen step works as expected.

Again, apologies for wasting anyone’s time investigating. Carry on.

Jim