Skip to content

Query with default variable that is an enums type doesn't compile #403

Open
@ta32

Description

@ta32

When this issue was happening I was using the derive macro, however the compile error was very strange. Warning about taking a str. I switch to the code gen method to see what was happening.

The query has variables where one is typed as an enum

query MergedPrQuery($user: String = "user", $state: [PullRequestState!] = [MERGED] ) {
  user(login: $user) {
    pullRequests(states: $state, first:100, orderBy: { field: CREATED_AT, direction: DESC} ) {
      nodes {
        number,
        baseRefName,
        headRefName,
        createdAt
      }
    }
  }
}

The generated variable section is:

    #[derive(Serialize)]
    pub struct Variables {
        pub user: Option<String>,
        pub state: Option<Vec<PullRequestState>>,
    }
    impl Variables {
        pub fn default_user() -> Option<String> {
            Some("user".to_string())
        }
        pub fn default_state() -> Option<Vec<PullRequestState>> {
            Some(vec!["MERGED"])
        }
    }

I manually corrected it too

    #[derive(Serialize)]
    pub struct Variables {
        pub user: Option<String>,
        pub state: Option<Vec<PullRequestState>>,
    }
    impl Variables {
        pub fn default_user() -> Option<String> {
            Some("user".to_string())
        }
        pub fn default_state() -> Option<Vec<PullRequestState>> {
            Some(vec![PullRequestState::MERGED])
        }
    }

Then the query works, I suspect the same issue was occurring with the macro derive method. Good thing we have this code gen tool because it would be much harder to troubleshoot the proc macro :)

would this be a simple fix for a beginner, I don't have much knowledge about proc macros though

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions