Infinite recursion and redundant imports

Hi,

I’ve generated some test mocks using the ApolloCodeGen config file setup but they seem to cause a couple of warnings.

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

import ApolloTestSupport
import MyGraphQL // <- File 'Film+Mock.graphql.swift' is part of module 'MyGraphQL'; ignoring import 

public class Film: MockObject {
  public static let objectType: Object = MyGraphQL.Objects.Film
  public static let _mockFields = MockFields()
  public typealias MockValueCollectionType = Array<Mock<Film>>

  public struct MockFields {
  }
}

public extension Mock where O == Film {
  convenience init(
  ) {
    self.init() // <- Function call causes an infinite recursion
  }
}

Separately…

  1. File 'Film+Mock.graphql.swift' is part of module 'ChipGraphQL'; ignoring import
  2. Function call causes an infinite recursion

I was wondering if there is a way to update the templates to remove the first import.

And is the infinite recursion something to worry about?

Thanks

It looks like someone else, or a co-worker, bumped into these same issues:

Are you able to share the configuration you’re using so I can verify we’re not missing any edge cases for the import statements - thanks.

Sure, will do.

Another thing I’ve just encountered. In all the struggles I had in getting the install to work I added .macOS(.v12) to the list of platforms in the Package.swift file.

Now that it’s running I removed that but now when I run the generation script I get tons of errors…

The app builds and runs, the tests run, everything seems to be working except the Apollo generation script.

swift package --allow-writing-to-package-directory apollo-generate

Thanks

This is my config file…

{
  "schemaName" : "MyGraphQL",
  "input" : {
    "operationSearchPaths" : [
      "./Sources/MyGraphQL/Queries/*.graphql"
    ],
    "schemaSearchPaths" : [
      "./Sources/MyGraphQL/Resources/*.graphql"
    ]
  },
  "output" : {
    "testMocks" : {
      "absolute" : {
        "path": "./Sources/MyGraphQL/TestMocks"
      }
    },
    "schemaTypes" : {
      "path" : "./Sources/MyGraphQL/Types",
      "moduleType" : {
        "other" : {
        }
      }
    },
    "operations" : {
      "inSchemaModule" : {
      }
    }
  }
}

Thanks

I think this… Generate library for test mock target by Gois · Pull Request #2633 · apollographql/apollo-ios · GitHub

Is not the solution I am looking for. It looks like this will generate a new package/module.

I just want them to be inside the same module. Would be good to wrap them in #if DEBUG or something though. And to remove the import from them.

Thanks

Those build errors seem to indicate that some of your project supports a minimum of macOS 10.13 whereas others have a minimum of macOS 10.15? Apollo iOS has a minimum macOS deployment target of 10.14.

I think that swift package command is failing because it builds your entire Swift package before executing any of the plugin commands, and then it encounters the macOS versioning conflicts.

Can you share a sample Swift project that’s set up to build, test, and deploy this way? I’m not completely following the configuration you mention. Currently all test mock configuration options treat it as though it’s in a separate module.

The project has had no mention of MacOS in it at all until I had to add it to get the Apollo script to work so I’m not sure.

Well for testing purposes. Any tests that want to add a mock to our GraphQLClient will have to import the MyGraphQL module in order to get hold of the GraphQLClient and pass the mocks in.

Having the test mocks in a different module just means we would also need to import another module to get to the mock objects. The mock objects would then also have to import MyGraphQL in order to get to the generated models too.

I think it would make sense to skip out the round trips of different imports and just have the test mocks in the same module as the client and the real data.

For an example of the project set up you can see a similar set up in the PointFree isowords project… GitHub - pointfreeco/isowords: Open source game built in SwiftUI and the Composable Architecture.

Thanks

I know this is a bit old now but did you solve the issue of the unnecessary import, I’ve got the identical issue as I’m also trying to generate the files into an existing swift package.

File ‘Redacted.graphql.swift’ is part of module ‘Redacted’; ignoring import