Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add environment-aware createHash function to apollo-env #1110

Merged
merged 3 commits into from
Mar 13, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- apollo
- JSON flag for service:check output [#1079](https://github.com/apollographql/apollo-tooling/pull/1079)
- apollo-env
- Add environment-aware createHash function to apollo-env [#1110](https://github.com/apollographql/apollo-tooling/pull/1110)

## `apollo@2.6.0`, `apollo-env@0.3.4`, `apollo-language-server@1.5.3`, `apollo-codegen-flow@0.32.9`, `apollo-codegen-scala@0.33.5`, `apollo-codegen-swift@0.32.9`, `apollo-codegen-typescript@0.32.10`, `apollo-graphql@0.1.2`

Expand Down
13 changes: 12 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion packages/apollo-env/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
},
"dependencies": {
"core-js": "3.0.0-beta.13",
"node-fetch": "^2.2.0"
"node-fetch": "^2.2.0",
"sha.js": "^2.4.11"
}
}
1 change: 1 addition & 0 deletions packages/apollo-env/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ import "./polyfills";

export * from "./typescript-utility-types";
export * from "../lib/fetch";
export * from "./utils";
10 changes: 10 additions & 0 deletions packages/apollo-env/src/utils/createHash.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { isNodeLike } from "./isNodeLike";

export function createHash(kind: string): import("crypto").Hash {
if (isNodeLike) {
// Use module.require instead of just require to avoid bundling whatever
// crypto polyfills a non-Node bundler might fall back to.
return module.require("crypto").createHash(kind);
}
return require("sha.js")(kind);
}
2 changes: 2 additions & 0 deletions packages/apollo-env/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from "./createHash";
export * from "./isNodeLike";
6 changes: 6 additions & 0 deletions packages/apollo-env/src/utils/isNodeLike.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const isNodeLike =
typeof process === "object" &&
process &&
process.release &&
process.versions &&
typeof process.versions.node === "string";
1 change: 1 addition & 0 deletions packages/apollo-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"node": ">=6"
},
"dependencies": {
"apollo-env": "file:../apollo-env",
"lodash.sortby": "^4.7.0"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/apollo-graphql/src/signature.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
// 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 { DocumentNode } from "graphql";
import { createHash } from "apollo-env";
import {
printWithReducedWhitespace,
dropUnusedDefinitions,
Expand Down