Skip to content

Commit 4f18996

Browse files
committed
[CLIENT] Fix apollo bad extraction
1 parent 89d6e9d commit 4f18996

File tree

5 files changed

+31
-10
lines changed

5 files changed

+31
-10
lines changed

packages/apollo/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@graphmetrics/apollo",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"repository": "[email protected]:graphmetrics/graphmetrics-js.git",
@@ -18,7 +18,7 @@
1818
"dist"
1919
],
2020
"dependencies": {
21-
"@graphmetrics/core": "workspace:0.2.2",
21+
"@graphmetrics/core": "workspace:0.2.3",
2222
"apollo-server-plugin-base": "0.10.4"
2323
},
2424
"peerDependencies": {

packages/client/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@graphmetrics/client",
3-
"version": "0.1.0",
3+
"version": "0.1.1",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"repository": "[email protected]:graphmetrics/graphmetrics-js.git",

packages/client/src/apollo.ts

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,15 @@ import { IncomingHttpHeaders } from 'http';
33
import { Context } from './context';
44
import { Details } from './interface';
55

6+
const CLIENT_NAME_HEADER = 'apollographql-client-name';
7+
const CLIENT_VERSION_HEADER = 'apollographql-client-version';
8+
9+
interface Headers {
10+
get(name: string): string | null;
11+
}
12+
613
type Request = {
7-
headers: IncomingHttpHeaders;
14+
headers: IncomingHttpHeaders | Headers;
815
};
916

1017
export function apolloContext<BaseContext>(
@@ -18,8 +25,15 @@ export function apolloContext<BaseContext>(
1825
}
1926

2027
export function apolloHeaders(req: Request): Details {
28+
// Extract name
2129
let name = '';
22-
const rawName = req.headers['apollographql-client-name'];
30+
let rawName: string | string[] | null = '';
31+
if (typeof req.headers.get === 'function') {
32+
rawName = req.headers.get(CLIENT_NAME_HEADER);
33+
} else {
34+
rawName = req.headers[CLIENT_NAME_HEADER];
35+
}
36+
2337
if (rawName) {
2438
if (Array.isArray(rawName)) {
2539
name = rawName[0];
@@ -28,8 +42,15 @@ export function apolloHeaders(req: Request): Details {
2842
}
2943
}
3044

45+
// Extract version
3146
let version = '';
32-
const rawVersion = req.headers['apollographql-client-version'];
47+
let rawVersion: string | string[] | null = '';
48+
if (typeof req.headers.get === 'function') {
49+
rawVersion = req.headers.get(CLIENT_VERSION_HEADER);
50+
} else {
51+
rawName = req.headers[CLIENT_VERSION_HEADER];
52+
}
53+
3354
if (rawVersion) {
3455
if (Array.isArray(rawVersion)) {
3556
version = rawVersion[0];

packages/core/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@graphmetrics/core",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"main": "dist/index.js",
55
"types": "dist/index.d.ts",
66
"repository": "[email protected]:graphmetrics/graphmetrics-js.git",
@@ -18,7 +18,7 @@
1818
"dist"
1919
],
2020
"dependencies": {
21-
"@graphmetrics/client": "workspace:0.1.0",
21+
"@graphmetrics/client": "workspace:0.1.1",
2222
"@graphmetrics/logger": "workspace:0.1.0",
2323
"@graphmetrics/sketches-js": "0.3.0",
2424
"denque": "1.5.0",

pnpm-lock.yaml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)