graphql-ppx
graphql-ppx copied to clipboard
makeInputObject* and friends
Hi there,
In the case one cannot change the graphql schema, and the said graphql schema contains some input types with uppercase fields (while a relatively rare practice, it does not go against the specs), how do you envision one should approach the challenge? The ppx generated makeInputObject
* functions will have labeled parameters starting with capital letters, which I do not think are proper ReasonML argument names (is there a trick to call such a function nonetheless?). I guess I could unwrap the input type and expose the field values as query parameters, but that gets old quickly. Currently, I have been using standard bs records and Obj.magic
them into the proper type, however that is terrible since whatever goes on inside these records is entirely opaque to the type checker. I could extend the server schema with a custom input type that I would use to reassemble the server input type in the query while exposing the custom type in the query interface, but it somehow feels again a little too convoluted again.
Any suggestion would help and I apologize if this is not the proper avenue for such a query.
Hey, good point. It should make the first letter lowercase in this situation. If that is not yet the case, PR is welcome. If a PR is not possible an test-case would be helpful!
No, it does not lowercase the first letter currently. Also, the proposed approach, while it will mitigate the situation for a lot of use cases, it still may not work for some schema in the wild where both the uppercase and the lowercase field names pop up. Maybe prepend the field name with some standard lowercase letter like 'f' or 'v' or even a full word? Looking at your to_valid_ident
it just prepends '_' in case the identifier starts with a digit or it matches a reserved word (well, it works, but it also may silence some not-used compiler warnings). Besides, prepending may confuse the user a bit as they have to remember the convention and it may not be that convenient for some expedient idioms though. I can attempt a PR, however it may take a while.
I am having an issue like this.