graphql-deduplicator
graphql-deduplicator copied to clipboard
Standard HTTP header to ask for deduplicated data
Instead of recommending to use a query param, why don't we recommend using a custom HTTP header to request deduplicated data?
-
inflate
is a noop if the data wasn't deflated it doesn't matter whether the backend ends up sending deduplicated data or not - Headers aren't visible in the URL which is neater
- Backend usage is the ~same
I imagine something like this:
const httpLink = new HttpLink({
credentials: 'include',
uri: '/api',
headers: {
'X-GraphQL-Deduplicate': true
}
});
app.use('/graphql', graphqlExpress((request) => {
return {
formatResponse: (response) => {
if (request.headers['X-GraphQL-Deduplicate'] && response.data && !response.data.__schema) {
return deflate(response.data);
}
return response;
}
};
}));
The only reason I have suggested GET query parameter is because thats what I was using when debugging/ developing. However, I agree that this information is better communicated via a header.
I will update the documentation.
p.s. request.headers
exposes get
and has
methods.
Thank you