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

Make proc macro support parameter attributes #441

Closed
wants to merge 13 commits into from

Conversation

davidpdrsn
Copy link
Contributor

@davidpdrsn davidpdrsn commented Oct 21, 2019

Fixes #421.

I decided to add https://crates.io/crates/proc-macro-error as mentioned here. It made returning a nice error significantly easier.

TODO

  • Fix use of old style in other tests/examples. cargo test currently produces quite a few deprecation warnings.
  • Make rename = "..." work. @theduke not quite sure how to handle this one. Got a hint?
  • Look into allowing docs on arguments with normal attribute Allow argument documentation  #525

@davidpdrsn
Copy link
Contributor Author

It seems like rustfmt removes the param attributes on CI

image

Is it running a pre 1.39 version of nightly perhaps? Things are working fine on my machine.

@davidpdrsn
Copy link
Contributor Author

I see the tests on stable and beta all fail because

---- src/lib.rs - object (line 136) stdout ----
420error[E0658]: attributes on function parameters are unstable
421  --> src/lib.rs:174:9
422   |
42340 | /         #[graphql(
42441 | |             // You can specify default values.
42542 | |             // A default can be any valid expression that yields the right type.
42643 | |             default = true,
42744 | |             description = "Argument description....",
42845 | |         )] arg1: bool,
429   | |__________^

Not quite sure how to resolve that 🤔

@davidpdrsn
Copy link
Contributor Author

@theduke @LegNeato would one of you be able to skim this and let me know if I'm missing something obvious? If all is good I'll look into updating all the other code using the old style of customising arguments. But just in case something needs to be changed I would like some confirmation before starting that.

Copy link
Member

@theduke theduke left a comment

Choose a reason for hiding this comment

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

Looks good to me!

I'm actually also fine with removing the old format right away without a deprecation period, and publishing it with the async release.

juniper_codegen/src/impl_object.rs Outdated Show resolved Hide resolved
@davidpdrsn
Copy link
Contributor Author

This should be ready to go now. I have removed support for the old style of customising args and updated all the existing code to use the new style. I was also able to get renaming working.

All thats left is wait for 1.39 to ship.

Let me know if you want me to squash the commits 😊

@davidpdrsn
Copy link
Contributor Author

I also took the liberty of adding assert-json-diff as a dev dependency. It makes comparing serde_json::Values in tests easier by pin pointing exactly where there are differences. This made implementing the renaming quite a bit easier.

Full disclosure: I maintain assert-json-diff.

@davidpdrsn davidpdrsn marked this pull request as ready for review October 26, 2019 10:46
@LegNeato
Copy link
Member

LegNeato commented Nov 5, 2019

The formatting seems to have removed some of these?

@davidpdrsn
Copy link
Contributor Author

@LegNeato I guess those todos were adding in the async-await branch. I created this branch from master.

This reverts commit 2858764.

Apparently rustfmt removes parameter attributes
@davidpdrsn
Copy link
Contributor Author

Hm so it seems rustfmt on stable (1.4.8-stable) removes parameter attributes. That is why lots of tests failed after I formatted. I guess we can either format on nightly, or wait for a new version of rustfmt to come out that doesn't remove parameter attributes.

I have reverted the formatting commit so at least cargo +nightly test passes.

@LegNeato
Copy link
Member

The fix should be on latest stable, right?

@davidpdrsn
Copy link
Contributor Author

@LegNeato Doesn't seem like it

/U/d/de/n/juniper [parameter-attributes@ce34e54cfdf3c]
$ cargo +nightly fmt

/U/d/de/n/juniper [parameter-attributes@ce34e54cfdf3c]
$ git status
On branch parameter-attributes
Your branch is up to date with 'origin/parameter-attributes'.

nothing to commit, working tree clean

/U/d/de/n/juniper [parameter-attributes@ce34e54cfdf3c]
$ cargo +stable fmt

/U/d/de/n/juniper [parameter-attributes@ce34e54cfdf3c *]
$ git status
On branch parameter-attributes
Your branch is up to date with 'origin/parameter-attributes'.

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
  modified:   juniper/src/executor_tests/introspection/mod.rs
  modified:   juniper/src/executor_tests/variables.rs
  modified:   juniper/src/macros/tests/args.rs
  modified:   juniper/src/macros/tests/impl_object.rs
  modified:   juniper/src/schema/schema.rs
  modified:   juniper/src/tests/schema.rs

no changes added to commit (use "git add" and/or "git commit -a")

@LegNeato
Copy link
Member

How about now? 😁

@davidpdrsn
Copy link
Contributor Author

@LegNeato I'm a bit behind on some OSS stuff. Hoping to get time this weekend to look into things. Great that async/await support is merged! 🎊

@davidpdrsn
Copy link
Contributor Author

I see has drifted quite far behind the current master. I'll try to get things up to date so we can finally get it merged.

@booooh
Copy link

booooh commented Apr 3, 2021

Checking in a year later -- is this still planned? 😉

@davidpdrsn
Copy link
Contributor Author

Ah sorry. Dropped the ball on this one.

Unfortunately I don't currently have the bandwidth to drive it home. I'll leave this PR open in case some one wants to pick it up but maintainers would feel free to close it.

@booooh
Copy link

booooh commented Apr 3, 2021

Ah sorry. Dropped the ball on this one.

No worries, it seems like most of the content is already in the MR -- so thanks for that!

Unfortunately I don't currently have the bandwidth to drive it home. I'll leave this PR open in case some one wants to pick it up but maintainers would feel free to close it.

I'll try to take a look, and see if I can get it in shape for a review.
I'm guessing the first step would be to rebase this on latest master and then confirm the updated functionality still works as expected?

@davidpdrsn
Copy link
Contributor Author

I'm guessing the first step would be to rebase this on latest master and then confirm the updated functionality still works as expected?

Yes. Good luck 😊

@booooh
Copy link

booooh commented Apr 3, 2021

Hmmm, I started the rebasing effort, but seems like some tests have already been enabled here:

fn attr_arg_descr(#[graphql(description = "The arg")] arg: i32) -> i32 {

I realize that this MR also cleans up a lot of the other content, but does this mean the core functionality is available in master - and the docs just need to be updated?

@tyranron tyranron mentioned this pull request Jul 22, 2021
6 tasks
@tyranron tyranron added the wontfix This will not be worked on label Aug 11, 2021
@tyranron
Copy link
Member

Done in #971

@tyranron tyranron closed this Aug 11, 2021
@tyranron tyranron added k::api Related to API (application interface) enhancement Improvement of existing features or bugfix semver::breaking Breaking change in terms of SemVer labels Aug 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement of existing features or bugfix k::api Related to API (application interface) semver::breaking Breaking change in terms of SemVer wontfix This will not be worked on
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactor object proc macro attributes to support parameter attributes
5 participants