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

feature: Emit Identifiable conformance on SelectionSets #584

Merged
merged 1 commit into from
Jan 24, 2025

Conversation

x-sheep
Copy link
Contributor

@x-sheep x-sheep commented Jan 23, 2025

This is a rework of #548, except this time it will only emit a conformance if the keyFields is set to exactly ["id"] (instead of assuming the presence of an id field is enough).

If a type has a field named id it is actually impossible to override the behavior of Identifiable, so I believe there is no situation in which an automatic conformance to Identifiable isn't desirable.

This PR will not generate a getter named id (as was proposed earlier), so there won't be an unexpected field named id in any case.

Copy link

netlify bot commented Jan 23, 2025

👷 Deploy request for eclectic-pie-88a2ba pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 07a3dbb

Copy link

netlify bot commented Jan 23, 2025

👷 Deploy request for apollo-ios-docc pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 07a3dbb

@svc-apollo-docs
Copy link
Collaborator

svc-apollo-docs commented Jan 23, 2025

✅ Docs preview has no changes

The preview was not built because there were no changes.

Build ID: a1a89cc70882192bce5fc7a5

@calvincestari
Copy link
Member

I think it would be beneficial to include a test that has id as the key field but it is not included in the selection set; test should not generate Identifiable conformance.

// given
schemaSDL = """
type Query {
  allAnimals: [Animal!]
}
type Animal @typePolicy(keyFields: "id") {
  id: ID!
  species: String!
}
"""

document = """
query TestOperation {
  allAnimals {
    species
  }
}
"""

Copy link
Member

@calvincestari calvincestari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One formatting suggestion.

@x-sheep
Copy link
Contributor Author

x-sheep commented Jan 24, 2025

I've added another test.

Copy link
Member

@calvincestari calvincestari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for following through on this @x-sheep.

Copy link
Contributor

@AnthonyMDev AnthonyMDev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy with this approach! Thanks so much @x-sheep!

@AnthonyMDev AnthonyMDev merged commit d769938 into apollographql:main Jan 24, 2025
23 checks passed
BobaFetters pushed a commit to apollographql/apollo-ios-codegen that referenced this pull request Jan 24, 2025
BobaFetters pushed a commit that referenced this pull request Jan 24, 2025
c254f6c7 feature: Emit Identifiable conformance on SelectionSets (#584)

git-subtree-dir: apollo-ios-codegen
git-subtree-split: c254f6c7b30b57b9c84d700b761d3af329f79bc3
BobaFetters pushed a commit that referenced this pull request Jan 24, 2025
…ormance on SelectionSets

git-subtree-dir: apollo-ios-codegen
git-subtree-mainline: 761cb21
git-subtree-split: c254f6c7b30b57b9c84d700b761d3af329f79bc3
@x-sheep x-sheep deleted the identifiable branch January 24, 2025 17:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants