Skip to content

Allow to parse camel case input variables from .graphql files and generate snake_case variables in Rust #381

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

Merged
merged 1 commit into from
Sep 2, 2021

Conversation

o0Ignition0o
Copy link
Contributor

This pull request mimics the current codegen's behaviour for output types.

It allows the codegen to generate snake_case variables whatever the case of the .graphql schema variables, which allows variable names to use the rust case.

I've added tests in input_object_variables_schema.graphql to make sure it doesn't break the current codegen as well.

Please let me know if there's anything I can do to improve this PR :)

Jeremy

@o0Ignition0o o0Ignition0o force-pushed the igni/input_variable_case branch from 38b8f35 to 003c623 Compare August 4, 2021 15:04
Copy link
Member

@tomhoule tomhoule left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have time to do a super thorough review now, but just to kick off the discussion: isn't this a breaking change for users currently using input types?

@o0Ignition0o
Copy link
Contributor Author

o0Ignition0o commented Aug 16, 2021

Hey, thanks a lot for your comment!

I just tried to investigate a bit more, and it turns out the behavior changed between the 0.9 release and 0.10. I first thought it happened between 0.10 and master, and it was an oversight. It turns out it probably wasn't!

Regardless of whether this would be a good or a bad idea, i think this change would be a breaking one, people would have camelCase members in their rust structures, and would need to make them snake_case again.

Here are the things IMO that would help figure out whether it would be worth a breaking change or not:

I by no means know the codebase and the project's history well enough to bring a better analysis at the moment.
Since there's probably a good reason behind this change between 0.9 and 0.10, I'll dig deeper and get back to you with more context :)

If you feel like keeping it as is makes more sense, or even changing the variables casing does, feel free to close this PR and/or let me know, I'll gladly give it a try or refactor what is needed :)

Thanks again for your time!

EDIT: I think this is where the snake case conversion used to happen in the inputs on 9.0, I now have to dig to find when it changed, and if it was on purpose, I hope to be able to write an EDIT2: soon :D

EDIT2: There used to be a test with a pawCount input that turned into paw_count that got commented out here (I think gh links are buggy but if you expand inputs.rs you should find it :D I'll soon write an EDIT3 pretty soon once I figure out where the behavior changed, and if it was on purpose ^^

EDIT3: Ok so it seems like it got turned into ingest_input somewhere around this commit in graphql_parser_conversion.rs and the snake_caseing somehow got lost in the refactoring, and there were unfortunately no tests to notice that.

I unfortunately cannot tell from the commits / changes alone whether this was intentional or not :/

@tomhoule
Copy link
Member

That refactoring stretched over a way too long time and I guess this got lost :/ I'll do a more thorough review first, but I now think we should merge this PR and do a patch release.

Copy link
Member

@tomhoule tomhoule left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge this — I don't have free time for graphql-client at the moment, so I don't know when I'll get around to doing a patch release unfortunately. Help is very much appreciated. Thanks for the PR :)

@tomhoule tomhoule merged commit b5befea into graphql-rust:main Sep 2, 2021
@o0Ignition0o
Copy link
Contributor Author

Sure no worries, I hope I can help doing triage or whatever sometimes, if I have a bit more time :)

@o0Ignition0o o0Ignition0o deleted the igni/input_variable_case branch September 2, 2021 07:42
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

Successfully merging this pull request may close these issues.

2 participants