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

Codegen: Add Identifiable conformance #710

Closed
Tracked by #1700
designatednerd opened this issue Aug 13, 2019 · 7 comments
Closed
Tracked by #1700

Codegen: Add Identifiable conformance #710

designatednerd opened this issue Aug 13, 2019 · 7 comments
Labels
codegen Issues related to or arising from code generation enhancement Issues outlining new things we want to do or things that will make our lives as devs easier v1.x

Comments

@designatednerd
Copy link
Contributor

Great idea from the thread seeking Swift codegen suggestions - anything that has a GraphQLID should conform to Identifiable.

Note: Identifiable is part of the Swift 5.1 release, so it will need to wait until that gets finalized. That's likely well before the updated codegen gets finalized, though.

@designatednerd designatednerd added the codegen Issues related to or arising from code generation label Aug 13, 2019
@designatednerd designatednerd added the enhancement Issues outlining new things we want to do or things that will make our lives as devs easier label Aug 14, 2019
@rodrigoelp
Copy link

Ideally it should auto implement Hashable as well, allowing us to use the objects/structs directly in dictionaries and/or sets.
However, I understand some people might say certain fields should be consider in the hash and some people might vote for adding everything to the hash.

@designatednerd
Copy link
Contributor Author

@rodrigoelp Hashable and Equatable conformance will be added by default in updated codegen - please see the RFC in #939 for details.

@rodrigoelp
Copy link

Ah, bad @designatednerd, I did read that issue (only the part of Equatable). Thanks for the reply and happy new year.

@daisyramos317
Copy link

@designatednerd is there something missing in this query or a doc for GraphQLID I can take a look at? This project is running on Swift 5.6.1 but not seeing Identifiable conformance generated

query getLiveStreams($status: LiveStreamStatus) {
 	liveStreams(status: $status) {
 		id
 		channel {
 			id
 			name
 		}
 	}
 } 

@designatednerd
Copy link
Contributor Author

Hi Daisy, I no longer work at Apollo so information on timeline is best gotten from @AnthonyMDev and @calvincestari, but this was not implemented in Original Crispy Flavor™ codegen, it may be coming in updated codegen but I remember running into some issues around it.

Guys, any thoughts?

@AnthonyMDev
Copy link
Contributor

This is not being implemented in the 1.0 release with the new Codegen. There are a lot of good reasons why this is not being included. Primarily, GraphQL objects should be stored using the GraphQL NormalizedCache, not using Codable, so there isn't really a great reason for this.

@dfalling
Copy link

dfalling commented Aug 3, 2022

@AnthonyMDev,

Is there a reason to not implement Identifiable as suggested in this ticket? It would make iterating over collections in SwiftUI a bit less boilerplatey:

Current

ForEach(users, id: \.self.id) { user in
  NavigationLink(destination: UserDetails(user: user)) {
    Text(user.name)
  }
  .tag(user.id)
}

With Identifiable

ForEach(users) { user in
  NavigationLink(destination: UserDetails(user: user)) {
    Text(user.name)
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
codegen Issues related to or arising from code generation enhancement Issues outlining new things we want to do or things that will make our lives as devs easier v1.x
Projects
None yet
Development

No branches or pull requests

6 participants