zino-hofmann / graphql-flutter

A GraphQL client for Flutter, bringing all the features from a modern GraphQL client to one easy to use package.
https://zino-hofmann.github.io/graphql-flutter
MIT License
3.25k stars 623 forks source link

GraphQL Camel Case to/from Postgres Snake Case needed #1224

Closed BerndWessels closed 2 years ago

BerndWessels commented 2 years ago

Hello

When using graphql with a postgres backend there is a common need to translate between postgres snake case and graphql camel case. Especially since the dart client site usually also uses camel case.

Is there a way to do this with graphql-flutter ?

Ideally in a general way somewhere hidden in a link layer or something?

Thanks

budde377 commented 2 years ago

You can alias field selections in your graphql query

query { 
  fieldOne: field_one
}

Other than that I believe such a change should be done on your server, not in the client.

If we start making assumptions and modifications to naming in the client we're bound to get buggy code which is hard to debug.

Finally, I'd also question the value of enforcing such casing. Why does it really matter? And will it not just create more confusion with inconsistent naming?

BerndWessels commented 2 years ago

Thanks for the response @budde377 . The alias looks promising. It might be just my OCD but I just feel uncomfortable with snake case in the client site flutter code and graphql schema. This seems such a common issue not only for dart but C#, JS and other languages that I was hoping it has some generic solution. Doing it on the server would most likely be the best place, unfortunately I am using AppSync and doing it in VTL is pretty complex, but I might give it a shot. Cheers