firebase / firebase/firebase-tools

[Data Connect] Bug: Swift SDK generates conflicting property/class names

Open
#9,704 5 comments 0 reactions 1 assignee Claimed by @aashishpatil-g View on GitHub
api: dataconnect ready type: bug
Dominant language
TypeScript
Stars
4.5k
Forks
1.3k
Avg merge
1d 12h
Merged PRs (30d)
84

Description

### [REQUIRED] Environment info

**firebase-tools:** 15.1.0

**Platform:** macOS

### [REQUIRED] Test case

Create a Firebase Data Connect mutation with an underscore-prefixed or PascalCase name:

```graphql
# File: dataconnect/app-connector/mutations.gql

mutation _Placeholder @auth(level: NO_ACCESS) {
company_upsert(data: { cik: "_placeholder" })
}
```
**Configure Swift SDK generation in connector.yaml:**

connectorId: app
generate:
swiftSdk:
outputDir: ../apps/ios/MyApp/DataConnect
package: MyAppDataConnect

**[REQUIRED] Steps to reproduce**

1. Create a Data Connect connector with a mutation named _Placeholder (or any PascalCase name like CreateUser)
2. Run firebase dataconnect:sdk:generate
3. Open the generated Swift project in Xcode
4. Attempt to build the project

**[REQUIRED] Expected behavior**

The generated Swift SDK should compile without errors. The SDK generator should ensure that property names use camelCase to avoid conflicts with class names.

**Expected generated code:**
// Property uses camelCase, class uses PascalCase - no conflict
public let placeholderMutation: PlaceholderMutation

**[REQUIRED] Actual behavior**

The generated Swift code produces a compilation error because the property name and class name are identical:

Xcode Error:
```
Use of 'PlaceholderMutation' refers to instance method rather than class 'PlaceholderMutation' in module 'MyAppDataConnect'

Generated code (AppClient.swift):
public class AppConnector {
init(dataConnect: DataConnect) {
// Property and class have the same name - causes Swift conflict
self.PlaceholderMutation = PlaceholderMutation(dataConnect: dataConnect)
}

// MARK: Operations
public let PlaceholderMutation: PlaceholderMutation // ❌ Conflict!
}
```
**Root Cause:**
When the GraphQL operation name starts with uppercase (after removing _ prefix), the SDK generator uses the same casing for both the property name and class name, causing a Swift naming conflict.

| GraphQL Name | Generated Property | Generated Class | Result |
|--------------|---------------------|---------------------|-------------|
| _Placeholder | PlaceholderMutation | PlaceholderMutation | ❌ Conflict |
| CreateUser | CreateUserMutation | CreateUserMutation | ❌ Conflict |
| placeholder | placeholderMutation | PlaceholderMutation | ✅ Works |
| createUser | createUserMutation | CreateUserMutation | ✅ Works |

**Workaround:**
Use camelCase for all GraphQL operation names (e.g., placeholder instead of _Placeholder).

**Suggested Fix:**
The SDK generator should normalize property names to camelCase regardless of the input GraphQL operation name casing.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.