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

examples(rhai): Building surrogate cache keys #648

Closed
abernix opened this issue Mar 15, 2022 · 9 comments · Fixed by #1136
Closed

examples(rhai): Building surrogate cache keys #648

abernix opened this issue Mar 15, 2022 · 9 comments · Fixed by #1136
Assignees
Labels
component/rhai documentation Improvements or additions to documentation

Comments

@abernix
Copy link
Member

abernix commented Mar 15, 2022

Let's get an example using Rhai script that allows building a surrogate response cache key from subgraph responses. e.g.:subgraph a returns cache-key: one-way and subgraph b returns cache-key: or-another, and the response key returned to the client is surrogate-cache-key: one-way,or-another

blocked by #661

Worth noting that CAN actually be done as a Rust plugin today, but we just want to make it more simple and allow it in Rhai.

@abernix abernix changed the title Build surrogate response cache key from subgraph responses. e.g.:subgraph a returns cache-key: one-way and subgraph b returns cache-key: or-another, and the response key returned to the client is surrogate-cache-key: one-way,or-another examples: Building surrogate cache keys Mar 15, 2022
@abernix abernix added the documentation Improvements or additions to documentation label Mar 15, 2022
@Geal Geal self-assigned this Mar 15, 2022
@Geal
Copy link
Contributor

Geal commented Mar 15, 2022

right now we do not store response headers anywhere and have not thought about how and where they could be stored, so I propose we put off this example until we solve that

@abernix abernix changed the title examples: Building surrogate cache keys examples(rhai): Building surrogate cache keys Mar 22, 2022
@Geal
Copy link
Contributor

Geal commented May 16, 2022

this should be doable now that rhai plugins have access to subgraph response headers

@kroehre
Copy link

kroehre commented May 17, 2022

Looking forward to this example, I'm not seeing subgraph response headers in any of the rhai plugin response objects

@garypen
Copy link
Contributor

garypen commented May 18, 2022

Most responses expose response.headers. This will contain the response headers which will eventually be propagated back to the client. The Subgraph response.headers can be read to examine headers returned by a subgraph.

I'm going to guess that the existence of request.sub_headers on the SubgraphRequest is the source of confusion...

In a Request, headers are the headers which were originally supplied by the client (possibly modified during the progression of a plugin pipeline). For SubgraphRequest we also need a way to indicate the headers that we are going to send to downstream subgraphs, which is what request.sub_headers represents on the SubgraphRequest. Is that helpful?

@kroehre
Copy link

kroehre commented May 18, 2022

Hey thanks for the reply! For some reason response.headers is null when I print them from the subgraph_service hook callback:

fn subgraph_service(service, subgraph) {
  const response_callback = Fn("process_response");
  service.map_response(response_callback);
}

fn process_response(response) {
  print(`${response.headers}`);
}

In our case the goal is to propagate a few specific headers from subgraph responses.

@garypen
Copy link
Contributor

garypen commented May 18, 2022

Three options:

  • the subgraph isn't returning any headers
  • the headers aren't being propagated from the router subgraph handling
  • the rhai language binding has a bug which means it isn't picking up the headers properly.

I'll work through them and see if I can figure out what is happening.

@garypen
Copy link
Contributor

garypen commented May 18, 2022

And the winner is:

  • the headers aren't being propagated from the router subgraph handling

I've raised #1094 and will look into this.

@garypen
Copy link
Contributor

garypen commented May 19, 2022

@kroehre I've just merged the fix for #1094. This is now available on main and will be in the next release of the router.

@kroehre
Copy link

kroehre commented May 19, 2022

@garypen nice work! thank you

@abernix abernix added this to the v0.9.3 milestone May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/rhai documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants