Skip to content

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

@prasadrlv

Description

@prasadrlv

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");
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions