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

Move apollo-engine-reporting signatures into apollo-graphql. #2259

Merged
merged 11 commits into from
Feb 4, 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
6 changes: 4 additions & 2 deletions docs/source/api/apollo-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,8 +303,10 @@ addMockFunctionsToSchema({

* `calculateSignature`: (ast: DocumentNode, operationName: string) => string

Specify the function for creating a signature for a query. See signature.ts
for details.
Specify the function for creating a signature for a query.

> See [`apollo-graphql`'s `signature.ts`](https://npm.im/apollo-graphql)
> for more information on how the default signature is generated.

* `reportIntervalMs`: number

Expand Down
2 changes: 1 addition & 1 deletion jest.config.base.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = {
// We don't want to match `apollo-server-env` and
// `apollo-engine-reporting-protobuf`, because these don't depend on
// compilation but need to be initialized from as parto of `prepare`.
'^(?!apollo-server-env|apollo-engine-reporting-protobuf)(apollo-(?:server|datasource|cache-control|tracing|engine)[^/]*|graphql-extensions)(?:/dist)?((?:/.*)|$)': '<rootDir>/../../packages/$1/src$2'
'^(?!apollo-server-env|apollo-engine-reporting-protobuf)(apollo-(?:server|graphql|datasource|cache-control|tracing|engine)[^/]*|graphql-extensions)(?:/dist)?((?:/.*)|$)': '<rootDir>/../../packages/$1/src$2'
},
clearMocks: true,
globals: {
Expand Down
22 changes: 18 additions & 4 deletions package-lock.json

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

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"apollo-datasource-rest": "file:packages/apollo-datasource-rest",
"apollo-engine-reporting": "file:packages/apollo-engine-reporting",
"apollo-engine-reporting-protobuf": "file:packages/apollo-engine-reporting-protobuf",
"apollo-graphql": "file:packages/apollo-graphql",
"apollo-server": "file:packages/apollo-server",
"apollo-server-azure-functions": "file:packages/apollo-server-azure-functions",
"apollo-server-cache-memcached": "file:packages/apollo-server-cache-memcached",
Expand Down Expand Up @@ -74,6 +75,7 @@
"@types/koa-multer": "1.0.0",
"@types/koa-router": "7.0.39",
"@types/lodash": "4.14.120",
"@types/lodash.sortby": "4.7.4",
"@types/lru-cache": "4.1.1",
"@types/memcached": "2.2.5",
"@types/micro": "7.3.3",
Expand Down
8 changes: 7 additions & 1 deletion packages/apollo-engine-reporting/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
### vNext

* Initial release.
# v1.0.0

* The signature functions which were previously exported from this package's
main module have been removed from `apollo-engine-reporting` and
moved to the `apollo-graphql` package. They should be more universally
helpful in that library, and should avoid tooling which needs to use them
from needing to bring in all of `apollo-server-core`.

6 changes: 3 additions & 3 deletions packages/apollo-engine-reporting/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "apollo-engine-reporting",
"version": "0.2.2",
"version": "1.0.0",
"description": "Send reports about your GraphQL services to Apollo Engine",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand All @@ -12,10 +12,10 @@
},
"dependencies": {
"apollo-engine-reporting-protobuf": "file:../apollo-engine-reporting-protobuf",
"apollo-graphql": "file:../apollo-graphql",
"apollo-server-core": "file:../apollo-server-core",
"apollo-server-env": "file:../apollo-server-env",
"async-retry": "^1.2.1",
"graphql-extensions": "file:../graphql-extensions",
"lodash": "^4.17.10"
"graphql-extensions": "file:../graphql-extensions"
}
}
4 changes: 2 additions & 2 deletions packages/apollo-engine-reporting/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
import { Trace, google } from 'apollo-engine-reporting-protobuf';

import { EngineReportingOptions, GenerateClientInfo } from './agent';
import { defaultSignature } from './signature';
import { defaultEngineReportingSignature } from 'apollo-graphql';
import { GraphQLRequestContext } from 'apollo-server-core/dist/requestPipelineAPI';

const clientNameHeaderKey = 'apollographql-client-name';
Expand Down Expand Up @@ -214,7 +214,7 @@ export class EngineReportingExtension<TContext = any>
let signature;
if (this.documentAST) {
const calculateSignature =
this.options.calculateSignature || defaultSignature;
this.options.calculateSignature || defaultEngineReportingSignature;
signature = calculateSignature(this.documentAST, operationName);
} else if (this.queryString) {
// We didn't get an AST, possibly because of a parse failure. Let's just
Expand Down
9 changes: 0 additions & 9 deletions packages/apollo-engine-reporting/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1 @@
export {
hideLiterals,
dropUnusedDefinitions,
sortAST,
removeAliases,
printWithReducedWhitespace,
defaultSignature,
} from './signature';

export { EngineReportingOptions, EngineReportingAgent } from './agent';
1 change: 1 addition & 0 deletions packages/apollo-engine-reporting/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"exclude": ["**/__tests__", "**/__mocks__"],
"references": [
{ "path": "../graphql-extensions" },
{ "path": "../apollo-graphql" },
{ "path": "../apollo-server-core/tsconfig.requestPipelineAPI.json" }
]
}
6 changes: 6 additions & 0 deletions packages/apollo-graphql/.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-graphql/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Change Log

### vNEXT

1 change: 1 addition & 0 deletions packages/apollo-graphql/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# `apollo-graphql`
3 changes: 3 additions & 0 deletions packages/apollo-graphql/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const config = require('../../jest.config.base');

module.exports = Object.assign(Object.create(null), config);
20 changes: 20 additions & 0 deletions packages/apollo-graphql/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"name": "apollo-graphql",
"version": "0.0.1-alpha.0",
"description": "Apollo GraphQL utility library",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"keywords": [],
"author": "Apollo <opensource@apollographql.com>",
"license": "MIT",
"engines": {
"node": ">=6"
},
"dependencies": {
"lodash.sortby": "^4.7.0"
},
"devDependencies": {},
"peerDependencies": {
"graphql": "^14.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,82 +7,12 @@ import {
dropUnusedDefinitions,
sortAST,
removeAliases,
} from '../signature';
} from '../transforms';

// The gql duplicate fragment warning feature really is just warnings; nothing
// breaks if you turn it off in tests.
disableFragmentWarnings();

describe('printWithReducedWhitespace', () => {
const cases = [
{
name: 'lots of whitespace',
// Note: there's a tab after "tab->", which prettier wants to keep as a
// literal tab rather than \t. In the output, there should be a literal
// backslash-t.
input: gql`
query Foo($a: Int) {
user(
name: " tab-> yay"
other: """
apple
bag
cat
"""
) {
name
}
}
`,
output:
'query Foo($a:Int){user(name:" tab->\\tyay",other:"apple\\n bag\\ncat"){name}}',
},
];
cases.forEach(({ name, input, output }) => {
test(name, () => {
expect(printWithReducedWhitespace(input)).toEqual(output);
});
});
});

describe('hideLiterals', () => {
const cases = [
{
name: 'full test',
input: gql`
query Foo($b: Int, $a: Boolean) {
user(name: "hello", age: 5) {
...Bar
... on User {
hello
bee
}
tz
aliased: name
}
}

fragment Bar on User {
age @skip(if: $a)
...Nested
}

fragment Nested on User {
blah
}
`,
output:
'query Foo($b:Int,$a:Boolean){user(name:"",age:0){...Bar...on User{hello bee}tz aliased:name}}' +
'fragment Bar on User{age@skip(if:$a)...Nested}fragment Nested on User{blah}',
},
];
cases.forEach(({ name, input, output }) => {
test(name, () => {
expect(printWithReducedWhitespace(hideLiterals(input))).toEqual(output);
});
});
});

describe('aggressive signature', () => {
function aggressive(ast: DocumentNode, operationName: string): string {
return printWithReducedWhitespace(
Expand Down
77 changes: 77 additions & 0 deletions packages/apollo-graphql/src/__tests__/transforms.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { default as gql, disableFragmentWarnings } from 'graphql-tag';

import { printWithReducedWhitespace, hideLiterals } from '../transforms';

// The gql duplicate fragment warning feature really is just warnings; nothing
// breaks if you turn it off in tests.
disableFragmentWarnings();

describe('printWithReducedWhitespace', () => {
const cases = [
{
name: 'lots of whitespace',
// Note: there's a tab after "tab->", which prettier wants to keep as a
// literal tab rather than \t. In the output, there should be a literal
// backslash-t.
input: gql`
query Foo($a: Int) {
user(
name: " tab-> yay"
other: """
apple
bag
cat
"""
) {
name
}
}
`,
output:
'query Foo($a:Int){user(name:" tab->\\tyay",other:"apple\\n bag\\ncat"){name}}',
},
];
cases.forEach(({ name, input, output }) => {
test(name, () => {
expect(printWithReducedWhitespace(input)).toEqual(output);
});
});
});

describe('hideLiterals', () => {
const cases = [
{
name: 'full test',
input: gql`
query Foo($b: Int, $a: Boolean) {
user(name: "hello", age: 5) {
...Bar
... on User {
hello
bee
}
tz
aliased: name
}
}

fragment Bar on User {
age @skip(if: $a)
...Nested
}

fragment Nested on User {
blah
}
`,
output:
'query Foo($b:Int,$a:Boolean){user(name:"",age:0){...Bar...on User{hello bee}tz aliased:name}}' +
'fragment Bar on User{age@skip(if:$a)...Nested}fragment Nested on User{blah}',
},
];
cases.forEach(({ name, input, output }) => {
test(name, () => {
expect(printWithReducedWhitespace(hideLiterals(input))).toEqual(output);
});
});
});
7 changes: 7 additions & 0 deletions packages/apollo-graphql/src/__tests__/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../../../tsconfig.test.base",
"include": ["**/*"],
"references": [
{ "path": "../../" }
]
}
1 change: 1 addition & 0 deletions packages/apollo-graphql/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { defaultEngineReportingSignature } from './signature';
Loading