Skip to content

Commit

Permalink
feat: Allow passing HTTP headers to client fetcher
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
mvantellingen committed Aug 6, 2024
1 parent 7722a6f commit 549714b
Show file tree
Hide file tree
Showing 7 changed files with 1,053 additions and 1,409 deletions.
5 changes: 5 additions & 0 deletions .changeset/modern-walls-sip.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@labdigital/graphql-fetcher": minor
---

Support passing extra HTTP headers to client fetcher
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,24 @@ Only used for fetching from GraphQL endpoints.
- Client fetcher with React context support when the endpoint is only known at runtime
- Next data cache support


## Usage

```ts
import { initClientFetcher } from "@labdigital/graphql-fetcher";

const fetcher = initClientFetcher("https://localhost/graphql");

const gqlResponse = await fetcher(query, {
myVar: "baz",
}, {
signal: AbortSignal.timeout(10),
headers: {
"X-extra-header": "foo",
}
});
```

## Notes

### Node 18.x requires webcrypto on globalThis
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@
"react": ">= 18.0.0",
"react-dom": ">= 18.2.0",
"@opentelemetry/api": ">= 1.7.0"
}
},
"packageManager": "[email protected]"
}
Loading

0 comments on commit 549714b

Please sign in to comment.