@graphql-tools/documents
Advanced tools
Comparing version 1.0.0 to 1.0.1-rc-20240527102513-c1d3920eae85fae308bbb764ae936a2827436d8e
@@ -10,2 +10,5 @@ "use strict"; | ||
function sortExecutableDocument(document) { | ||
const ignoredNodes = new WeakSet(); | ||
const ignoredSelectionsArr = new Set(); | ||
const ignoredFragments = new Set(); | ||
return (0, graphql_1.visit)(document, { | ||
@@ -19,2 +22,6 @@ Document(node) { | ||
OperationDefinition(node) { | ||
if (node.operation === 'mutation') { | ||
ignoredNodes.add(node.selectionSet); | ||
ignoredSelectionsArr.add(node.selectionSet.selections); | ||
} | ||
return { | ||
@@ -26,2 +33,6 @@ ...node, | ||
SelectionSet(node) { | ||
if (ignoredNodes.has(node)) { | ||
ignoredSelectionsArr.add(node.selections); | ||
return node; | ||
} | ||
return { | ||
@@ -32,3 +43,6 @@ ...node, | ||
}, | ||
FragmentSpread(node) { | ||
FragmentSpread(node, _key, parent) { | ||
if (Array.isArray(parent) && ignoredSelectionsArr.has(parent)) { | ||
ignoredFragments.add(node.name.value); | ||
} | ||
return { | ||
@@ -39,3 +53,8 @@ ...node, | ||
}, | ||
InlineFragment(node) { | ||
InlineFragment(node, _key, parent) { | ||
if (Array.isArray(parent) && ignoredSelectionsArr.has(parent)) { | ||
ignoredNodes.add(node.selectionSet); | ||
ignoredSelectionsArr.add(node.selectionSet.selections); | ||
return node; | ||
} | ||
return { | ||
@@ -47,2 +66,5 @@ ...node, | ||
FragmentDefinition(node) { | ||
if (ignoredFragments.has(node.name.value)) { | ||
return node; | ||
} | ||
return { | ||
@@ -49,0 +71,0 @@ ...node, |
@@ -7,2 +7,5 @@ import { visit } from 'graphql'; | ||
export function sortExecutableDocument(document) { | ||
const ignoredNodes = new WeakSet(); | ||
const ignoredSelectionsArr = new Set(); | ||
const ignoredFragments = new Set(); | ||
return visit(document, { | ||
@@ -16,2 +19,6 @@ Document(node) { | ||
OperationDefinition(node) { | ||
if (node.operation === 'mutation') { | ||
ignoredNodes.add(node.selectionSet); | ||
ignoredSelectionsArr.add(node.selectionSet.selections); | ||
} | ||
return { | ||
@@ -23,2 +30,6 @@ ...node, | ||
SelectionSet(node) { | ||
if (ignoredNodes.has(node)) { | ||
ignoredSelectionsArr.add(node.selections); | ||
return node; | ||
} | ||
return { | ||
@@ -29,3 +40,6 @@ ...node, | ||
}, | ||
FragmentSpread(node) { | ||
FragmentSpread(node, _key, parent) { | ||
if (Array.isArray(parent) && ignoredSelectionsArr.has(parent)) { | ||
ignoredFragments.add(node.name.value); | ||
} | ||
return { | ||
@@ -36,3 +50,8 @@ ...node, | ||
}, | ||
InlineFragment(node) { | ||
InlineFragment(node, _key, parent) { | ||
if (Array.isArray(parent) && ignoredSelectionsArr.has(parent)) { | ||
ignoredNodes.add(node.selectionSet); | ||
ignoredSelectionsArr.add(node.selectionSet.selections); | ||
return node; | ||
} | ||
return { | ||
@@ -44,2 +63,5 @@ ...node, | ||
FragmentDefinition(node) { | ||
if (ignoredFragments.has(node.name.value)) { | ||
return node; | ||
} | ||
return { | ||
@@ -46,0 +68,0 @@ ...node, |
{ | ||
"name": "@graphql-tools/documents", | ||
"version": "1.0.0", | ||
"version": "1.0.1-rc-20240527102513-c1d3920eae85fae308bbb764ae936a2827436d8e", | ||
"description": "Utilities for GraphQL documents.", | ||
@@ -10,4 +10,4 @@ "sideEffects": false, | ||
"dependencies": { | ||
"tslib": "^2.4.0", | ||
"lodash.sortby": "^4.7.0" | ||
"lodash.sortby": "^4.7.0", | ||
"tslib": "^2.4.0" | ||
}, | ||
@@ -14,0 +14,0 @@ "repository": { |
@@ -15,5 +15,4 @@ # `@graphql-tools/documents` | ||
A stable way to print a GraphQL document. | ||
All executable/fragment variable definitions, fields are printed in a stable way. | ||
Useful for stuff like persisted GraphQL operations. | ||
A stable way to print a GraphQL document. All executable/fragment variable definitions, fields are | ||
printed in a stable way. Useful for stuff like persisted GraphQL operations. | ||
@@ -48,3 +47,4 @@ #### Usage | ||
console.assert( | ||
outputStr === 'fragment B on Query { c } query A { ... on Query { a { a ...B } } ... on Query { a { b ...B } } }', | ||
outputStr === | ||
'fragment B on Query { c } query A { ... on Query { a { a ...B } } ... on Query { a { b ...B } } }', | ||
'Stuff is not equal.' | ||
@@ -59,2 +59,3 @@ ) | ||
- Arguments (Directive, Fields) are sorted alphabetical | ||
- Selections sets are sorted Field, FragmentSpread, InlineFragmentSpread (sorted based on TypeCondition, inner SelectionSet) | ||
- Selections sets are sorted Field, FragmentSpread, InlineFragmentSpread (sorted based on | ||
TypeCondition, inner SelectionSet) |
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
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
18580
328
59
2