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

Chain operator execution order should be reversed #614

Closed
Shan6305 opened this issue Aug 31, 2021 · 1 comment
Closed

Chain operator execution order should be reversed #614

Shan6305 opened this issue Aug 31, 2021 · 1 comment

Comments

@Shan6305
Copy link

Currently, the chain operator executes guards last to first. For example, this code:

struct MessageGuard {
	message: String,
}
#[async_trait::async_trait]
impl Guard for MessageGuard {
	async fn check(&self, ctx: &async_graphql::Context<'_>) -> async_graphql::Result<()> {
		println!("{}", self.message.as_str());
		Ok(())
	}
}

pub struct Query;
#[Object]
impl Query {
	#[graphql(guard(
		chain(
			MessageGuard(message = r#""1""#),
			MessageGuard(message = r#""2""#),
			MessageGuard(message = r#""3""#),
			MessageGuard(message = r#""4""#),
			MessageGuard(message = r#""5""#),
		)
	))]
	async fn test(&self) -> String {
		"Test".into()
	}
}

would produce:

5
4
3
2
1

It would make more sense to execute guards from first to last. This would also match the behavior of the and guard, which executes guards from first to last. If there is some reason that this change can't/shouldn't be made, this behavior should at least be documented in the documentation.

@sunli829
Copy link
Collaborator

Released in v2.10.1

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

2 participants