Skip to content

Commit 549714b

Browse files
committed
feat: Allow passing HTTP headers to client fetcher
Add the ability to pass extra HTTP headers to a request. To achieve this the third argument (signal) now can also be a RequestOptions object (recommended), which includes the signal and headers keys.
1 parent 7722a6f commit 549714b

File tree

7 files changed

+1053
-1409
lines changed

7 files changed

+1053
-1409
lines changed

.changeset/modern-walls-sip.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@labdigital/graphql-fetcher": minor
3+
---
4+
5+
Support passing extra HTTP headers to client fetcher

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,24 @@ Only used for fetching from GraphQL endpoints.
1212
- Client fetcher with React context support when the endpoint is only known at runtime
1313
- Next data cache support
1414

15+
16+
## Usage
17+
18+
```ts
19+
import { initClientFetcher } from "@labdigital/graphql-fetcher";
20+
21+
const fetcher = initClientFetcher("https://localhost/graphql");
22+
23+
const gqlResponse = await fetcher(query, {
24+
myVar: "baz",
25+
}, {
26+
signal: AbortSignal.timeout(10),
27+
headers: {
28+
"X-extra-header": "foo",
29+
}
30+
});
31+
```
32+
1533
## Notes
1634

1735
### Node 18.x requires webcrypto on globalThis

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,5 +67,6 @@
6767
"react": ">= 18.0.0",
6868
"react-dom": ">= 18.2.0",
6969
"@opentelemetry/api": ">= 1.7.0"
70-
}
70+
},
71+
"packageManager": "[email protected]"
7172
}

0 commit comments

Comments
 (0)