blob: 2ab364557b8fedab847240055b6b273240ebccd8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
import { ApolloLink } from 'apollo-link';
import { memoize } from 'lodash';
export const FEATURE_CATEGORY_HEADER = 'x-gitlab-feature-category';
/**
* Returns the ApolloLink (or null) used to add instrumentation metadata to the GraphQL request.
*
* - The result will be null if the `feature_category` cannot be found.
* - The result is memoized since the `feature_category` is the same for the entire page.
*/
export const getInstrumentationLink = memoize(() => {
const { feature_category: featureCategory } = gon;
if (!featureCategory) {
return null;
}
return new ApolloLink((operation, forward) => {
operation.setContext(({ headers = {} }) => ({
headers: {
...headers,
[FEATURE_CATEGORY_HEADER]: featureCategory,
},
}));
return forward(operation);
});
});
|