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

Schema/Target/Module name with spaces in it breaks generated code #2653

Closed
Narayane opened this issue Nov 9, 2022 · 4 comments · Fixed by #2760
Closed

Schema/Target/Module name with spaces in it breaks generated code #2653

Narayane opened this issue Nov 9, 2022 · 4 comments · Fixed by #2760
Assignees
Labels
bug Generally incorrect behavior codegen Issues related to or arising from code generation planned-next Slated to be included in the next release

Comments

@Narayane
Copy link

Narayane commented Nov 9, 2022

Bug report

When a Xcode project name contains a space character, relative module name contains an _ character instead.

In Test mocks files (Xxx+Mock.graphql.swift), for a project named First Project, imports are like:

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

import Apollo
import First Project

public class Xxx: MockObject {

but it should be

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

import Apollo
import First_Project

public class Xxx: MockObject {

Versions

Please fill in the versions you're currently using:

  • apollo-ios SDK version: 1.0.3
  • Xcode version: 13.4.1
  • Swift version: 5.6.1
  • CocoaPods: 1.11.3

Steps to reproduce

Run apollo-ios-cli generate onto a Xcode project whose name contains a space.

@calvincestari
Copy link
Member

Hi @Narayane 👋🏻 - thanks for reporting the issue.

This should be an easy fix, we'll get it into the next release. The workaround for now though is to use the Xcode-style of project name, i.e.: First_Project in the codegen configuration.

@calvincestari calvincestari added bug Generally incorrect behavior codegen Issues related to or arising from code generation labels Nov 9, 2022
@calvincestari calvincestari added this to the Release 1.0.4 milestone Nov 9, 2022
@calvincestari calvincestari self-assigned this Dec 20, 2022
@calvincestari calvincestari changed the title Wrong module name in generated test mocks import Project/Target/Module name with spaces in it breaks generated code Dec 20, 2022
@calvincestari calvincestari changed the title Project/Target/Module name with spaces in it breaks generated code Schema/Target/Module name with spaces in it breaks generated code Dec 20, 2022
@calvincestari
Copy link
Member

calvincestari commented Dec 20, 2022

I dug into this issue a bit today and the fix is a bit more involved than I initially thought; I've updated the issue title to better reflect the scope of the problem.

Configuration - embeddedInTarget - Sample Project

  • schema name with a space in it breaks the namespace enum and in all the templates where it is referenced.
  • target name with a space in it breaks import statements in test mocks. The target name generally matches the Xcode project name, Xcode handles this by replacing the space with an underscore.

Configuration - swiftPackageManager - Sample Project

  • schema name with a space in it breaks the module name reference and in all the templates where it is referenced.
  • schema name with a space in it breaks import statements in test mocks.

Note: This is an interesting configuration where the generated module Just Works™ because of the auto-generated Xcode project when editing the package with Xcode. The package name we generate into Package.swift can have a space in it but the module name we then reference in swift code needs to be underscored. It's anyone's guess whether it continues to work this way.

Configuration - other

  • This isn't a problem with CocoaPods because pod lib create does not allow spaces in pod names - [!] The Pod name cannot contain spaces.
  • I haven't tested other dependency managers that could work with the other module type.

@calvincestari calvincestari removed their assignment Dec 22, 2022
@AnthonyMDev
Copy link
Contributor

AnthonyMDev commented Jan 5, 2023

Can we just solve this by sanitizing the schemaName in ApolloCodegenConfiguration.init? If we need to use both the original name with spaces in it and the underscored one, let's add a let schemaNamespaceName: String to either ApolloCodegenConfiguration or ApolloCodegen.ConfigurationContext. That way we only need to do the conversion to the underscored name once and can use it where needed.

I'm really not sure why we would need to keep the schemaName with spaces (instead of underscores) around though. So if possible, it's easiest to just add the underscores to schemaName during initialization of the configuration.

@calvincestari
Copy link
Member

@Narayane - this is fixed, available on main, and will go out in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Generally incorrect behavior codegen Issues related to or arising from code generation planned-next Slated to be included in the next release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants