🚀 Big News:Socket Has Acquired Secure Annex.Learn More
Socket
Book a DemoSign in
Socket

@apollo/utils.printwithreducedwhitespace

Package Overview
Dependencies
Maintainers
3
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@apollo/utils.printwithreducedwhitespace - npm Package Compare versions

Comparing version
1.1.0
to
2.0.0
+20
README.md
# printWithReducedWhitespace
Prints a GraphQL AST with a minimal amount of whitespace. Consider using the
[`stripIgnoredCharacters`](https://github.com/graphql/graphql-js/blob/e9a81f2ba9020ec5fd0f67f5553ccabe392e95e8/src/utilities/stripIgnoredCharacters.ts) function from `graphql` instead of this function.
## Usage
```ts
import { printWithReducedWhitespace } from "@apollo/utils.operationregistrysignature";
const signature = operationRegistrySignature(
parse(`#graphql
query Foo {
bar
}
`),
"Foo",
{ preserveStringAndNumericLiterals: true },
);
```
+3
-6
{
"name": "@apollo/utils.printwithreducedwhitespace",
"version": "1.1.0",
"version": "2.0.0",
"description": "Print an AST with as little whitespace as possible",

@@ -10,3 +10,3 @@ "main": "dist/index.js",

"url": "git+https://github.com/apollographql/apollo-utils.git",
"directory": "printWithReducedWhitespace/"
"directory": "packages/printWithReducedWhitespace/"
},

@@ -22,7 +22,4 @@ "keywords": [

"engines": {
"node": ">=12.13.0"
"node": ">=14"
},
"publishConfig": {
"access": "public"
},
"peerDependencies": {

@@ -29,0 +26,0 @@ "graphql": "14.x || 15.x || 16.x"

@@ -5,31 +5,25 @@ import gql from "graphql-tag";

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
}
it("removes 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.
const document = 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);
});
}
`;
expect(printWithReducedWhitespace(document)).toBe(
`query Foo($a:Int){user(name:" tab->\\tyay"other:"apple\\n bag\\ncat"){name}}`,
);
});
});