Skip to content

Commit

Permalink
Make apollo-server-env work with Cloudflare Workers and fly.io
Browse files Browse the repository at this point in the history
  • Loading branch information
martijnwalraven committed Sep 1, 2018
1 parent 77064af commit 78d7879
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 5 deletions.
8 changes: 4 additions & 4 deletions packages/apollo-server-cloudflare/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
export * from 'graphql-tools';

export { ApolloServer } from './ApolloServer';

export {
GraphQLUpload,
GraphQLOptions,
Expand All @@ -21,3 +17,7 @@ export {
PlaygroundConfig,
PlaygroundRenderPageOptions,
} from 'apollo-server-core';

export { ApolloServer } from './ApolloServer';

export * from 'graphql-tools';
44 changes: 43 additions & 1 deletion packages/apollo-server-env/src/index.browser.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,44 @@
const { fetch, Request, Response, Headers, URL, URLSearchParams } = global;
if (!global) {
global = self;
}

let { fetch, Request, Response, Headers, URL, URLSearchParams } = global;
fetch = fetch.bind(global);
export { fetch, Request, Response, Headers, URL, URLSearchParams };

if (!global.process) {
global.process = {};
}

if (!global.process.env) {
global.process.env = {
NODE_ENV: 'production',
};
}

if (!global.process.version) {
global.process.version = '';
}

if (!global.process.hrtime) {
// Adapted from https://github.com/kumavis/browser-process-hrtime
global.process.hrtime = function hrtime(previousTimestamp) {
var clocktime = Date.now() * 1e-3;
var seconds = Math.floor(clocktime);
var nanoseconds = Math.floor((clocktime % 1) * 1e9);
if (previousTimestamp) {
seconds = seconds - previousTimestamp[0];
nanoseconds = nanoseconds - previousTimestamp[1];
if (nanoseconds < 0) {
seconds--;
nanoseconds += 1e9;
}
}
return [seconds, nanoseconds];
};
}

if (!global.os) {
// FIXME: Add some sensible values
global.os = {};
}

0 comments on commit 78d7879

Please sign in to comment.