Skip to content
Graffle is a work in progress. Learn more.

Dynamic Headers

This example shows how to leverage the extension system to dynamically manipulate headers per request.

ts
import { 
Graffle
} from 'graffle'
const
graffle
=
Graffle
.
create
({
schema
: `https://countries.trevorblades.com/graphql`,
}) .
anyware
(async ({
pack
}) => {
return await
pack
({
input
: {
...
pack
.
input
,
headers
: {
'X-Sent-At-Time':
Date
.
now
().
toString
(),
}, }, }) }) .
anyware
(async ({
exchange
}) => {
// todo wrong type / runtime value
console
.
log
(
exchange
.
input
.
request
)
return
exchange
()
}) await
graffle
.
rawString
({
document
: `{ languages { code } }` })

Outputs

txt
{
  methodMode: 'post',
  headers: Headers {
    accept: 'application/graphql-response+json; charset=utf-8, application/json; charset=utf-8',
    'content-type': 'application/json',
    'x-sent-at-time': '1726679254856'
  },
  signal: undefined,
  method: 'post',
  url: 'https://countries.trevorblades.com/graphql',
  body: '{"query":"{ languages { code } }"}'
}

Released under the MIT License.