Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

makeInputObject* and friends #238

Open
shirouto opened this issue Jan 28, 2021 · 3 comments
Open

makeInputObject* and friends #238

shirouto opened this issue Jan 28, 2021 · 3 comments

Comments

@shirouto
Copy link

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.

@jfrolich
Copy link
Collaborator

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!

@shirouto
Copy link
Author

shirouto commented Jan 29, 2021

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.

@LukasDeco
Copy link

I am having an issue like this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants