Skip to content

Data Connect Swift Generation Struct Property Name Conflict #10341

@mschwerz-bitrip

Description

@mschwerz-bitrip

[REQUIRED] Environment info

firebase-tools:15.14.0

Platform:macOS

[REQUIRED] Test case

Starting with the codelab for iOS: https://firebase.google.com/codelabs/firebase-dataconnect-ios#0

[REQUIRED] Steps to reproduce

  1. Modify the Review table to have another property that is also a User:
# Reviews is a join table between User and Movie.
# It has a composite primary keys `userUid` and `movieId`.
# A user can leave reviews for many movies. A movie can have reviews from many users.
# User  <-> Review is a one-to-many relationship
# Movie <-> Review is a one-to-many relationship
# Movie <-> User is a many-to-many relationship
type Review @table(name: "Reviews", key: ["movie", "user"]) {
  user: User!
  otherUser: User!
  # The user field adds the following foreign key field. Feel free to uncomment and customize it.
  #  userUid: String!
  movie: Movie!
  # The movie field adds the following foreign key field. Feel free to uncomment and customize it.
  #  movieId: UUID!
  rating: Int
  reviewText: String
  reviewDate: Date! @default(expr: "request.time")
}

and correct the AddReview query:

mutation AddReview($movieId: UUID!, $rating: Int!, $reviewText: String!)
@auth(level: USER) {
  review_upsert(
    data: {
      userId_expr: "auth.uid"
      otherUserId_expr: "auth.uid"
      movieId: $movieId
      rating: $rating
      reviewText: $reviewText
      # reviewDate defaults to today in the schema. No need to set it manually.
    }
  )
}
  1. Create the following query:
query ListReviewsRepro @auth(level: PUBLIC) {
  reviews {                                                                                                                 
    rating
    reviewText                                                                                                              
    user        { id username }
    otherUser { id username }
  }
}   
  1. Generate the sdk for swift

[REQUIRED] Expected behavior

The User structs underneath the ListReviewsReproQuery class should have unique names like generating for Android creates:

        @kotlinx.serialization.Serializable
  public data class User(
  
    val id: String,
    val username: String
  ) {
    
    
  }
      
        @kotlinx.serialization.Serializable
  public data class OtherUser(
  
    val id: String,
    val username: String
  ) {
    
    
  }

[REQUIRED] Actual behavior

The same name is given to struct for both the user and other user properties with the ListReviewsReproQuery. This prevents the iOS code from being able to build

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions