Skip to content

Commit

Permalink
Centralize operation hashing function
Browse files Browse the repository at this point in the history
These two operations will likely be used in tandem, and we want this to be consistent across consumers.
  • Loading branch information
trevor-scheer committed Feb 27, 2019
1 parent 6522598 commit b947a84
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
5 changes: 4 additions & 1 deletion packages/apollo-graphql/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
export { defaultEngineReportingSignature } from "./signature";
export {
defaultEngineReportingSignature,
hashForOperationSignature
} from "./signature";
8 changes: 7 additions & 1 deletion packages/apollo-graphql/src/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
// the server no longer needs to parse the signature or run its own signature
// algorithm on it, and the details of the signature algorithm are now up to the
// reporting agent.

import { createHash } from "crypto";
import { DocumentNode } from "graphql";
import {
printWithReducedWhitespace,
Expand All @@ -66,3 +66,9 @@ export function defaultEngineReportingSignature(
)
);
}

export function hashForOperationSignature(operationSignature: string): string {
return createHash("sha256")
.update(operationSignature)
.digest("hex");
}
14 changes: 5 additions & 9 deletions packages/apollo/src/utils/getOperationManifestFromProject.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { createHash } from "crypto";
import { defaultEngineReportingSignature } from "apollo-graphql";
import { GraphQLClientProject } from "apollo-language-server";
import {
defaultEngineReportingSignature,
hashForOperationSignature
} from "apollo-graphql";

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

return {
signature: manifestOperationHash(printed),
signature: hashForOperationSignature(printed),
document: printed,
metadata: {
engineSignature: printed
Expand All @@ -29,9 +31,3 @@ export function getOperationManifestFromProject(

return manifest;
}

function manifestOperationHash(str: string): string {
return createHash("sha256")
.update(str)
.digest("hex");
}

0 comments on commit b947a84

Please sign in to comment.