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

Generated MockObjects sometimes cause an infinite recursion warning #2654

Closed
bdunay3 opened this issue Nov 9, 2022 · 1 comment
Closed

Comments

@bdunay3
Copy link

bdunay3 commented Nov 9, 2022

Bug report

When generating mock object types with the code generation tool we are seeing cases where the extension on the Mock type will create a convenience init that takes no parameters and calls self.init() thus resulting the compiler warning "Function call causes an infinite recursion."

Versions

Please fill in the versions you're currently using:

  • apollo-ios SDK version: 1.0.2
  • Xcode version: 14.1
  • Swift version: 5.7
  • Package manager: 5.7

Steps to reproduce

We are seeing this when we generate code for a query that doesn't ask for an entire sub-object type. For example say in our schema we define a type in our schema that has this kind of property graph:

Stuff
id: Int!
title: String
ValuePropLink
url: String!
id: Int!

And we write a query that's something like:

query getStuff() {
    Stuff() {
        id
        title
    }
}

When we run the code generation tool configuring it to generate mock object we would expect that no mock type would be generated for ValuePropLink. But instead we see this file created:

import ApolloTestSupport
import SharedGraphTypes

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

  public struct MockFields {
  }
}

public extension Mock where O == ValuePropLink {
  convenience init(
  ) {
    self.init()
  }
}

As you can see, if one where to call the convenience init where O is ValuePropLink it would just call itself recursively until the system runs out of stack memory.

What we would expect to see is the mock type would be generated. Looking through the code It appears that the mock code generator isn't checking to see if the field list is empty before writing the mock code template out to disk.

@calvincestari
Copy link
Member

Hi @bdunay3 👋🏻 - good news! This is already fixed with #2634, which is merged into main but not yet in a release. It will go out in 1.0.4 soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants