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

Add DataContext trait #786

Merged
merged 1 commit into from
Jan 19, 2022
Merged

Conversation

smmoosavi
Copy link
Contributor

Define the DataContext trait and implement for ContextBase and ExtensionContext

Why

Sometimes we have a function that gets Context as an argument, we can't use that function in Extension

pub fn get_foo_services(ctx: &async_graphql::Context<'_>) -> impl FooServices {}

#[async_trait::async_trait]
impl Extension for FooExtension {
    async fn execute(
        &self,
        ctx: &ExtensionContext<'_>,
        operation_name: Option<&str>,
        next: NextExecute<'_>,
    ) -> Response {
        let result = next.run(ctx, operation_name).await;
        let services = get_foo_services(ctx);

        result
    }
}
         let services = get_hsm_services(ctx);
                                         ^^^ expected struct `async_graphql::ContextBase`, found struct `async_graphql::extensions::ExtensionContext`

@sunli829
Copy link
Collaborator

This is very useful, thank you! 🙂

@sunli829 sunli829 merged commit 5c4289e into async-graphql:master Jan 19, 2022
@smmoosavi smmoosavi deleted the data-context branch January 19, 2022 07:11
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.

None yet

2 participants