graphql-rust / graphql-client

Typed, correct GraphQL requests and responses in Rust
Apache License 2.0
1.15k stars 158 forks source link

Field renaming causing collisions with names like "_id" #498

Open TymanWasTaken opened 1 month ago

TymanWasTaken commented 1 month ago

I am trying to interface with the Canvas LMS GraphQL API, but when I try to create queries in rust with this library, there are name collisions between the id and _id fields present in most types (corresponding to two types of identifiers in the API). After a bit of investigating, it appears that the heck library used by this crate will rename _id to id when running to_snake_case():

Welcome to evcxr. For help, type :help
>> :dep heck
   Compiling heck v0.5.0
>> use heck::ToSnakeCase;
>> "_id".to_snake_case()
"id"

Then, this new name is blindly accepted by graphql-client regardless of if there is already a type named id in the query, causing compiler errors due to field redefinition. I can get around this for now by using the CLI to generate the types and then manually renaming the _id field, but it would be nice if graphql-client could recognize situations like this and adjust. I'm not sure what the best solution to this is, perhaps not renaming a field if doing so would cause a collision could be the simplest fix?

tomhoule commented 1 month ago

Looks like a bug, thanks for reporting.