Open kvenn opened 6 months ago
👋 @kvenn Thank you for raising an issue. I will investigate the issue and get back to you as soon as possible. Please make sure you have provided enough context.
This library is created and maintained by me, @budde377. Please consider supporting my work and ensure our survival by donating here.
Good idea, thanks for raising it. I will investigate and see if its possible :)
Incredible thank you!!
We've been using wrappers in our code which kind of exemplify our ideal API. The read (in our case) could only need a string ID and the write only needs the object (since it will have the ID on it). I know this makes the function a little less flexible, but maybe it's a building block on top of the default?
Fragment$User? readUser(String id)
void writeUser(Fragment$User user)
Implementation
extension UserCache on GraphQLClient {
Fragment$User? readUser(String id) =>
readFragment$User(
idFields: {
'__typename': 'User',
'id': id,
},
);
void writeUser(Fragment$User user) =>
writeFragment$User(
idFields: {
'__typename': 'User',
'id': user.id,
},
data: user,
);
}
I see the docs mention the use of write and read like so:
But from this change, the Fragment already knows its own typename : https://github.com/heftapp/graphql_codegen/pull/247
Is it possible to generate a shorthand so I can just call it like so:
Or even better yet (since all of our idFields are the same for all our fragments):