[Plugin Request] Generate and verify @apollo/client@3
keyFields
configuration
#4700
-
@benjamn talks about it in this great talk: https://youtu.be/n_j8QckQN5I, and specifically what I'm requesting is the code generation mentioned briefly here: https://youtu.be/n_j8QckQN5I?t=1347. My hope for this potential new codegen plugin is:
Docs: https://www.apollographql.com/docs/react/caching/cache-configuration/#generating-unique-identifiers |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments
-
That could be great! Thank you @SimenB ! |
Beta Was this translation helpful? Give feedback.
-
@SimenB We have a new plugin for this :) see: #4973 |
Beta Was this translation helpful? Give feedback.
-
Yay! |
Beta Was this translation helpful? Give feedback.
-
@dotansimha just saw this plugin, this is a great start, thank you for putting it together. I had a few thoughts, wondering what you think: 1. The keyFields function signature doesn't allow passing in the entity object, it always gets typed as: keyFields?: false | FooBarKeySpecifier | (() => undefined | FooBarKeySpecifier); Some keyFields need to be computed based on object properties, but this function actually prohibits access to the object entirely. Is that by design? I think the logical thing to do would be to create a union of all fragment types that the consumer has on fragment FooBarFullInfo on FooBar {
id
name
details
bars {
id
name
}
}
fragment FooBarMinimalInfo on FooBar {
id
name
details
} Would produce: type FooBarFragments = FooBarFullInfoFragment | FooBarMinimalInfoFragment;
...
keyFields?: false | FooBarKeySpecifier | ((object: FooBarFragments) => undefined | FooBarKeySpecifier);
|
Beta Was this translation helpful? Give feedback.
@SimenB We have a new plugin for this :) see: #4973
Available as
@graphql-codegen/typescript-apollo-client-helpers
.