Skip to content

Allow using attributes on queries/mutations #697

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

Closed
mbenoukaiss opened this issue Jul 14, 2020 · 0 comments
Closed

Allow using attributes on queries/mutations #697

mbenoukaiss opened this issue Jul 14, 2020 · 0 comments
Assignees
Labels
enhancement Improvement of existing features or bugfix

Comments

@mbenoukaiss
Copy link

mbenoukaiss commented Jul 14, 2020

Is your feature request related to a problem? Please describe.
I am trying to use proc macro attributes to automatically generate code to handle authorization and rate-limits for the different queries and mutations. Problem is, the function gets transformed into an async block and attributes get removed in the process.

The currently generated code inside the match arm matching the query/mutation name looks like this :

let f = async move {
    let res: /* my function return type */ = async move { 
        /* get the context and function arguments */ 
        /* the code in my function */ 
    }.await;

    /* some code generated by juniper */
};

FutureExt::boxed(f)

Describe the solution you'd like
I believe it is possible to get the work done by keeping the function (and therefore its attributes):

let f = async move {
    let res: FieldResult<Account> = {
        async fn inner(/* original function arguments, including the context */) -> /* my function return type */ {
            /* the code in my function */
        }

        /* get context and arguments */
        inner(/* context and arguments */).await
    };

    /* some code generated by juniper */
};

FutureExt::boxed(f)

Potential problems

  • Would it add any overhead? To me, it doesn't seem like it would, but I'm not an async expert
  • I've seen code that directly uses the executor variable to get the context. This type of code would get broken by this change since the executor will be "hidden" behind the function. But it sounds like a hacky and unnecessary way to get the context anyway.

I can make a pull request with the changes if this is ok since I like doing stuff with proc macros.

@mbenoukaiss mbenoukaiss added the enhancement Improvement of existing features or bugfix label Jul 14, 2020
@mbenoukaiss mbenoukaiss changed the title Attributes on queries/mutations get removed Allow using attributes on queries/mutations Jul 15, 2020
@tyranron tyranron self-assigned this Jul 22, 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
Projects
None yet
Development

No branches or pull requests

2 participants