Header Forwarding for Connectors

Graeme CouparGraeme CouparJamie BartonJamie Barton
Header Forwarding for Connectors

Both the GraphQL and OpenAPI connectors use HTTP to talk to downstream servers.

These servers typically accept HTTP headers. We've provided a feature to set up constant headers that are dispatched with each request. However, there are times when an API requires headers that can't be defined ahead of time - they may need to vary based on the user or the particular request.

Good news: Grafbase now supports header forwarding! — read more

If you're using the new Grafbase TypeScript SDK you can use the new set method to configure header forwarding:

import { connector } from '@grafbase/sdk' const shopify = connector.GraphQL('Shopify', { url: g.env('SHOPIFY_STORE_API_URL'), headers: headers => { headers.set('Authorization', { forward: 'Authorization' }) }, })

You can also forward and map one header to another:

import { connector } from '@grafbase/sdk' const shopify = connector.GraphQL('Shopify', { url: g.env('SHOPIFY_STORE_API_URL'), headers: headers => { headers.set('Authorization', { forward: 'original-header-name' }) }, })

If you're using the GraphQL SDL inside grafbase/schema.graphql to configure your project you can also forward headers:

extend schema @graphql( schema: "{{ env.SHOPIFY_STORE_API_URL }}" headers: [{ name: "Authorization", forward: "Authorization" }] )

The SDK will deprecate the method static() in favor of set(). This means to set a static header you must now do this:

import { connector } from '@grafbase/sdk' const shopify = connector.GraphQL('Shopify', { url: g.env('SHOPIFY_STORE_API_URL'), headers: headers => { headers.set('Authorization', `Bearer ${g.env('STRIPE_API_KEY')}`) }, })

We'd love to hear your feedback and ideas, so join us on Discord.