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

Native plugins not called on invalid GraphQL query since 1.45 #5134

Open
yanns opened this issue May 10, 2024 · 0 comments
Open

Native plugins not called on invalid GraphQL query since 1.45 #5134

yanns opened this issue May 10, 2024 · 0 comments

Comments

@yanns
Copy link
Contributor

yanns commented May 10, 2024

Describe the bug
When an invalid GraphQL query is sent to the router, the router answers this query without calling any native plugins.
This is a new behavior since v1.45.0 and I guess it's related to #4551

To Reproduce
Send an invalid query like:

    let request = Request::builder()
        .query(r#"query { _service { sdl"#)
        .build();

In router v1.44, the plugins are called and have a chance to adapt the response sent. Ex:

#[derive(Debug)]
struct CustomizeErrorResponsePlugin {}

#[async_trait::async_trait]
impl Plugin for CustomizeErrorResponsePlugin {
    type Config = CustomizeErrorResponseConfig;

    async fn new(_init: PluginInit<Self::Config>) -> Result<Self, BoxError> {
        Ok(Self {})
    }

    fn supergraph_service(&self, service: supergraph::BoxService) -> supergraph::BoxService {
        use apollo_router::layers::ServiceBuilderExt;
        ServiceBuilder::new()
            .map_first_graphql_response(|_context, http_parts, mut graphql_response| {
                customise_response_error(&mut graphql_response.errors);
                (http_parts, graphql_response)
            })
            .service(service)
            .boxed()
    }
}

fn customise_response_error(errors: &mut [Error]) {
  // mutate the errors if necessary
}

In router v1.45, the plugin is not called anymore.

Expected behavior
It'd be great if the plugins are called even in case of invalid GraphQL queries. This is the way we're adapting the error code.

Desktop (please complete the following information):

  • Version 1.45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant