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

Missing argument label 'dynamicMember:' in subscript for generated code #2626

Closed
AlexHartford opened this issue Oct 31, 2022 · 4 comments
Closed

Comments

@AlexHartford
Copy link

AlexHartford commented Oct 31, 2022

Bug report

After following the getting started instructions, the generated code will not compile as the dynamicMember argument label is missing. It looks like this field has since been renamed "key" which would introduce more problems in future code. My suggested fix is #2627 which simply removes the required label. It looks like this is how code is being generated currently so not sure how anyone is actually able to use the generated code and I'm surprised there aren't any other issues around this.

Versions

Please fill in the versions you're currently using:

  • apollo-ios SDK version: 1.0.2
  • Xcode version: 14.0.1
  • Swift version: 5.7
  • Package manager: SPM via XCode

Steps to reproduce

  1. Use Codegen CLI to generate package dependency for schema.
  2. Observe that getters and setters are generated without mandatory argument label dynamicMember.

Further details

I have a large schema so manually updating the generated files is quite cumbersome. I believe this is a simple issue to resolve.

@calvincestari
Copy link
Member

Hi @AlexHartford, I believe the change you're referring to in InputDict is from #2607 which removed dynamic member lookup and changed it to a custom subscript. That PR is also full of generated sample code that builds, such as this. This change is not available in 1.0.2 but is currently available on main and will be included with the 1.0.3 release shortly.

Can you share a code sample demonstrating your issue with the parameter name. It would help narrow down on what the problem is.

I have a large schema so manually updating the generated files is quite cumbersome. I believe this is a simple issue to resolve.

You should never need to manually edit the generated files unless the header comment states they won't be overwritten, such as the schema configuration file.

@AlexHartford
Copy link
Author

AlexHartford commented Nov 1, 2022

Here's an example of the code that got generated. I downloaded the cli and installed manually from the main branch to generate this code.

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

import ApolloAPI

public struct CancelMessageInput: InputObject {
  public private(set) var __data: InputDict

  public init(_ data: InputDict) {
    __data = data
  }

  public init(
    conversationUid: String,
    timestampUid: String
  ) {
    __data = InputDict([
      "conversationUid": conversationUid,
      "timestampUid": timestampUid
    ])
  }

  public var conversationUid: String {
    get { __data["conversationUid"] }
    set { __data["conversationUid"] = newValue }
  }

  public var timestampUid: String {
    get { __data["timestampUid"] }
    set { __data["timestampUid"] = newValue }
  }
}

image

@calvincestari
Copy link
Member

I've built a demo app that builds fine with this type of input - issue2626.zip. I didn't include the generated files in that archive so you can verify the generation builds as expected. Use the command swift package plugin --allow-writing-to-package-directory apollo-generate from the root folder of the project.

Your specific issue I believe is being caused by a mismatched version of the CLI and your project dependency. I think you're using 1.0.2 as your project dependency and download/built the CLI from main. 1.0.2 still has dynamic member lookup which is why the compiler is expecting it to be there but the CLI (from main) is updated to drop that and use the custom subscript syntax.

We're aware of this versioning issue and trying to figure out a way around it - see #2562.

@AlexHartford
Copy link
Author

Okay, next time I generate the code I will make sure the versions all match - appreciate your time.

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

Successfully merging a pull request may close this issue.

2 participants