apollo-graphql
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "apollo-graphql", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Apollo GraphQL utility library", | ||
"main": "dist/index.js", | ||
"types": "dist/index.d.ts", | ||
"main": "lib/index.js", | ||
"types": "lib/index.d.ts", | ||
"keywords": [], | ||
@@ -17,5 +17,35 @@ "author": "Apollo <opensource@apollographql.com>", | ||
"peerDependencies": { | ||
"graphql": "^14.0.0" | ||
"graphql": "^14.0.2" | ||
}, | ||
"gitHead": "a3222ece11f04ada75ce9c592efcf337396951ec" | ||
"jest": { | ||
"preset": "ts-jest", | ||
"transformIgnorePatterns": [ | ||
"/node_modules/", | ||
"/apollo-env/" | ||
], | ||
"testEnvironment": "node", | ||
"testMatch": [ | ||
"**/__tests__/*.(js|ts)" | ||
], | ||
"setupFiles": [ | ||
"<rootDir>/../apollo-env/lib/index.js" | ||
], | ||
"testPathIgnorePatterns": [ | ||
"<rootDir>/node_modules/", | ||
"<rootDir>/lib/", | ||
"<rootDir>/test/fixtures/", | ||
"<rootDir>/test/test-utils" | ||
], | ||
"moduleFileExtensions": [ | ||
"ts", | ||
"js" | ||
], | ||
"globals": { | ||
"ts-jest": { | ||
"tsConfig": "<rootDir>/tsconfig.test.json", | ||
"diagnostics": false | ||
} | ||
} | ||
}, | ||
"gitHead": "b5cdf815f9d9c9186121b98fffeabd156cb08e9e" | ||
} |
@@ -1,3 +0,3 @@ | ||
import { DocumentNode } from 'graphql'; | ||
import { default as gql, disableFragmentWarnings } from 'graphql-tag'; | ||
import { DocumentNode } from "graphql"; | ||
import { default as gql, disableFragmentWarnings } from "graphql-tag"; | ||
@@ -9,4 +9,4 @@ import { | ||
sortAST, | ||
removeAliases, | ||
} from '../transforms'; | ||
removeAliases | ||
} from "../transforms"; | ||
@@ -17,8 +17,8 @@ // The gql duplicate fragment warning feature really is just warnings; nothing | ||
describe('aggressive signature', () => { | ||
describe("aggressive signature", () => { | ||
function aggressive(ast: DocumentNode, operationName: string): string { | ||
return printWithReducedWhitespace( | ||
removeAliases( | ||
hideLiterals(sortAST(dropUnusedDefinitions(ast, operationName))), | ||
), | ||
hideLiterals(sortAST(dropUnusedDefinitions(ast, operationName))) | ||
) | ||
); | ||
@@ -30,4 +30,4 @@ } | ||
{ | ||
name: 'basic test', | ||
operationName: '', | ||
name: "basic test", | ||
operationName: "", | ||
input: gql` | ||
@@ -40,7 +40,7 @@ { | ||
`, | ||
output: '{user{name}}', | ||
output: "{user{name}}" | ||
}, | ||
{ | ||
name: 'basic test with query', | ||
operationName: '', | ||
name: "basic test with query", | ||
operationName: "", | ||
input: gql` | ||
@@ -53,7 +53,7 @@ query { | ||
`, | ||
output: '{user{name}}', | ||
output: "{user{name}}" | ||
}, | ||
{ | ||
name: 'basic with operation name', | ||
operationName: 'OpName', | ||
name: "basic with operation name", | ||
operationName: "OpName", | ||
input: gql` | ||
@@ -66,7 +66,7 @@ query OpName { | ||
`, | ||
output: 'query OpName{user{name}}', | ||
output: "query OpName{user{name}}" | ||
}, | ||
{ | ||
name: 'with various inline types', | ||
operationName: 'OpName', | ||
name: "with various inline types", | ||
operationName: "OpName", | ||
input: gql` | ||
@@ -79,7 +79,7 @@ query OpName { | ||
`, | ||
output: 'query OpName{user{name(apple:[],bag:{},cat:ENUM_VALUE)}}', | ||
output: "query OpName{user{name(apple:[],bag:{},cat:ENUM_VALUE)}}" | ||
}, | ||
{ | ||
name: 'with various argument types', | ||
operationName: 'OpName', | ||
name: "with various argument types", | ||
operationName: "OpName", | ||
input: gql` | ||
@@ -93,7 +93,7 @@ query OpName($c: Int!, $a: [[Boolean!]!], $b: EnumType) { | ||
output: | ||
'query OpName($a:[[Boolean!]!],$b:EnumType,$c:Int!){user{name(apple:$a,bag:$b,cat:$c)}}', | ||
"query OpName($a:[[Boolean!]!],$b:EnumType,$c:Int!){user{name(apple:$a,bag:$b,cat:$c)}}" | ||
}, | ||
{ | ||
name: 'fragment', | ||
operationName: '', | ||
name: "fragment", | ||
operationName: "", | ||
input: gql` | ||
@@ -115,7 +115,7 @@ { | ||
`, | ||
output: '{user{name...Bar}}fragment Bar on User{asd}', | ||
output: "{user{name...Bar}}fragment Bar on User{asd}" | ||
}, | ||
{ | ||
name: 'full test', | ||
operationName: 'Foo', | ||
name: "full test", | ||
operationName: "Foo", | ||
input: gql` | ||
@@ -149,4 +149,4 @@ query Foo($b: Int, $a: Boolean) { | ||
'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}', | ||
}, | ||
"fragment Bar on User{age@skip(if:$a)...Nested}fragment Nested on User{blah}" | ||
} | ||
]; | ||
@@ -153,0 +153,0 @@ cases.forEach(({ name, operationName, input, output }) => { |
@@ -1,4 +0,4 @@ | ||
import { default as gql, disableFragmentWarnings } from 'graphql-tag'; | ||
import { default as gql, disableFragmentWarnings } from "graphql-tag"; | ||
import { printWithReducedWhitespace, hideLiterals } from '../transforms'; | ||
import { printWithReducedWhitespace, hideLiterals } from "../transforms"; | ||
@@ -9,6 +9,6 @@ // The gql duplicate fragment warning feature really is just warnings; nothing | ||
describe('printWithReducedWhitespace', () => { | ||
describe("printWithReducedWhitespace", () => { | ||
const cases = [ | ||
{ | ||
name: 'lots of whitespace', | ||
name: "lots of whitespace", | ||
// Note: there's a tab after "tab->", which prettier wants to keep as a | ||
@@ -32,4 +32,4 @@ // literal tab rather than \t. In the output, there should be a literal | ||
output: | ||
'query Foo($a:Int){user(name:" tab->\\tyay",other:"apple\\n bag\\ncat"){name}}', | ||
}, | ||
'query Foo($a:Int){user(name:" tab->\\tyay",other:"apple\\n bag\\ncat"){name}}' | ||
} | ||
]; | ||
@@ -43,6 +43,6 @@ cases.forEach(({ name, input, output }) => { | ||
describe('hideLiterals', () => { | ||
describe("hideLiterals", () => { | ||
const cases = [ | ||
{ | ||
name: 'full test', | ||
name: "full test", | ||
input: gql` | ||
@@ -72,4 +72,4 @@ query Foo($b: Int, $a: Boolean) { | ||
'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}', | ||
}, | ||
"fragment Bar on User{age@skip(if:$a)...Nested}fragment Nested on User{blah}" | ||
} | ||
]; | ||
@@ -76,0 +76,0 @@ cases.forEach(({ name, input, output }) => { |
@@ -1,1 +0,1 @@ | ||
export { defaultEngineReportingSignature } from './signature'; | ||
export { defaultEngineReportingSignature } from "./signature"; |
@@ -47,3 +47,3 @@ // In Engine, we want to group requests making the same query together, and | ||
import { DocumentNode } from 'graphql'; | ||
import { DocumentNode } from "graphql"; | ||
import { | ||
@@ -54,4 +54,4 @@ printWithReducedWhitespace, | ||
sortAST, | ||
hideLiterals, | ||
} from './transforms'; | ||
hideLiterals | ||
} from "./transforms"; | ||
@@ -63,9 +63,9 @@ // The default signature function consists of removing unused definitions | ||
ast: DocumentNode, | ||
operationName: string, | ||
operationName: string | ||
): string { | ||
return printWithReducedWhitespace( | ||
sortAST( | ||
removeAliases(hideLiterals(dropUnusedDefinitions(ast, operationName))), | ||
), | ||
removeAliases(hideLiterals(dropUnusedDefinitions(ast, operationName))) | ||
) | ||
); | ||
} |
@@ -1,2 +0,2 @@ | ||
import { visit } from 'graphql/language/visitor'; | ||
import { visit } from "graphql/language/visitor"; | ||
import { | ||
@@ -15,11 +15,11 @@ DocumentNode, | ||
ObjectValueNode, | ||
ListValueNode, | ||
} from 'graphql/language/ast'; | ||
import { print } from 'graphql/language/printer'; | ||
import { separateOperations } from 'graphql/utilities'; | ||
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'; | ||
import { ListIteratee } from "lodash"; | ||
import sortBy from "lodash.sortby"; | ||
@@ -35,9 +35,9 @@ // Replace numeric, string, list, and object literals with "empty" | ||
IntValue(node: IntValueNode): IntValueNode { | ||
return { ...node, value: '0' }; | ||
return { ...node, value: "0" }; | ||
}, | ||
FloatValue(node: FloatValueNode): FloatValueNode { | ||
return { ...node, value: '0' }; | ||
return { ...node, value: "0" }; | ||
}, | ||
StringValue(node: StringValueNode): StringValueNode { | ||
return { ...node, value: '', block: false }; | ||
return { ...node, value: "", block: false }; | ||
}, | ||
@@ -49,3 +49,3 @@ ListValue(node: ListValueNode): ListValueNode { | ||
return { ...node, fields: [] }; | ||
}, | ||
} | ||
}); | ||
@@ -59,10 +59,10 @@ } | ||
IntValue(node: IntValueNode): IntValueNode { | ||
return { ...node, value: '0' }; | ||
return { ...node, value: "0" }; | ||
}, | ||
FloatValue(node: FloatValueNode): FloatValueNode { | ||
return { ...node, value: '0' }; | ||
return { ...node, value: "0" }; | ||
}, | ||
StringValue(node: StringValueNode): StringValueNode { | ||
return { ...node, value: '', block: false }; | ||
}, | ||
return { ...node, value: "", block: false }; | ||
} | ||
}); | ||
@@ -78,3 +78,3 @@ } | ||
ast: DocumentNode, | ||
operationName: string, | ||
operationName: string | ||
): DocumentNode { | ||
@@ -110,3 +110,3 @@ const separated = separateOperations(ast)[operationName]; | ||
OperationDefinition( | ||
node: OperationDefinitionNode, | ||
node: OperationDefinitionNode | ||
): OperationDefinitionNode { | ||
@@ -117,4 +117,4 @@ return { | ||
node.variableDefinitions, | ||
'variable.name.value', | ||
), | ||
"variable.name.value" | ||
) | ||
}; | ||
@@ -129,3 +129,3 @@ }, | ||
// Use sortBy instead of sorted because 'selections' is not optional. | ||
selections: sortBy(node.selections, 'kind', 'name.value'), | ||
selections: sortBy(node.selections, "kind", "name.value") | ||
}; | ||
@@ -136,10 +136,10 @@ }, | ||
...node, | ||
arguments: sorted(node.arguments, 'name.value'), | ||
arguments: sorted(node.arguments, "name.value") | ||
}; | ||
}, | ||
FragmentSpread(node: FragmentSpreadNode): FragmentSpreadNode { | ||
return { ...node, directives: sorted(node.directives, 'name.value') }; | ||
return { ...node, directives: sorted(node.directives, "name.value") }; | ||
}, | ||
InlineFragment(node: InlineFragmentNode): InlineFragmentNode { | ||
return { ...node, directives: sorted(node.directives, 'name.value') }; | ||
return { ...node, directives: sorted(node.directives, "name.value") }; | ||
}, | ||
@@ -149,12 +149,12 @@ FragmentDefinition(node: FragmentDefinitionNode): FragmentDefinitionNode { | ||
...node, | ||
directives: sorted(node.directives, 'name.value'), | ||
directives: sorted(node.directives, "name.value"), | ||
variableDefinitions: sorted( | ||
node.variableDefinitions, | ||
'variable.name.value', | ||
), | ||
"variable.name.value" | ||
) | ||
}; | ||
}, | ||
Directive(node: DirectiveNode): DirectiveNode { | ||
return { ...node, arguments: sorted(node.arguments, 'name.value') }; | ||
}, | ||
return { ...node, arguments: sorted(node.arguments, "name.value") }; | ||
} | ||
}); | ||
@@ -172,5 +172,5 @@ } | ||
...node, | ||
alias: undefined, | ||
alias: undefined | ||
}; | ||
}, | ||
} | ||
}); | ||
@@ -197,15 +197,15 @@ } | ||
...node, | ||
value: Buffer.from(node.value, 'utf8').toString('hex'), | ||
block: false, | ||
value: Buffer.from(node.value, "utf8").toString("hex"), | ||
block: false | ||
}; | ||
}, | ||
} | ||
}); | ||
const withWhitespace = print(sanitizedAST); | ||
const minimizedButStillHex = withWhitespace | ||
.replace(/\s+/g, ' ') | ||
.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')), | ||
JSON.stringify(Buffer.from(hex, "hex").toString("utf8")) | ||
); | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28435