You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wrote a whole response, and then clicked "unmark as answer" before i hit reply so i lost it; but to summarize, this answer isn't satisfactory:
"GraphQL Codegen and the tooling it uses doesn't support string interpolation, and it's not going to add support for it, because in order to get the final string, we'll need to load, compile and look for that exported identifier. Doing that will make the setup of codegen much more complex - because of the many flavours in the JS ecosystem."
Even if theres a belief that this is "much more complex", TypeScript server handles it already. If you have a string, and interpolate a const into the string, typescript is able to deduce the proper end string. It does this performantly and without an issue. However, in this answer, we're not even given the option to opt into the complexity mentioned here.
The strings are still static even with interpolation. However, interpolation would allow us to import fragments. We really do not like that there is no connection anymore between queries and fragments. This means we run into an issue where now someone can delete a fragment because they think it is unused. GraphQL CodeGen will produce an error in this case, but this isn't easy to notice; it doesnt regenerate the GraphQL File, so you can keep working as if nothing is wrong.
I don't know what to tell my team besides "deal with it" and it seems unsatisfactory. I cant find any way to "import" and "use" fragments (without the useFragment hook, which we dont want to use) within my queries. The Magic String is a big issue. Not being able to do "find all references" is a big issue. I don't know why the decision was made to not support interpolation as an option. I feel very uneasy not knowing how to solve this problem for my team presently. Unfortunately, we already converted the codebase over and nearly everyone is uneasy with the maintainability of unused fragments floating around everywhere.
I have no answer, but would like to chime in with another useful usecase: when wanting to restrict the input to an existing constant value used multiple places in the code, like for example an enum value, it would be great to be able to use interpolation for this
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Here we can see TS clearly knows its an interpolated string, and knows its a const, and can figure out how to map it to one;
but CodeGen requires no interpolation. Any chance it could do a similar analysis as TS?
Beta Was this translation helpful? Give feedback.
All reactions