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

Not able to access headers object from apollo_mocks::get_supergraph_service_response() #9

Open
prasadrlv opened this issue Dec 6, 2024 · 2 comments
Labels
question Further information is requested

Comments

@prasadrlv
Copy link

prasadrlv commented Dec 6, 2024

I get the following error when accessing the headers object from the supergraph service response.

Rhai script is forwarding the custom response headers from subgraphs to the client.

"
Unknown property 'headers' - a getter is not registered for type 'alloc::sync::Arc<std::sync::mutex::Mutex<core::option::Option<apollo_router::services::supergraph::Response>>>'
"
response-header-forwarder.rhai:

// Configure allowed response headers
fn getAllowedResponseHeaders() {
    ["custom_response_header"]
}
fn copyResponseHeadersInResponse(response) {
    for header in getAllowedResponseHeaders() {
        if response.context[header]!=() {
           response.headers[header] = response.context[header];
       }
   }
}

response-header-forwarder.test.rhai:

test("Validate response header", ||{

    let mockResponse = apollo_mocks::get_supergraph_service_response();
      mockResponse.context["custom_response_header"]= "custom header value";

   const execute = || {
        import "response-header-forwarder" as responseHeaderForwarder;
        responseHeaderForwarder::copyResponseHeadersInResponse(mockResponse);
    };
    execute.call();
    
    expect(mockResponse.headers["custom_response_header"]).to_be("custom header value");
});
@andrewmcgivery
Copy link
Collaborator

Can you please try reformatting your description with proper code blocks? :)

Also a screenshot of the full error output would be helpful!

Additionally, the code of the function you're testing responseHeaderForwarder::copyResponseHeadersInResponse would also help. :)

@andrewmcgivery andrewmcgivery added the question Further information is requested label Dec 6, 2024
@prasadrlv
Copy link
Author

@andrewmcgivery
The response header forwarder rhai script is similar to the solution mentioned in apollographql/router#2060.
I updated the issue with code blocks. I request you please check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants