Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using generated mocks when Graphql files are embedded in main target #3504

Closed
toddgower-hiatus opened this issue Jan 23, 2025 · 2 comments
Closed
Labels
question Issues that have a question which should be addressed

Comments

@toddgower-hiatus
Copy link

toddgower-hiatus commented Jan 23, 2025

Question

I'm just getting started trying to use the generated test mocks capability with Apollo but have run into issues with linking. Our generated GQL files are embedded in our main target and we've set up a framework to hold the mocks. Our config looks like this:

"output" : {
    "testMocks" : {
      "absolute" : {
        "path":"./hiatusTests/GraphQLV1Mocks",
        "accessModifier": "public"
      }
    },
    "schemaTypes" : {
      "path" : "./hiatus/API/GraphQL",
      "moduleType" : {
        "embeddedInTarget" : {
          "name" : "hiatus",
          "accessModifier": "internal"
        }
      }
    },
    "operations" : {
      "inSchemaModule" : {
      }
    }
  }

We're running into issues with the mocks attempting to import our main (app) target hiatus.

Image

This issue would go away if we created a separate framework to store our generated GQL files. Is that the only way to get this working or is it possible to leave our generated code in our main target?

@toddgower-hiatus toddgower-hiatus added the question Issues that have a question which should be addressed label Jan 23, 2025
@calvincestari
Copy link
Member

calvincestari commented Jan 23, 2025

Hi @toddgower-hiatus

We're running into issues with the mocks attempting to import our main (app) target hiatus.

The generated test mocks are additive to the generated schema code, so the test mock module has to be able to import the target/package/module that contains the generated schema code.

The JSON config shows that you're generating the schema code with an access modifier of internal which makes sense since it's in your main target, but that then requires you to manually add @testable to the import hiatus statement to be able to access it (looks like you've done this). The test mock module will also need a dependency link on the hiatus target for this still to work though. It's important to note that the generated test mock files do not support custom edits so the next time you execute code generation any custom edits you made will be overwritten. The alternative to this is generating the schema code with the public access modifier, or putting the generated schema code into it's own module which necessitates them having an access modifier of public anyways.

Copy link
Contributor

Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo iOS usage and allow us to serve you better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that have a question which should be addressed
Projects
None yet
Development

No branches or pull requests

2 participants