Skip to content

Commit 9e2fa7d

Browse files
committed
Centralize operation hashing function
These two operations will likely be used in tandem, and we want this to be consistent across consumers.
1 parent f52dbc5 commit 9e2fa7d

3 files changed

Lines changed: 16 additions & 11 deletions

File tree

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
export { defaultEngineReportingSignature } from "./signature";
1+
export {
2+
defaultEngineReportingSignature,
3+
hashForOperationSignature
4+
} from "./signature";

packages/apollo-graphql/src/signature.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
// the server no longer needs to parse the signature or run its own signature
4444
// algorithm on it, and the details of the signature algorithm are now up to the
4545
// reporting agent.
46-
46+
import { createHash } from "crypto";
4747
import { DocumentNode } from "graphql";
4848
import {
4949
printWithReducedWhitespace,
@@ -66,3 +66,9 @@ export function defaultEngineReportingSignature(
6666
)
6767
);
6868
}
69+
70+
export function hashForOperationSignature(operationSignature: string): string {
71+
return createHash("sha256")
72+
.update(operationSignature)
73+
.digest("hex");
74+
}

packages/apollo/src/utils/getOperationManifestFromProject.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import { createHash } from "crypto";
2-
import { defaultEngineReportingSignature } from "apollo-graphql";
31
import { GraphQLClientProject } from "apollo-language-server";
2+
import {
3+
defaultEngineReportingSignature,
4+
hashForOperationSignature
5+
} from "apollo-graphql";
46

57
export interface ManifestEntry {
68
signature: string;
@@ -19,7 +21,7 @@ export function getOperationManifestFromProject(
1921
const printed = defaultEngineReportingSignature(operationAST, "");
2022

2123
return {
22-
signature: manifestOperationHash(printed),
24+
signature: hashForOperationSignature(printed),
2325
document: printed,
2426
metadata: {
2527
engineSignature: printed
@@ -29,9 +31,3 @@ export function getOperationManifestFromProject(
2931

3032
return manifest;
3133
}
32-
33-
function manifestOperationHash(str: string): string {
34-
return createHash("sha256")
35-
.update(str)
36-
.digest("hex");
37-
}

0 commit comments

Comments
 (0)