Disable or delete Client Awareness headers in named clients

Hello Apollo!

I recently upgraded a system for a site where I have had to create multiple named clients.

Since doing this, I have discovered that the ‘Client Awareness’ headers apollographql-client-name and apollographql-client-version are automatically added to the initial Http request.

It turns out that Subgraphs provided by thegraph do not support these headers and returns a CORS error.

Is there a way I can delete these headers or disable client awareness when I construct the client?

I see that I can specify extra custom headers in HttpLink if I need them. But how would I go about deleting the ones which were automatically added?

I have been able to do this in a different app built with Angular app by using the HttpInterceptor. But I’m unable to find any documentation on how to do this in a ‘vanilla’ JS site. (I’m also not using React)

Thanks for any pointers!

Hey @kosso :wave:

The easiest way to do this would be to customize the fetch function that is executed when a network request is made. You’ll be able to strip out the headers here.

Another option would be to use the setContext link. HttpLink looks for context.clientAwareness when determining whether to add the header or not, so you could strip it out this way as well. Something like this might work:

const stripAwarenessLink = setContext(() => ({ clientAwareness: null }))

Try both and see what works best for you, but this should get you what you need!

1 Like