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

Warning "Function call causes an infinite recursion" for mocks which are of an unused ParentType. #2810

Closed
scottasoutherland opened this issue Feb 4, 2023 · 4 comments
Labels
awaiting response bug Generally incorrect behavior

Comments

@scottasoutherland
Copy link

scottasoutherland commented Feb 4, 2023

Summary

When generating code for a type which is only used in a union, but is never actually queried, a mock is generated for that type which has an initializer that calls itself and generates an infinite recursion, and gets an xcode warning saying such "Function call causes an infinite recursion"

Version

1.0.5

Steps to reproduce the behavior

Have a Schema Such as

type TypeOne { 
   myProperty:  Int!
}

type TypeTwo { 
   secondProperty: Int!
}

type TypeThree { 
   thirdProperty: Int!
}

union MyType =
    TypeOne |
    TypeTwo |
    TypeThree
   

and a query that includes a fragment such as

fragment responseFields on MyType {
    ... on TypeOne {
        myProperty
    }
    ... on TypeTwo {
       secondProperty
    }
}

Notice the query does not have any selection for "TypeThree". Generate the Code & Mocks for the schema. Notice that you get a mock such as

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

That causes the warning Function call causes an infinite recursion because the init calls itself as there are no properties passed to the initializer.

Logs

No response

Anything else?

No response

@scottasoutherland scottasoutherland added bug Generally incorrect behavior needs investigation labels Feb 4, 2023
@scottasoutherland
Copy link
Author

scottasoutherland commented Feb 4, 2023

I know the easy work around here, is to remove that type from the schema because it is unused. However in my case, that is difficult, because we have multiple targets that use the same schema but query it in different ways, and some use the other types, and some do not.

@calvincestari
Copy link
Member

Hi @scottasoutherland, can you please verify that you're using the latest version, and latest CLI. This bug was fixed in #2634 and released in 1.0.4.

The test case that was created to verify that PR fix is still passing and I've tried to replicate the build error using the types and fragment you mentioned above but I do not get the convenience initializer generated, which is expected from the previous fix.

If you are indeed on a version > 1.0.4 it would be helpful if you are able to reproduce the error in a standalone project we could then take a look at. Right now I cannot reproduce the error though.

@scottasoutherland
Copy link
Author

Ah, indeed. Our main project which uses apollo was on 1.0.5, but our code generation project was on 1.0.3, this was fixed when upgrading. Thank you.

@calvincestari
Copy link
Member

From 1.0.5 onwards there is a version check in the CLI that will warn you off mismatched versions between CLI and library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting response bug Generally incorrect behavior
Projects
None yet
Development

No branches or pull requests

2 participants