Skip to content

Autogenerated TestMocks files don't have access to SchemaGraphQL "schemaNamespace" in main target #3566

@Karram-Ayman

Description

@Karram-Ayman

Question

Hey Team,
using:
apollo-ios-cli --version
1.23.0

I’ve integrated ApolloTestSupport into our project, which uses Apollo via an XCFramework, and I’ve configured mock generation in the Apollo Codegen config as follows:

"output": {
      "testMocks": {
        "absolute": {
          "path": "./MyAppTests/ApolloGraphQL/ApolloGenerated/TestMocks",
          "targetName": "MyAppTests"
        }
      },
      "operations": {
        "inSchemaModule": {}
      },
      "schemaTypes": {
        "path": "./MyApp/ApolloGraphQL/ApolloGenerated/",
        "moduleType": {
          "embeddedInTarget": {
            "name": "MyApp"
          }
        }
      }
    }

The mock files are generated correctly under the MyAppTests target. However, I’m encountering the following error in the generated mock files:

// @generated
// This file was automatically generated and should not be edited.

import ApolloTestSupport
import MyApp

public class Campaign: MockObject {
  public static let objectType: ApolloAPI.Object = SchemaGraphQL.Objects.Campaign
  public static let _mockFields = MockFields()
  public typealias MockValueCollectionType = Array<Mock<Campaign>>
}

❗️Cannot find 'SchemaGraphQL' in scope — this module is generated in the MyApp target.

Question

Is there a supported way to make Apollo Codegen use:

@testable import MyApp instead of  import MyApp 

n the generated mock files? That would allow access to internal symbols without needing to make everything public.

Any advice or alternative approaches would be appreciated!

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionIssues that have a question which should be addressed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions