Skip to content

Commit

Permalink
fix: forward headers when fetching from server
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanPiercey committed Dec 14, 2022
1 parent c92fbb6 commit 7a3f734
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/components/gql-query/impl/server.marko
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
import fetch from "make-fetch-happen";
import fetchImpl from "make-fetch-happen";
import { createClient } from "../../../client";
$ {
let store =
out.global.$$GQL ||
(out.global.$$GQL = createClient({ fetch, isServer: true }));
(out.global.$$GQL = createClient({
isServer: true,
fetch(url, options) {
const incomingMessage = out.stream && (out.stream.req || out.stream.request) || out.global.req || out.global.request;
if (!incomingMessage) return fetchImpl(url, options);
return fetchImpl(url, {
...options,
headers: {
...incomingMessage.headers,
...options.headers,
}
});
}
}));
const request = store.client.query(input.query, input.variables).toPromise();
}

Expand Down

0 comments on commit 7a3f734

Please sign in to comment.