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

Code generation throwing an error in 1.2.1 only #3071

Closed
tahirmt opened this issue Jun 13, 2023 · 14 comments · Fixed by #3073
Closed

Code generation throwing an error in 1.2.1 only #3071

tahirmt opened this issue Jun 13, 2023 · 14 comments · Fixed by #3073
Assignees
Labels
bug Generally incorrect behavior needs investigation

Comments

@tahirmt
Copy link
Contributor

tahirmt commented Jun 13, 2023

Summary

I'm getting this error during generation of mocks. in only 1.2.1. This works well in 1.2.0.

Range requires lowerBound <= upperBound

This is what the log looks like when it happens. For reference I'm calling try ApolloCodegen.build(with: config) from a swift tools package myself by importing ApolloCodegenLib.

.
.
.
[DEBUG - ApolloCodegenLib:Glob.swift:225] - Matched /<file-path>/Mocks/<type-name>+Mock.graphql.swift
[DEBUG - ApolloCodegenLib:Glob.swift:225] - Matched /<file-path>/Mocks/<type-name>+Mock.graphql.swift
[DEBUG - ApolloCodegenLib:Glob.swift:225] - Matched /<file-path>/Mocks/<type-name>+Mock.graphql.swift
Swift/arm64e-apple-macos.swiftinterface:15840: Fatal error: Range requires lowerBound <= upperBound

Version

1.2.1

Steps to reproduce the behavior

I'm still working on isolating a project where I can reproduce it.

Logs

.
.
.
[DEBUG - ApolloCodegenLib:Glob.swift:225] - Matched /<file-path>/Mocks/<type-name>+Mock.graphql.swift
[DEBUG - ApolloCodegenLib:Glob.swift:225] - Matched /<file-path>/Mocks/<type-name>+Mock.graphql.swift
[DEBUG - ApolloCodegenLib:Glob.swift:225] - Matched /<file-path>/Mocks/<type-name>+Mock.graphql.swift
Swift/arm64e-apple-macos.swiftinterface:15840: Fatal error: Range requires lowerBound <= upperBound

Anything else?

The generated mock from 1.2.0 looks like this

import Apollo
import ModuleName

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

  public struct MockFields {
  }
}

// The original Object 

public extension Objects {
  static let TypeName = Object(
    typename: "TypeName",
    implementedInterfaces: [Interfaces.InterfaceName.self]
  )
}

Another thing to add is that this type does not add anything on top of the fields from the interface itself. All the fields that are part of this type are from the interface.

@AnthonyMDev
Copy link
Contributor

Thanks for the bug! I'm trying to look into this. Would definitely be really helpful to have a reproduction case that I can debug. Let me know if you come up with anything to reproduce this. I'll keep looking as well.

@AnthonyMDev
Copy link
Contributor

If you could maybe include a stack trace from where it fails, that might also be helpful.

@tahirmt
Copy link
Contributor Author

tahirmt commented Jun 13, 2023

I'm definitely looking into that. Will add more details as I can figure it out. I ran it from the command line so don't have a stack trace but I'll see if I can get it.

@AnthonyMDev
Copy link
Contributor

Okay, gotcha. Yeah to get a stack track you'd need to run it in Xcode for sure.

@AnthonyMDev
Copy link
Contributor

@dafurman is also experiencing a similar issue, though it's in generation of operations, not mocks.

I think I have some idea of what's going on in the code to cause this, but I can't reason through what sort of query shape would surface this. My assumption was that it would be impossible to get this range error (given a valid query definition).

I'll keep thinking on this, but I think I'm going to need a repro to get much farther.

If either of you are willing to privately send me your projects so I can run it locally and debug, that would also work.

@tahirmt
Copy link
Contributor Author

tahirmt commented Jun 13, 2023

I will never be able to get the necessary legal stuff sorted to share the actual schema with you so I'm going to try to recreate it in a sample schema. I'll reply if/when I do.

@AnthonyMDev
Copy link
Contributor

Haha, I definitely understand that. No worries. Thanks so much for working on reproducing this!

@tahirmt
Copy link
Contributor Author

tahirmt commented Jun 14, 2023

@AnthonyMDev I managed to create a schema with the error reproducible. When you open the Package.swift file you can run the codegen scheme to have it call ApolloCodegenLib and that will produce the error. And yes, it wasn't related to mocks at all. I just assumed it ws related because of the logs.

apollo-codegen-issue-1.2.1.zip

@tahirmt tahirmt changed the title Mock generation throwing an error in 1.2.1 only Code generation throwing an error in 1.2.1 only Jun 14, 2023
@AnthonyMDev
Copy link
Contributor

I say this probably once a day, but today I'm saying it to you!

@tahirmt, you are my hero (for today)! 🤟

I'll check this out and work to get a fix up ASAP. Assuming this bug doesn't explode into some really difficult to fix issue, my current plan is to get this and one other bug fixed and release a patch by EOW (6/16)

@tahirmt
Copy link
Contributor Author

tahirmt commented Jun 14, 2023

Happy to help!

@AnthonyMDev
Copy link
Contributor

The cause of this bug has been identified and fix has been implemented! Writing some unit tests to ensure this does not regress in the future and then I'll have a PR up! Thanks so much @tahirmt!

@AnthonyMDev
Copy link
Contributor

PR is in main and this is complete! The plan is to push the patch release 1.2.2 tomorrow which will include this fix!

@tahirmt
Copy link
Contributor Author

tahirmt commented Jun 14, 2023

Thanks @AnthonyMDev for the quick fix!

@AnthonyMDev
Copy link
Contributor

Couldn't have done it without you providing me the reproduction case! You rock @tahirmt!

@AnthonyMDev AnthonyMDev added this to the Patch Releases (1.x.x) milestone Jun 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Generally incorrect behavior needs investigation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants