Skip to content

Commit

Permalink
Import graphql-extensions+apollo-engine-reporting/no global apollo-se…
Browse files Browse the repository at this point in the history
…rver-env (#1259)

* Export polyfills and types separately

* More imports from apollo-server-env

* Initial commit

* Add .npmignore to avoid ignoring lib when publishing

* 0.0.2

* Reorganize code and clean up GraphQLExtension interface

* 0.0.3

* Add support for timing callbacks and add GraphQLExtensionStack

* 0.0.4

* Downgrade target in tsconfig.json from es2015 to es5

* 0.0.5

* Bump `graphql` peerDependency. (#3)

* 0.0.6

* Update dependencies

* 0.0.7

* whenResultIsFinished fix for array results (#4)

* 0.0.8

* [apollo-bot] Update the Issue/PR Templates with auto label (#6)

* Bump `graphql` peerDependency. (#7)

* Update `graphql` peer dependency range to allow 0.13.x. (#8)

* Update `devDependencies` to latest versions. (#9)

* dev: Update TypeScript to latest version, v2.7.2.

* dev: Update `graphql` to latest version, v0.13.2.

* dev: Update jest & dependencies to latest versions.

* dev: Update type definitions for `graphql`, `node` and `jest`.

* Allow `undefined` return values to `GraphQLExtension`'s `format()`. (#10)

In some cases, it's conceivable that the `format()` method may need to abort
its decision to provide extension information at runtime, in the event that
it doesn't have the proper information to return a full-result.

The `format` method already removed false-y results, so this simply changes
the types to allow the same.

* 0.0.9

* Fix lifecycle method invocations on extensions

* 0.0.10

* Add changelog

* Upgrade to TypeScript 2.8

Makes my editor integration happier (a bugfix in tsserver I think)

* Add tslint and prettier

Same configuration as apollo-engine-js

* Remove magic from GraphQLExtensionStack constructor

It's not hard to consistently pass in an actual extension object to this
low-level API.

* New extension API: didStart handlers return didEnd handlers

This is a backwards-incompatible change: GraphQLExtension implementations and
users of GraphQLExtensionStack (ie apollo-server-core) must change their
implementations, if they implement any of the xDidStart/xDidEnd APIs.

This allows "didEnd" handlers to refer to closure variables from the "didStart"
handler rather than needing to store state on the extension.

The new "didEnd" handlers run in the opposite order of the "didStart" handlers,
so that they properly nest.

* 0.1.0-beta.0

* Changelog

* Add magic back into GraphQLExtensionStack constructor

But now it actually gets more context (the execution arguments) and doesn't have
to be a constructor.

* 0.1.0-beta.1

* Export more types

* 0.1.0-beta.2

* Fix lifecycle handlers to pass proper "this"

* 0.1.0-beta.3

* Pass options directly to start handlers; eliminate factory again

* 0.1.0-beta.4

* error handling in didEnd

* 0.1.0-beta.5

* pass multiple errors to EndHandler

* 0.1.0-beta.6

* add willSendResponse

* 0.1.0-beta.7

* prettier

* setFieldResolver for custom fieldResolver

* reverse

* get more initial options into requestDidStart

* 0.1.0-beta.8

* 0.1.0-beta.9

* Actually, we already get the fieldResolver!

* 0.1.0-beta.10

* work without extensionStack

* 0.1.0-beta.11

* 0.1.0-beta.12

* Send errors to willResolveField callback

* 0.1.0-beta.13

* willSendResponse can return a result

* 0.1.0-beta.14

* Revert 1063be8..56912fc

This reverts commit 1063be8..56912fc.

* add PQ options to requestDidStart

* 0.1.0-beta.14

* 0.1.0-beta.15

* Initialize an empty TypeScript/Jest package

Template based on apollo-engine-js

* Basic trace node structure building

* basic timing

* Checkpoint towards signature implementation

The new signature implementation does not try to compress whitespace.

* Basic signature implementation

* progress towards actual reporting

* basic checkpoint for reporting

* 0.0.0-beta.1

* pull in @types/long, since it is in the external api

* 0.0.0-beta.2

* get rid of Long

* 0.0.0-beta.3

* debug log request what happened

* 0.0.0-beta.4

* 0.0.0-beta.5

* correct url

* 0.0.0-beta.6

* request headers

* 0.0.0-beta.7

* leave out a few headers

* 0.0.0-beta.8

* prettier

* move stuff into multiple files, and stop exporting the extension

* lots of doc comments

* address agent.ts XXX comments

* implement privateVariables

simplify API by removing flush() and allowing flush-ers to just call sendReport
directly

* privateHeaders and error tracking

* gzip, signals

* fix test

* 0.0.0-beta.9

* Error handling for reports

* 0.0.0-beta.10

* no need to include boring stacktrace

* 0.0.0-beta.11

* tweak error reporting

* 0.0.0-beta.12

* package-lock update (npm@6?)

* Reduce target report size to 512KB from 4MB.

Load testing revealed that protobuf encoding for large FullTraceReports could
tie up CPU and reduce p99 request latency (eg, to 200ms from 10ms). Reducing the
default target report size spreads out the encoding time and mitigates the
impact on latency.  If this is not acceptable for all users, we may have to
investigate reintroducing agent-side stats aggregation to keep report sizes
small.

* 0.0.0-beta.13

* Encode Traces as they come in

This improves p99 times with little effect on p50 times. It also lets us get rid
of the heuristic average trace size estimation.

* 0.0.0-beta.14

* support PQ fields

* npm audit fix

* 0.0.0-beta.15

* ignore coverage

* Make the default signature more aggressive

We'd rather tell people confused by literal removal to tweak the signature than
tell people causing outages to do so.

* 0.0.0-beta.16

* Remove obsolete files from graphql-extensions and apollo-engine-reporting

* Fix dependencies and configs

* Fix apollo-server-cloudflare to import from apollo-server-env

* Fix compilation and test configs

* Get all tests passing again

* Switch to Lerna independent versioning

* Polyfill promisify for Node < 8 and load polyfills in tests

* ES2016 exponentiation operator is only supported in Node > 6

* add dependency cache for circle

* add missing env dependencies in REST datasource
  • Loading branch information
martijnwalraven authored and evans committed Jun 27, 2018
1 parent 8ef1818 commit c2e4dfb
Show file tree
Hide file tree
Showing 59 changed files with 2,021 additions and 253 deletions.
13 changes: 13 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,15 @@ common_test_steps: &common_test_steps
steps:
- *run_install_desired_npm
- checkout
- run: cat ./packages/*/package.json > package-checksum
- restore_cache:
key: dependency-cache-{{ checksum "package.json" }}-{{ checksum "package-checksum" }}
- run: npm --version
- run: npm install
- save_cache:
key: dependency-cache-{{ checksum "package.json" }}-{{ checksum "package-checksum" }}
paths:
- ./node_modules
- run: npm run travis

# Important! When adding a new job to `jobs`, make sure to define when it
Expand Down Expand Up @@ -62,8 +69,14 @@ jobs:
steps:
# (speed) Intentionally omitted, unnecessary, run_install_desired_npm.
- checkout
- restore_cache:
key: dependency-cache-{{ checksum "./docs/package.json" }}
# (speed) Ignore scripts to skip the Lerna build stuff for linting.
- run: npm install-test --prefix ./docs
- save_cache:
key: dependency-cache-{{ checksum "./docs/package.json" }}
paths:
- ./docs/node_modules

ignore_doc_branches: &ignore_doc_branches
filters:
Expand Down
43 changes: 22 additions & 21 deletions __mocks__/fetch.ts → __mocks__/apollo-server-env.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
declare global {
namespace NodeJS {
interface Global {
fetch: typeof fetch;
}
}
}
import {
fetch,
Request,
Response,
BodyInit,
Headers,
URL,
URLSearchParams,
} from 'apollo-server-env';

type Headers = { [name: string]: string };

Expand All @@ -13,39 +15,38 @@ interface FetchMock extends jest.Mock<typeof fetch> {
mockJSONResponseOnce(data?: object, headers?: Headers);
}

const fetchMock = jest.fn<typeof fetch>() as FetchMock;
const mockFetch = jest.fn<typeof fetch>() as FetchMock;

fetchMock.mockResponseOnce = (
mockFetch.mockResponseOnce = (
data?: BodyInit,
headers?: Headers,
status: number = 200,
) => {
return fetchMock.mockImplementationOnce(async () => {
return mockFetch.mockImplementationOnce(async () => {
return new Response(data, {
status,
headers,
});
});
};

fetchMock.mockJSONResponseOnce = (
mockFetch.mockJSONResponseOnce = (
data = {},
headers?: Headers,
status?: number,
) => {
return fetchMock.mockResponseOnce(
return mockFetch.mockResponseOnce(
JSON.stringify(data),
Object.assign({ 'Content-Type': 'application/json' }, headers),
status,
);
};

export default fetchMock;

export function mockFetch() {
global.fetch = fetchMock;
}

export function unmockFetch() {
global.fetch = fetch;
}
export = {
fetch: mockFetch,
Request,
Response,
Headers,
URL,
URLSearchParams,
};
6 changes: 2 additions & 4 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"lerna": "2.0.0",
"version": "2.0.0-rc.5",
"version": "independent",
"changelog": {
"repo": "apollographql/apollo-server",
"labels": {
Expand All @@ -13,7 +13,5 @@
}
},
"hoist": true,
"packages": [
"packages/*"
]
"packages": ["packages/*"]
}
30 changes: 15 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,23 @@
"node": ">=6"
},
"devDependencies": {
"@types/chai": "4.1.3",
"@types/chai": "^4.1.4",
"@types/graphql": "^0.13.1",
"@types/mocha": "5.2.1",
"@types/node": "^10.3.2",
"@types/mocha": "^5.2.3",
"@types/node": "^10.3.6",
"@types/sinon": "5.0.1",
"chai": "4.1.2",
"graphql": "0.13.2",
"husky": "0.14.3",
"istanbul": "1.1.0-alpha.1",
"lerna": "2.11.0",
"lint-staged": "7.2.0",
"mocha": "5.2.0",
"prettier": "1.13.5",
"prettier-check": "2.0.0",
"remap-istanbul": "0.11.1",
"sinon": "6.0.0",
"supertest": "3.1.0",
"typescript": "2.9.1"
"graphql": "^0.13.2",
"husky": "^0.14.3",
"istanbul": "^1.1.0-alpha.1",
"lerna": "^2.11.0",
"lint-staged": "^7.2.0",
"mocha": "^5.2.0",
"prettier": "^1.13.6",
"prettier-check": "^2.0.0",
"remap-istanbul": "^0.11.1",
"sinon": "^6.0.1",
"supertest": "^3.1.0",
"typescript": "^2.9.2"
}
}
14 changes: 10 additions & 4 deletions packages/apollo-datasource-rest/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"url": "https://github.com/apollographql/apollo-server/issues"
},
"scripts": {
"clean": "rm -rf lib",
"clean": "rm -rf dist",
"compile": "tsc",
"prepublish": "npm run clean && npm run compile",
"test": "jest --verbose"
Expand All @@ -30,13 +30,16 @@
"lru-cache": "^4.1.3"
},
"devDependencies": {
"@types/jest": "^23.0.0",
"@types/jest": "^23.1.2",
"@types/lru-cache": "^4.1.1",
"jest": "^23.1.0",
"jest": "^23.2.0",
"ts-jest": "^22.4.6"
},
"jest": {
"testEnvironment": "node",
"setupFiles": [
"<rootDir>/node_modules/apollo-server-env/dist/index.js"
],
"transform": {
"^.+\\.(ts|js)$": "ts-jest"
},
Expand All @@ -45,7 +48,10 @@
"js",
"json"
],
"testRegex": "/__tests__/.*$",
"testRegex": "apollo-datasource-rest/src/__tests__/.*$",
"roots": [
"../../"
],
"globals": {
"ts-jest": {
"skipBabel": true
Expand Down
9 changes: 9 additions & 0 deletions packages/apollo-datasource-rest/src/HTTPCache.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import {
fetch,
Request,
RequestInfo,
RequestInit,
Response,
Headers,
} from 'apollo-server-env';

import CachePolicy = require('http-cache-semantics');

import { KeyValueCache, InMemoryLRUCache } from 'apollo-server-caching';
Expand Down
11 changes: 11 additions & 0 deletions packages/apollo-datasource-rest/src/RESTDataSource.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
import {
BodyInit,
Headers,
Request,
RequestInit,
Response,
URL,
URLSearchParams,
URLSearchParamsInit,
} from 'apollo-server-env';

import { HTTPCache } from './HTTPCache';
import {
ApolloError,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import 'apollo-server-env';
import { fetch } from 'apollo-server-env';
import { HTTPCache } from '../HTTPCache';

import fetch, { mockFetch, unmockFetch } from '../../../../__mocks__/fetch';
import {
mockDate,
unmockDate,
Expand All @@ -13,7 +12,6 @@ describe('HTTPCache', () => {
let httpCache: HTTPCache;

beforeAll(() => {
mockFetch();
mockDate();
});

Expand All @@ -25,7 +23,6 @@ describe('HTTPCache', () => {
});

afterAll(() => {
unmockFetch();
unmockDate();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
import 'apollo-server-env';
import { fetch } from 'apollo-server-env';

import {
ApolloError,
AuthenticationError,
ForbiddenError,
} from 'apollo-server-errors';
import { RESTDataSource } from '../RESTDataSource';

import fetch, { mockFetch, unmockFetch } from '../../../../__mocks__/fetch';
import { HTTPCache } from '../HTTPCache';

describe('RESTDataSource', () => {
const store = new Map<string, string>();
let httpCache: HTTPCache;

beforeAll(() => {
mockFetch();

httpCache = new HTTPCache({
async get(key: string) {
return store.get(key);
Expand All @@ -31,10 +29,6 @@ describe('RESTDataSource', () => {
store.clear();
});

afterAll(() => {
unmockFetch();
});

it('returns data as parsed JSON when Content-Type is application/json', async () => {
const dataSource = new class extends RESTDataSource {
baseURL = 'https://api.example.com';
Expand Down
6 changes: 6 additions & 0 deletions packages/apollo-engine-reporting/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*
!src/**/*
!dist/**/*
dist/**/*.test.*
!package.json
!README.md
4 changes: 4 additions & 0 deletions packages/apollo-engine-reporting/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### vNext

* Initial release.

6 changes: 6 additions & 0 deletions packages/apollo-engine-reporting/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# apollo-engine-reporting

[![npm version](https://badge.fury.io/js/apollo-engine-reporting.svg)](https://badge.fury.io/js/apollo-engine-reporting)
[![Build Status](https://circleci.com/gh/apollographql/apollo-engine-reporting.svg?style=svg)](https://circleci.com/gh/apollographql/apollo-engine-reporting)

This package is a pure JS implementation of the Apollo Engine reporting feature. It is a work in progress and is not recommended for production use.
64 changes: 64 additions & 0 deletions packages/apollo-engine-reporting/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"name": "apollo-engine-reporting",
"version": "0.0.0-beta.16",
"description": "Send reports about your GraphQL services to Apollo Engine",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"scripts": {
"clean": "rm -rf dist",
"compile": "tsc",
"watch": "tsc -w",
"prepublish": "npm run clean && npm run compile",
"test": "jest --verbose",
"circle": "jest --verbose --coverage",
"lint": "prettier -l 'src/**/*.{ts,js}' && tslint -p tsconfig.json 'src/**/*.ts'",
"lint-fix": "prettier --write 'src/**/*.{ts,js}' && tslint --fix -p tsconfig.json 'src/**/*.ts'"
},
"license": "MIT",
"repository": "https://github.com/apollographql/apollo-engine-reporting",
"author": "Apollo <[email protected]>",
"engines": {
"node": ">=6.0"
},
"dependencies": {
"apollo-server-env": "^2.0.0-rc.3",
"apollo-engine-reporting-protobuf": "0.0.0-beta.7",
"graphql-extensions": "^0.1.0-beta.15",
"lodash": "^4.17.10",
"requestretry": "^1.13.0"
},
"devDependencies": {
"@types/graphql": "^0.13.1",
"@types/jest": "^23.1.2",
"@types/lodash": "^4.14.110",
"@types/node-fetch": "^2.1.1",
"@types/requestretry": "^1.12.3",
"graphql": "^0.13.2",
"graphql-tag": "^2.9.2",
"graphql-tools": "^3.0.4",
"jest": "^23.2.0",
"node-fetch": "^2.1.2",
"ts-jest": "^22.4.6",
"tslint": "^5.10.0"
},
"jest": {
"testEnvironment": "node",
"setupFiles": [
"<rootDir>/node_modules/apollo-server-env/dist/index.js"
],
"transform": {
"^.+\\.(ts|js)$": "ts-jest"
},
"moduleFileExtensions": [
"ts",
"js",
"json"
],
"testRegex": "/__tests__/.*$",
"globals": {
"ts-jest": {
"skipBabel": true
}
}
}
}
Loading

0 comments on commit c2e4dfb

Please sign in to comment.