From 708a29f9e0c3a80cfaa230c51a4229551663752b Mon Sep 17 00:00:00 2001 From: Trevor Scheer Date: Wed, 13 Feb 2019 17:27:37 -0800 Subject: [PATCH 1/2] Remove apollo-graphql package, migrating to apollo-tooling repo --- jest.config.base.js | 2 +- package-lock.json | 47 +++-- package.json | 1 - packages/apollo-engine-reporting/package.json | 4 +- .../apollo-engine-reporting/tsconfig.json | 1 - packages/apollo-graphql/.npmignore | 6 - packages/apollo-graphql/CHANGELOG.md | 4 - packages/apollo-graphql/README.md | 1 - packages/apollo-graphql/jest.config.js | 3 - packages/apollo-graphql/package.json | 19 -- .../src/__tests__/signature.test.ts | 148 ------------- .../src/__tests__/transforms.test.ts | 77 ------- .../src/__tests__/tsconfig.json | 7 - packages/apollo-graphql/src/index.ts | 1 - packages/apollo-graphql/src/signature.ts | 68 ------ packages/apollo-graphql/src/transforms.ts | 199 ------------------ packages/apollo-graphql/tsconfig.json | 10 - tsconfig.build.json | 1 - tsconfig.test.json | 1 - 19 files changed, 37 insertions(+), 563 deletions(-) delete mode 100644 packages/apollo-graphql/.npmignore delete mode 100644 packages/apollo-graphql/CHANGELOG.md delete mode 100644 packages/apollo-graphql/README.md delete mode 100644 packages/apollo-graphql/jest.config.js delete mode 100644 packages/apollo-graphql/package.json delete mode 100644 packages/apollo-graphql/src/__tests__/signature.test.ts delete mode 100644 packages/apollo-graphql/src/__tests__/transforms.test.ts delete mode 100644 packages/apollo-graphql/src/__tests__/tsconfig.json delete mode 100644 packages/apollo-graphql/src/index.ts delete mode 100644 packages/apollo-graphql/src/signature.ts delete mode 100644 packages/apollo-graphql/src/transforms.ts delete mode 100644 packages/apollo-graphql/tsconfig.json diff --git a/jest.config.base.js b/jest.config.base.js index 45592377f7e..328505f1da7 100644 --- a/jest.config.base.js +++ b/jest.config.base.js @@ -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|graphql|datasource|cache-control|tracing|engine)[^/]*|graphql-extensions)(?:/dist)?((?:/.*)|$)': '/../../packages/$1/src$2' + '^(?!apollo-server-env|apollo-engine-reporting-protobuf)(apollo-(?:server|datasource|cache-control|tracing|engine)[^/]*|graphql-extensions)(?:/dist)?((?:/.*)|$)': '/../../packages/$1/src$2' }, clearMocks: true, globals: { diff --git a/package-lock.json b/package-lock.json index f4ab23010bf..618c3cb618b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2313,7 +2313,7 @@ "version": "file:packages/apollo-engine-reporting", "requires": { "apollo-engine-reporting-protobuf": "file:packages/apollo-engine-reporting-protobuf", - "apollo-graphql": "file:packages/apollo-graphql", + "apollo-graphql": "^0.1.0", "apollo-server-core": "file:packages/apollo-server-core", "apollo-server-env": "file:packages/apollo-server-env", "async-retry": "^1.2.1", @@ -2345,7 +2345,9 @@ } }, "apollo-graphql": { - "version": "file:packages/apollo-graphql", + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/apollo-graphql/-/apollo-graphql-0.1.0.tgz", + "integrity": "sha512-Mi5GqZJz1A/0i8SEm9EVHWe/LkGbYzV5wzobUY+1Q0SI1NdFtRgqHZUdHU0hz1jDnL+dpRqK1huVmtOO/DGa/A==", "requires": { "lodash.sortby": "^4.7.0" } @@ -5562,7 +5564,8 @@ "ansi-regex": { "version": "2.1.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "aproba": { "version": "1.2.0", @@ -5583,12 +5586,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -5603,17 +5608,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -5730,7 +5738,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -5742,6 +5751,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -5756,6 +5766,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -5763,12 +5774,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.3.5", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.2", "yallist": "^3.0.0" @@ -5787,6 +5800,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -5867,7 +5881,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -5879,6 +5894,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -5964,7 +5980,8 @@ "safe-buffer": { "version": "5.1.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "safer-buffer": { "version": "2.1.2", @@ -6000,6 +6017,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", @@ -6019,6 +6037,7 @@ "version": "3.0.1", "bundled": true, "dev": true, + "optional": true, "requires": { "ansi-regex": "^2.0.0" } @@ -6062,12 +6081,14 @@ "wrappy": { "version": "1.0.2", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "yallist": { "version": "3.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true } } }, diff --git a/package.json b/package.json index e33e2709f88..7941f31b4a8 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,6 @@ "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", diff --git a/packages/apollo-engine-reporting/package.json b/packages/apollo-engine-reporting/package.json index d2096d9a559..96b69768924 100644 --- a/packages/apollo-engine-reporting/package.json +++ b/packages/apollo-engine-reporting/package.json @@ -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", + "graphql-extensions": "file:../graphql-extensions", "async-retry": "^1.2.1", - "graphql-extensions": "file:../graphql-extensions" + "apollo-graphql": "^0.1.0" } } diff --git a/packages/apollo-engine-reporting/tsconfig.json b/packages/apollo-engine-reporting/tsconfig.json index 07e4625888e..c226f290c52 100644 --- a/packages/apollo-engine-reporting/tsconfig.json +++ b/packages/apollo-engine-reporting/tsconfig.json @@ -8,7 +8,6 @@ "exclude": ["**/__tests__", "**/__mocks__"], "references": [ { "path": "../graphql-extensions" }, - { "path": "../apollo-graphql" }, { "path": "../apollo-server-core/tsconfig.requestPipelineAPI.json" } ] } diff --git a/packages/apollo-graphql/.npmignore b/packages/apollo-graphql/.npmignore deleted file mode 100644 index a165046d359..00000000000 --- a/packages/apollo-graphql/.npmignore +++ /dev/null @@ -1,6 +0,0 @@ -* -!src/**/* -!dist/**/* -dist/**/*.test.* -!package.json -!README.md diff --git a/packages/apollo-graphql/CHANGELOG.md b/packages/apollo-graphql/CHANGELOG.md deleted file mode 100644 index ef45b84f48c..00000000000 --- a/packages/apollo-graphql/CHANGELOG.md +++ /dev/null @@ -1,4 +0,0 @@ -# Change Log - -### vNEXT - diff --git a/packages/apollo-graphql/README.md b/packages/apollo-graphql/README.md deleted file mode 100644 index 07909aab7ea..00000000000 --- a/packages/apollo-graphql/README.md +++ /dev/null @@ -1 +0,0 @@ -# `apollo-graphql` diff --git a/packages/apollo-graphql/jest.config.js b/packages/apollo-graphql/jest.config.js deleted file mode 100644 index a383fbc925f..00000000000 --- a/packages/apollo-graphql/jest.config.js +++ /dev/null @@ -1,3 +0,0 @@ -const config = require('../../jest.config.base'); - -module.exports = Object.assign(Object.create(null), config); diff --git a/packages/apollo-graphql/package.json b/packages/apollo-graphql/package.json deleted file mode 100644 index 5b164275715..00000000000 --- a/packages/apollo-graphql/package.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "name": "apollo-graphql", - "version": "0.1.0", - "description": "Apollo GraphQL utility library", - "main": "dist/index.js", - "types": "dist/index.d.ts", - "keywords": [], - "author": "Apollo ", - "license": "MIT", - "engines": { - "node": ">=6" - }, - "dependencies": { - "lodash.sortby": "^4.7.0" - }, - "peerDependencies": { - "graphql": "^14.0.0" - } -} diff --git a/packages/apollo-graphql/src/__tests__/signature.test.ts b/packages/apollo-graphql/src/__tests__/signature.test.ts deleted file mode 100644 index 161e07ef30f..00000000000 --- a/packages/apollo-graphql/src/__tests__/signature.test.ts +++ /dev/null @@ -1,148 +0,0 @@ -import { DocumentNode } from 'graphql'; -import { default as gql, disableFragmentWarnings } from 'graphql-tag'; - -import { - printWithReducedWhitespace, - hideLiterals, - dropUnusedDefinitions, - sortAST, - removeAliases, -} from '../transforms'; - -// The gql duplicate fragment warning feature really is just warnings; nothing -// breaks if you turn it off in tests. -disableFragmentWarnings(); - -describe('aggressive signature', () => { - function aggressive(ast: DocumentNode, operationName: string): string { - return printWithReducedWhitespace( - removeAliases( - hideLiterals(sortAST(dropUnusedDefinitions(ast, operationName))), - ), - ); - } - - const cases = [ - // Test cases borrowed from optics-agent-js. - { - name: 'basic test', - operationName: '', - input: gql` - { - user { - name - } - } - `, - output: '{user{name}}', - }, - { - name: 'basic test with query', - operationName: '', - input: gql` - query { - user { - name - } - } - `, - output: '{user{name}}', - }, - { - name: 'basic with operation name', - operationName: 'OpName', - input: gql` - query OpName { - user { - name - } - } - `, - output: 'query OpName{user{name}}', - }, - { - name: 'with various inline types', - operationName: 'OpName', - input: gql` - query OpName { - user { - name(apple: [[10]], cat: ENUM_VALUE, bag: { input: "value" }) - } - } - `, - output: 'query OpName{user{name(apple:[],bag:{},cat:ENUM_VALUE)}}', - }, - { - name: 'with various argument types', - operationName: 'OpName', - input: gql` - query OpName($c: Int!, $a: [[Boolean!]!], $b: EnumType) { - user { - name(apple: $a, cat: $c, bag: $b) - } - } - `, - output: - 'query OpName($a:[[Boolean!]!],$b:EnumType,$c:Int!){user{name(apple:$a,bag:$b,cat:$c)}}', - }, - { - name: 'fragment', - operationName: '', - input: gql` - { - user { - name - ...Bar - } - } - - fragment Bar on User { - asd - } - - fragment Baz on User { - jkl - } - `, - output: '{user{name...Bar}}fragment Bar on User{asd}', - }, - { - name: 'full test', - operationName: 'Foo', - input: gql` - query Foo($b: Int, $a: Boolean) { - user(name: "hello", age: 5) { - ...Bar - ... on User { - hello - bee - } - tz - aliased: name - } - } - - fragment Baz on User { - asd - } - - fragment Bar on User { - age @skip(if: $a) - ...Nested - } - - fragment Nested on User { - blah - } - `, - output: - 'query Foo($a:Boolean,$b:Int){user(age:0,name:""){name tz...Bar...on User{bee hello}}}' + - 'fragment Bar on User{age@skip(if:$a)...Nested}fragment Nested on User{blah}', - }, - ]; - cases.forEach(({ name, operationName, input, output }) => { - test(name, () => { - expect(aggressive(input, operationName)).toEqual(output); - }); - }); -}); diff --git a/packages/apollo-graphql/src/__tests__/transforms.test.ts b/packages/apollo-graphql/src/__tests__/transforms.test.ts deleted file mode 100644 index e0ad5e471d3..00000000000 --- a/packages/apollo-graphql/src/__tests__/transforms.test.ts +++ /dev/null @@ -1,77 +0,0 @@ -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); - }); - }); -}); diff --git a/packages/apollo-graphql/src/__tests__/tsconfig.json b/packages/apollo-graphql/src/__tests__/tsconfig.json deleted file mode 100644 index 428259da813..00000000000 --- a/packages/apollo-graphql/src/__tests__/tsconfig.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "extends": "../../../../tsconfig.test.base", - "include": ["**/*"], - "references": [ - { "path": "../../" } - ] -} diff --git a/packages/apollo-graphql/src/index.ts b/packages/apollo-graphql/src/index.ts deleted file mode 100644 index 8161d6647f0..00000000000 --- a/packages/apollo-graphql/src/index.ts +++ /dev/null @@ -1 +0,0 @@ -export { defaultEngineReportingSignature } from './signature'; diff --git a/packages/apollo-graphql/src/signature.ts b/packages/apollo-graphql/src/signature.ts deleted file mode 100644 index 8ddc71fe9f2..00000000000 --- a/packages/apollo-graphql/src/signature.ts +++ /dev/null @@ -1,68 +0,0 @@ -// In Engine, we want to group requests making the same query together, and -// treat different queries distinctly. But what does it mean for two queries to -// be "the same"? And what if you don't want to send the full text of the query -// to Apollo Engine's servers, either because it contains sensitive data or -// because it contains extraneous operations or fragments? -// -// To solve these problems, EngineReportingAgent has the concept of -// "signatures". We don't (by default) send the full query string of queries to -// the Engine servers. Instead, each trace has its query string's "signature". -// -// You can specify any function mapping a GraphQL query AST (DocumentNode) to -// string as your signature algorithm by providing it as the 'signature' option -// to the EngineReportingAgent constructor. Ideally, your signature should be a -// valid GraphQL query, though as of now the Engine servers do not re-parse your -// signature and do not expect it to match the execution tree in the trace. -// -// This module utilizes several AST transformations from the adjacent -// 'transforms' module (which are also for writing your own signature method). - -// - dropUnusedDefinitions, which removes operations and fragments that -// aren't going to be used in execution -// - hideLiterals, which replaces all numeric and string literals as well -// as list and object input values with "empty" values -// - removeAliases, which removes field aliasing from the query -// - sortAST, which sorts the children of most multi-child nodes -// consistently -// - printWithReducedWhitespace, a variant on graphql-js's 'print' -// which gets rid of unneeded whitespace -// -// defaultSignature consists of applying all of these building blocks. -// -// Historical note: the default signature algorithm of the Go engineproxy -// performed all of the above operations, and the Engine servers then re-ran a -// mostly identical signature implementation on received traces. This was -// primarily to deal with edge cases where some users used literal interpolation -// instead of GraphQL variables, included randomized alias names, etc. In -// addition, the servers relied on the fact that dropUnusedDefinitions had been -// called in order (and that the signature could be parsed as GraphQL) to -// extract the name of the operation for display. This caused confusion, as the -// query document shown in the Engine UI wasn't the same as the one actually -// sent. apollo-engine-reporting uses a new reporting API which requires it to -// explicitly include the operation name with each signature; this means that -// 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 { - printWithReducedWhitespace, - dropUnusedDefinitions, - removeAliases, - sortAST, - hideLiterals, -} from './transforms'; - -// The default signature function consists of removing unused definitions -// and whitespace. -// XXX consider caching somehow -export function defaultEngineReportingSignature( - ast: DocumentNode, - operationName: string, -): string { - return printWithReducedWhitespace( - sortAST( - removeAliases(hideLiterals(dropUnusedDefinitions(ast, operationName))), - ), - ); -} diff --git a/packages/apollo-graphql/src/transforms.ts b/packages/apollo-graphql/src/transforms.ts deleted file mode 100644 index c8565f5c37f..00000000000 --- a/packages/apollo-graphql/src/transforms.ts +++ /dev/null @@ -1,199 +0,0 @@ -import { visit } from 'graphql/language/visitor'; -import { - DocumentNode, - FloatValueNode, - IntValueNode, - StringValueNode, - OperationDefinitionNode, - SelectionSetNode, - FragmentSpreadNode, - InlineFragmentNode, - DirectiveNode, - FieldNode, - FragmentDefinitionNode, - ObjectValueNode, - ListValueNode, -} from 'graphql/language/ast'; -import { print } from 'graphql/language/printer'; -import { separateOperations } from 'graphql/utilities'; -// We'll only fetch the `ListIteratee` type from the `@types/lodash`, but get -// `sortBy` from the modularized version of the package to avoid bringing in -// all of `lodash`. -import { ListIteratee } from 'lodash'; -import sortBy from 'lodash.sortby'; - -// Replace numeric, string, list, and object literals with "empty" -// values. Leaves enums alone (since there's no consistent "zero" enum). This -// can help combine similar queries if you substitute values directly into -// queries rather than use GraphQL variables, and can hide sensitive data in -// your query (say, a hardcoded API key) from Engine servers, but in general -// avoiding those situations is better than working around them. -export function hideLiterals(ast: DocumentNode): DocumentNode { - return visit(ast, { - IntValue(node: IntValueNode): IntValueNode { - return { ...node, value: '0' }; - }, - FloatValue(node: FloatValueNode): FloatValueNode { - return { ...node, value: '0' }; - }, - StringValue(node: StringValueNode): StringValueNode { - return { ...node, value: '', block: false }; - }, - ListValue(node: ListValueNode): ListValueNode { - return { ...node, values: [] }; - }, - ObjectValue(node: ObjectValueNode): ObjectValueNode { - return { ...node, fields: [] }; - }, - }); -} - -// In the same spirit as the similarly named `hideLiterals` function, only -// hide string and numeric literals. -export function hideStringAndNumericLiterals(ast: DocumentNode): DocumentNode { - return visit(ast, { - IntValue(node: IntValueNode): IntValueNode { - return { ...node, value: '0' }; - }, - FloatValue(node: FloatValueNode): FloatValueNode { - return { ...node, value: '0' }; - }, - StringValue(node: StringValueNode): StringValueNode { - return { ...node, value: '', block: false }; - }, - }); -} - -// A GraphQL query may contain multiple named operations, with the operation to -// use specified separately by the client. This transformation drops unused -// operations from the query, as well as any fragment definitions that are not -// referenced. (In general we recommend that unused definitions are dropped on -// the client before sending to the server to save bandwidth and parsing time.) -export function dropUnusedDefinitions( - ast: DocumentNode, - operationName: string, -): DocumentNode { - const separated = separateOperations(ast)[operationName]; - if (!separated) { - // If the given operationName isn't found, just make this whole transform a - // no-op instead of crashing. - return ast; - } - return separated; -} - -// Like lodash's sortBy, but sorted(undefined) === undefined rather than []. It -// is a stable non-in-place sort. -function sorted( - items: ReadonlyArray | undefined, - ...iteratees: Array> -): Array | undefined { - if (items) { - return sortBy(items, ...iteratees); - } - return undefined; -} - -// sortAST sorts most multi-child nodes alphabetically. Using this as part of -// your signature calculation function may make it easier to tell the difference -// between queries that are similar to each other, and if for some reason your -// GraphQL client generates query strings with elements in nondeterministic -// order, it can make sure the queries are treated as identical. -export function sortAST(ast: DocumentNode): DocumentNode { - return visit(ast, { - OperationDefinition( - node: OperationDefinitionNode, - ): OperationDefinitionNode { - return { - ...node, - variableDefinitions: sorted( - node.variableDefinitions, - 'variable.name.value', - ), - }; - }, - SelectionSet(node: SelectionSetNode): SelectionSetNode { - return { - ...node, - // Define an ordering for field names in a SelectionSet. Field first, - // then FragmentSpread, then InlineFragment. By a lovely coincidence, - // the order we want them to appear in is alphabetical by node.kind. - // Use sortBy instead of sorted because 'selections' is not optional. - selections: sortBy(node.selections, 'kind', 'name.value'), - }; - }, - Field(node: FieldNode): FieldNode { - return { - ...node, - arguments: sorted(node.arguments, 'name.value'), - }; - }, - FragmentSpread(node: FragmentSpreadNode): FragmentSpreadNode { - return { ...node, directives: sorted(node.directives, 'name.value') }; - }, - InlineFragment(node: InlineFragmentNode): InlineFragmentNode { - return { ...node, directives: sorted(node.directives, 'name.value') }; - }, - FragmentDefinition(node: FragmentDefinitionNode): FragmentDefinitionNode { - return { - ...node, - directives: sorted(node.directives, 'name.value'), - variableDefinitions: sorted( - node.variableDefinitions, - 'variable.name.value', - ), - }; - }, - Directive(node: DirectiveNode): DirectiveNode { - return { ...node, arguments: sorted(node.arguments, 'name.value') }; - }, - }); -} - -// removeAliases gets rid of GraphQL aliases, a feature by which you can tell a -// server to return a field's data under a different name from the field -// name. Maybe this is useful if somebody somewhere inserts random aliases into -// their queries. -export function removeAliases(ast: DocumentNode): DocumentNode { - return visit(ast, { - Field(node: FieldNode): FieldNode { - return { - ...node, - alias: undefined, - }; - }, - }); -} - -// Like the graphql-js print function, but deleting whitespace wherever -// feasible. Specifically, all whitespace (outside of string literals) is -// reduced to at most one space, and even that space is removed anywhere except -// for between two alphanumerics. -export function printWithReducedWhitespace(ast: DocumentNode): string { - // In a GraphQL AST (which notably does not contain comments), the only place - // where meaningful whitespace (or double quotes) can exist is in - // StringNodes. So to print with reduced whitespace, we: - // - temporarily sanitize strings by replacing their contents with hex - // - use the default GraphQL printer - // - minimize the whitespace with a simple regexp replacement - // - convert strings back to their actual value - // We normalize all strings to non-block strings for simplicity. - - const sanitizedAST = visit(ast, { - StringValue(node: StringValueNode): StringValueNode { - return { - ...node, - value: Buffer.from(node.value, 'utf8').toString('hex'), - block: false, - }; - }, - }); - const withWhitespace = print(sanitizedAST); - const minimizedButStillHex = withWhitespace - .replace(/\s+/g, ' ') - .replace(/([^_a-zA-Z0-9]) /g, (_, c) => c) - .replace(/ ([^_a-zA-Z0-9])/g, (_, c) => c); - return minimizedButStillHex.replace(/"([a-f0-9]+)"/g, (_, hex) => - JSON.stringify(Buffer.from(hex, 'hex').toString('utf8')), - ); -} diff --git a/packages/apollo-graphql/tsconfig.json b/packages/apollo-graphql/tsconfig.json deleted file mode 100644 index 4fcb63fe14f..00000000000 --- a/packages/apollo-graphql/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "../../tsconfig.base", - "compilerOptions": { - "rootDir": "./src", - "outDir": "./dist" - }, - "include": ["src/**/*"], - "exclude": ["**/__tests__", "**/__mocks__"], - "references": [] -} diff --git a/tsconfig.build.json b/tsconfig.build.json index ebb88ce4ba9..24a42b86b9e 100644 --- a/tsconfig.build.json +++ b/tsconfig.build.json @@ -9,7 +9,6 @@ { "path": "./packages/apollo-datasource" }, { "path": "./packages/apollo-datasource-rest" }, { "path": "./packages/apollo-engine-reporting" }, - { "path": "./packages/apollo-graphql" }, { "path": "./packages/apollo-server" }, { "path": "./packages/apollo-server-azure-functions" }, { "path": "./packages/apollo-server-cache-memcached" }, diff --git a/tsconfig.test.json b/tsconfig.test.json index 85f4028c15d..1d906e03b7a 100644 --- a/tsconfig.test.json +++ b/tsconfig.test.json @@ -8,7 +8,6 @@ { "path": "./packages/apollo-cache-control/src/__tests__/" }, { "path": "./packages/apollo-datasource-rest/src/__tests__/" }, { "path": "./packages/apollo-engine-reporting/src/__tests__/" }, - { "path": "./packages/apollo-graphql/src/__tests__/" }, { "path": "./packages/apollo-server/src/__tests__/" }, { "path": "./packages/apollo-server-azure-functions/src/__tests__/" }, { "path": "./packages/apollo-server-cache-memcached/src/__tests__/" }, From f0b659215805bd1c41172ff0c3d9c120c693be3e Mon Sep 17 00:00:00 2001 From: Trevor Scheer Date: Wed, 13 Feb 2019 17:32:49 -0800 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 71041ea624a..5d28da16e47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Allow passing `parseOptions` to `ApolloServerBase` constructor. [PR #2289](https://github.com/apollographql/apollo-server/pull/2289) - Rename `azureFunctions.d.ts` to `azureFunctions.ts`. [PR #2287](https://github.com/apollographql/apollo-server/pull/2287) - Require `apollo-engine-reporting` only if `EngineReportingAgent` used. [PR #2305](https://github.com/apollographql/apollo-server/pull/2305) +- Move `apollo-graphql` package to the `apollo-tooling` repository [PR #2316](https://github.com/apollographql/apollo-server/pull/2316) ### v2.4.0