@graphql-tools/utils 8.1.0 → 8.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/es5/helpers.d.ts CHANGED
@@ -1,10 +1,8 @@
1
1
  import { ASTNode } from 'graphql';
2
2
  export declare const asArray: <T>(fns: T | T[]) => T[];
3
- export declare function isEqual<T>(a: T, b: T): boolean;
4
- export declare function isNotEqual<T>(a: T, b: T): boolean;
5
- export declare function isDocumentString(str: string): boolean;
6
- export declare function isValidPath(str: string): boolean;
7
- export declare function compareStrings<A, B>(a: A, b: B): 0 | 1 | -1;
3
+ export declare function isDocumentString(str: any): boolean;
4
+ export declare function isValidPath(str: any): boolean;
5
+ export declare function compareStrings<A, B>(a: A, b: B): 1 | -1 | 0;
8
6
  export declare function nodeToString(a: ASTNode): string;
9
7
  export declare function compareNodes(a: ASTNode, b: ASTNode, customFn?: (a: any, b: any) => number): number;
10
8
  export declare function isSome<T>(input: T): input is Exclude<T, null | undefined>;
package/es5/index.js CHANGED
@@ -11,30 +11,17 @@ const blockString_js = require('graphql/language/blockString.js');
11
11
  const execute_js = require('graphql/execution/execute.js');
12
12
 
13
13
  var asArray = function (fns) { return (Array.isArray(fns) ? fns : fns ? [fns] : []); };
14
- function isEqual(a, b) {
15
- if (Array.isArray(a) && Array.isArray(b)) {
16
- if (a.length !== b.length) {
17
- return false;
18
- }
19
- for (var index = 0; index < a.length; index++) {
20
- if (a[index] !== b[index]) {
21
- return false;
22
- }
23
- }
24
- return true;
25
- }
26
- return a === b || (!a && !b);
27
- }
28
- function isNotEqual(a, b) {
29
- return !isEqual(a, b);
30
- }
14
+ var invalidDocRegex = /\.[a-z0-9]+$/i;
31
15
  function isDocumentString(str) {
16
+ if (typeof str !== 'string') {
17
+ return false;
18
+ }
32
19
  // XXX: is-valid-path or is-glob treat SDL as a valid path
33
20
  // (`scalar Date` for example)
34
21
  // this why checking the extension is fast enough
35
22
  // and prevent from parsing the string in order to find out
36
23
  // if the string is a SDL
37
- if (/\.[a-z0-9]+$/i.test(str)) {
24
+ if (invalidDocRegex.test(str)) {
38
25
  return false;
39
26
  }
40
27
  try {
@@ -1537,19 +1524,21 @@ function resetFieldMap() {
1537
1524
  fieldTypeMap = new Map();
1538
1525
  }
1539
1526
  function buildOperationNodeForField(_a) {
1540
- var schema = _a.schema, kind = _a.kind, field = _a.field, models = _a.models, ignore = _a.ignore, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, argNames = _a.argNames, _b = _a.selectedFields, selectedFields = _b === void 0 ? true : _b;
1527
+ var schema = _a.schema, kind = _a.kind, field = _a.field, models = _a.models, _b = _a.ignore, ignore = _b === void 0 ? [] : _b, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, argNames = _a.argNames, _c = _a.selectedFields, selectedFields = _c === void 0 ? true : _c;
1541
1528
  resetOperationVariables();
1542
1529
  resetFieldMap();
1530
+ var rootTypeNames = getRootTypeNames(schema);
1543
1531
  var operationNode = buildOperationAndCollectVariables({
1544
1532
  schema: schema,
1545
1533
  fieldName: field,
1546
1534
  kind: kind,
1547
1535
  models: models || [],
1548
- ignore: ignore || [],
1536
+ ignore: ignore,
1549
1537
  depthLimit: depthLimit || Infinity,
1550
1538
  circularReferenceDepth: circularReferenceDepth || 1,
1551
1539
  argNames: argNames,
1552
1540
  selectedFields: selectedFields,
1541
+ rootTypeNames: rootTypeNames,
1553
1542
  });
1554
1543
  // attach variables
1555
1544
  operationNode.variableDefinitions = tslib.__spreadArray([], tslib.__read(operationVariables));
@@ -1559,7 +1548,7 @@ function buildOperationNodeForField(_a) {
1559
1548
  }
1560
1549
  function buildOperationAndCollectVariables(_a) {
1561
1550
  var e_1, _b;
1562
- var schema = _a.schema, fieldName = _a.fieldName, kind = _a.kind, models = _a.models, ignore = _a.ignore, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, argNames = _a.argNames, selectedFields = _a.selectedFields;
1551
+ var schema = _a.schema, fieldName = _a.fieldName, kind = _a.kind, models = _a.models, ignore = _a.ignore, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, argNames = _a.argNames, selectedFields = _a.selectedFields, rootTypeNames = _a.rootTypeNames;
1563
1552
  var type = getDefinedRootType(schema, kind);
1564
1553
  var field = type.getFields()[fieldName];
1565
1554
  var operationName = fieldName + "_" + kind;
@@ -1606,13 +1595,14 @@ function buildOperationAndCollectVariables(_a) {
1606
1595
  depth: 0,
1607
1596
  argNames: argNames,
1608
1597
  selectedFields: selectedFields,
1598
+ rootTypeNames: rootTypeNames,
1609
1599
  }),
1610
1600
  ],
1611
1601
  },
1612
1602
  };
1613
1603
  }
1614
1604
  function resolveSelectionSet(_a) {
1615
- var parent = _a.parent, type = _a.type, models = _a.models, firstCall = _a.firstCall, path = _a.path, ancestors = _a.ancestors, ignore = _a.ignore, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, schema = _a.schema, depth = _a.depth, argNames = _a.argNames, selectedFields = _a.selectedFields;
1605
+ var parent = _a.parent, type = _a.type, models = _a.models, firstCall = _a.firstCall, path = _a.path, ancestors = _a.ancestors, ignore = _a.ignore, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, schema = _a.schema, depth = _a.depth, argNames = _a.argNames, selectedFields = _a.selectedFields, rootTypeNames = _a.rootTypeNames;
1616
1606
  if (typeof selectedFields === 'boolean' && depth > depthLimit) {
1617
1607
  return;
1618
1608
  }
@@ -1649,6 +1639,7 @@ function resolveSelectionSet(_a) {
1649
1639
  depth: depth,
1650
1640
  argNames: argNames,
1651
1641
  selectedFields: selectedFields,
1642
+ rootTypeNames: rootTypeNames,
1652
1643
  }),
1653
1644
  };
1654
1645
  })
@@ -1688,13 +1679,14 @@ function resolveSelectionSet(_a) {
1688
1679
  depth: depth,
1689
1680
  argNames: argNames,
1690
1681
  selectedFields: selectedFields,
1682
+ rootTypeNames: rootTypeNames,
1691
1683
  }),
1692
1684
  };
1693
1685
  })
1694
1686
  .filter(function (fragmentNode) { var _a, _b; return ((_b = (_a = fragmentNode === null || fragmentNode === void 0 ? void 0 : fragmentNode.selectionSet) === null || _a === void 0 ? void 0 : _a.selections) === null || _b === void 0 ? void 0 : _b.length) > 0; }),
1695
1687
  };
1696
1688
  }
1697
- if (graphql.isObjectType(type)) {
1689
+ if (graphql.isObjectType(type) && !rootTypeNames.has(type.name)) {
1698
1690
  var isIgnored = ignore.includes(type.name) || ignore.includes(parent.name + "." + path[path.length - 1]);
1699
1691
  var isModel = models.includes(type.name);
1700
1692
  if (!firstCall && isModel && !isIgnored) {
@@ -1736,6 +1728,7 @@ function resolveSelectionSet(_a) {
1736
1728
  depth: depth,
1737
1729
  argNames: argNames,
1738
1730
  selectedFields: selectedSubFields,
1731
+ rootTypeNames: rootTypeNames,
1739
1732
  });
1740
1733
  }
1741
1734
  return null;
@@ -1791,7 +1784,7 @@ function getArgumentName(name, path) {
1791
1784
  return tslib.__spreadArray(tslib.__spreadArray([], tslib.__read(path)), [name]).join('_');
1792
1785
  }
1793
1786
  function resolveField(_a) {
1794
- var type = _a.type, field = _a.field, models = _a.models, firstCall = _a.firstCall, path = _a.path, ancestors = _a.ancestors, ignore = _a.ignore, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, schema = _a.schema, depth = _a.depth, argNames = _a.argNames, selectedFields = _a.selectedFields;
1787
+ var type = _a.type, field = _a.field, models = _a.models, firstCall = _a.firstCall, path = _a.path, ancestors = _a.ancestors, ignore = _a.ignore, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, schema = _a.schema, depth = _a.depth, argNames = _a.argNames, selectedFields = _a.selectedFields, rootTypeNames = _a.rootTypeNames;
1795
1788
  var namedType = graphql.getNamedType(field.type);
1796
1789
  var args = [];
1797
1790
  var removeField = false;
@@ -1853,6 +1846,7 @@ function resolveField(_a) {
1853
1846
  depth: depth + 1,
1854
1847
  argNames: argNames,
1855
1848
  selectedFields: selectedFields,
1849
+ rootTypeNames: rootTypeNames,
1856
1850
  }) || undefined, arguments: args });
1857
1851
  }
1858
1852
  return tslib.__assign(tslib.__assign({ kind: graphql.Kind.FIELD, name: {
@@ -4480,9 +4474,7 @@ exports.isAsyncIterable = isAsyncIterable;
4480
4474
  exports.isDescribable = isDescribable;
4481
4475
  exports.isDocumentNode = isDocumentNode;
4482
4476
  exports.isDocumentString = isDocumentString;
4483
- exports.isEqual = isEqual;
4484
4477
  exports.isNamedStub = isNamedStub;
4485
- exports.isNotEqual = isNotEqual;
4486
4478
  exports.isSome = isSome;
4487
4479
  exports.isValidPath = isValidPath;
4488
4480
  exports.makeDeprecatedDirective = makeDeprecatedDirective;
package/es5/index.mjs CHANGED
@@ -5,30 +5,17 @@ import { dedentBlockStringValue } from 'graphql/language/blockString.js';
5
5
  import { collectFields } from 'graphql/execution/execute.js';
6
6
 
7
7
  var asArray = function (fns) { return (Array.isArray(fns) ? fns : fns ? [fns] : []); };
8
- function isEqual(a, b) {
9
- if (Array.isArray(a) && Array.isArray(b)) {
10
- if (a.length !== b.length) {
11
- return false;
12
- }
13
- for (var index = 0; index < a.length; index++) {
14
- if (a[index] !== b[index]) {
15
- return false;
16
- }
17
- }
18
- return true;
19
- }
20
- return a === b || (!a && !b);
21
- }
22
- function isNotEqual(a, b) {
23
- return !isEqual(a, b);
24
- }
8
+ var invalidDocRegex = /\.[a-z0-9]+$/i;
25
9
  function isDocumentString(str) {
10
+ if (typeof str !== 'string') {
11
+ return false;
12
+ }
26
13
  // XXX: is-valid-path or is-glob treat SDL as a valid path
27
14
  // (`scalar Date` for example)
28
15
  // this why checking the extension is fast enough
29
16
  // and prevent from parsing the string in order to find out
30
17
  // if the string is a SDL
31
- if (/\.[a-z0-9]+$/i.test(str)) {
18
+ if (invalidDocRegex.test(str)) {
32
19
  return false;
33
20
  }
34
21
  try {
@@ -1531,19 +1518,21 @@ function resetFieldMap() {
1531
1518
  fieldTypeMap = new Map();
1532
1519
  }
1533
1520
  function buildOperationNodeForField(_a) {
1534
- var schema = _a.schema, kind = _a.kind, field = _a.field, models = _a.models, ignore = _a.ignore, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, argNames = _a.argNames, _b = _a.selectedFields, selectedFields = _b === void 0 ? true : _b;
1521
+ var schema = _a.schema, kind = _a.kind, field = _a.field, models = _a.models, _b = _a.ignore, ignore = _b === void 0 ? [] : _b, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, argNames = _a.argNames, _c = _a.selectedFields, selectedFields = _c === void 0 ? true : _c;
1535
1522
  resetOperationVariables();
1536
1523
  resetFieldMap();
1524
+ var rootTypeNames = getRootTypeNames(schema);
1537
1525
  var operationNode = buildOperationAndCollectVariables({
1538
1526
  schema: schema,
1539
1527
  fieldName: field,
1540
1528
  kind: kind,
1541
1529
  models: models || [],
1542
- ignore: ignore || [],
1530
+ ignore: ignore,
1543
1531
  depthLimit: depthLimit || Infinity,
1544
1532
  circularReferenceDepth: circularReferenceDepth || 1,
1545
1533
  argNames: argNames,
1546
1534
  selectedFields: selectedFields,
1535
+ rootTypeNames: rootTypeNames,
1547
1536
  });
1548
1537
  // attach variables
1549
1538
  operationNode.variableDefinitions = __spreadArray([], __read(operationVariables));
@@ -1553,7 +1542,7 @@ function buildOperationNodeForField(_a) {
1553
1542
  }
1554
1543
  function buildOperationAndCollectVariables(_a) {
1555
1544
  var e_1, _b;
1556
- var schema = _a.schema, fieldName = _a.fieldName, kind = _a.kind, models = _a.models, ignore = _a.ignore, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, argNames = _a.argNames, selectedFields = _a.selectedFields;
1545
+ var schema = _a.schema, fieldName = _a.fieldName, kind = _a.kind, models = _a.models, ignore = _a.ignore, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, argNames = _a.argNames, selectedFields = _a.selectedFields, rootTypeNames = _a.rootTypeNames;
1557
1546
  var type = getDefinedRootType(schema, kind);
1558
1547
  var field = type.getFields()[fieldName];
1559
1548
  var operationName = fieldName + "_" + kind;
@@ -1600,13 +1589,14 @@ function buildOperationAndCollectVariables(_a) {
1600
1589
  depth: 0,
1601
1590
  argNames: argNames,
1602
1591
  selectedFields: selectedFields,
1592
+ rootTypeNames: rootTypeNames,
1603
1593
  }),
1604
1594
  ],
1605
1595
  },
1606
1596
  };
1607
1597
  }
1608
1598
  function resolveSelectionSet(_a) {
1609
- var parent = _a.parent, type = _a.type, models = _a.models, firstCall = _a.firstCall, path = _a.path, ancestors = _a.ancestors, ignore = _a.ignore, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, schema = _a.schema, depth = _a.depth, argNames = _a.argNames, selectedFields = _a.selectedFields;
1599
+ var parent = _a.parent, type = _a.type, models = _a.models, firstCall = _a.firstCall, path = _a.path, ancestors = _a.ancestors, ignore = _a.ignore, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, schema = _a.schema, depth = _a.depth, argNames = _a.argNames, selectedFields = _a.selectedFields, rootTypeNames = _a.rootTypeNames;
1610
1600
  if (typeof selectedFields === 'boolean' && depth > depthLimit) {
1611
1601
  return;
1612
1602
  }
@@ -1643,6 +1633,7 @@ function resolveSelectionSet(_a) {
1643
1633
  depth: depth,
1644
1634
  argNames: argNames,
1645
1635
  selectedFields: selectedFields,
1636
+ rootTypeNames: rootTypeNames,
1646
1637
  }),
1647
1638
  };
1648
1639
  })
@@ -1682,13 +1673,14 @@ function resolveSelectionSet(_a) {
1682
1673
  depth: depth,
1683
1674
  argNames: argNames,
1684
1675
  selectedFields: selectedFields,
1676
+ rootTypeNames: rootTypeNames,
1685
1677
  }),
1686
1678
  };
1687
1679
  })
1688
1680
  .filter(function (fragmentNode) { var _a, _b; return ((_b = (_a = fragmentNode === null || fragmentNode === void 0 ? void 0 : fragmentNode.selectionSet) === null || _a === void 0 ? void 0 : _a.selections) === null || _b === void 0 ? void 0 : _b.length) > 0; }),
1689
1681
  };
1690
1682
  }
1691
- if (isObjectType(type)) {
1683
+ if (isObjectType(type) && !rootTypeNames.has(type.name)) {
1692
1684
  var isIgnored = ignore.includes(type.name) || ignore.includes(parent.name + "." + path[path.length - 1]);
1693
1685
  var isModel = models.includes(type.name);
1694
1686
  if (!firstCall && isModel && !isIgnored) {
@@ -1730,6 +1722,7 @@ function resolveSelectionSet(_a) {
1730
1722
  depth: depth,
1731
1723
  argNames: argNames,
1732
1724
  selectedFields: selectedSubFields,
1725
+ rootTypeNames: rootTypeNames,
1733
1726
  });
1734
1727
  }
1735
1728
  return null;
@@ -1785,7 +1778,7 @@ function getArgumentName(name, path) {
1785
1778
  return __spreadArray(__spreadArray([], __read(path)), [name]).join('_');
1786
1779
  }
1787
1780
  function resolveField(_a) {
1788
- var type = _a.type, field = _a.field, models = _a.models, firstCall = _a.firstCall, path = _a.path, ancestors = _a.ancestors, ignore = _a.ignore, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, schema = _a.schema, depth = _a.depth, argNames = _a.argNames, selectedFields = _a.selectedFields;
1781
+ var type = _a.type, field = _a.field, models = _a.models, firstCall = _a.firstCall, path = _a.path, ancestors = _a.ancestors, ignore = _a.ignore, depthLimit = _a.depthLimit, circularReferenceDepth = _a.circularReferenceDepth, schema = _a.schema, depth = _a.depth, argNames = _a.argNames, selectedFields = _a.selectedFields, rootTypeNames = _a.rootTypeNames;
1789
1782
  var namedType = getNamedType(field.type);
1790
1783
  var args = [];
1791
1784
  var removeField = false;
@@ -1847,6 +1840,7 @@ function resolveField(_a) {
1847
1840
  depth: depth + 1,
1848
1841
  argNames: argNames,
1849
1842
  selectedFields: selectedFields,
1843
+ rootTypeNames: rootTypeNames,
1850
1844
  }) || undefined, arguments: args });
1851
1845
  }
1852
1846
  return __assign(__assign({ kind: Kind.FIELD, name: {
@@ -4418,4 +4412,4 @@ function isFieldDefinitionNode(node) {
4418
4412
  return node.kind === 'FieldDefinition';
4419
4413
  }
4420
4414
 
4421
- export { AggregateErrorImpl as AggregateError, MapperKind, addTypes, appendObjectFields, asArray, assertSome, astFromArg, astFromDirective, astFromEnumType, astFromEnumValue, astFromField, astFromInputField, astFromInputObjectType, astFromInterfaceType, astFromObjectType, astFromScalarType, astFromSchema, astFromUnionType, astFromValueUntyped, buildOperationNodeForField, checkValidationErrors, collectComment, compareNodes, compareStrings, correctASTNodes, createNamedStub, createSchemaDefinition, createStub, createVariableNameGenerator, filterSchema, fixSchemaAst, forEachDefaultValue, forEachField, getArgumentValues, getBuiltInForStub, getDefinedRootType, getDeprecatableDirectiveNodes, getDirective, getDirectiveInExtensions, getDirectiveNodes, getDirectives, getDirectivesInExtensions, getDocumentNodeFromSchema, getFieldsWithDirectives, getImplementingTypes, getLeadingCommentBlock, getResolversFromSchema, getResponseKeyFromInfo, getRootTypeMap, getRootTypeNames, getRootTypes, getUserTypesFromSchema, healSchema, healTypes, implementsAbstractType, isAsyncIterable, isDescribable, isDocumentNode, isDocumentString, isEqual, isNamedStub, isNotEqual, isSome, isValidPath, makeDeprecatedDirective, makeDirectiveNode, makeDirectiveNodes, mapAsyncIterator, mapSchema, mergeDeep, modifyObjectFields, nodeToString, observableToAsyncIterable, parseGraphQLJSON, parseGraphQLSDL, parseInputValue, parseInputValueLiteral, parseSelectionSet, printComment, printSchemaWithDirectives, printWithComments, pruneSchema, pushComment, relocatedError, removeObjectFields, renameType, resetComments, rewireTypes, selectObjectFields, serializeInputValue, transformCommentsToDescriptions, transformInputValue, updateArgument, validateGraphQlDocuments, valueMatchesCriteria, visitData, visitErrors, visitResult, withCancel };
4415
+ export { AggregateErrorImpl as AggregateError, MapperKind, addTypes, appendObjectFields, asArray, assertSome, astFromArg, astFromDirective, astFromEnumType, astFromEnumValue, astFromField, astFromInputField, astFromInputObjectType, astFromInterfaceType, astFromObjectType, astFromScalarType, astFromSchema, astFromUnionType, astFromValueUntyped, buildOperationNodeForField, checkValidationErrors, collectComment, compareNodes, compareStrings, correctASTNodes, createNamedStub, createSchemaDefinition, createStub, createVariableNameGenerator, filterSchema, fixSchemaAst, forEachDefaultValue, forEachField, getArgumentValues, getBuiltInForStub, getDefinedRootType, getDeprecatableDirectiveNodes, getDirective, getDirectiveInExtensions, getDirectiveNodes, getDirectives, getDirectivesInExtensions, getDocumentNodeFromSchema, getFieldsWithDirectives, getImplementingTypes, getLeadingCommentBlock, getResolversFromSchema, getResponseKeyFromInfo, getRootTypeMap, getRootTypeNames, getRootTypes, getUserTypesFromSchema, healSchema, healTypes, implementsAbstractType, isAsyncIterable, isDescribable, isDocumentNode, isDocumentString, isNamedStub, isSome, isValidPath, makeDeprecatedDirective, makeDirectiveNode, makeDirectiveNodes, mapAsyncIterator, mapSchema, mergeDeep, modifyObjectFields, nodeToString, observableToAsyncIterable, parseGraphQLJSON, parseGraphQLSDL, parseInputValue, parseInputValueLiteral, parseSelectionSet, printComment, printSchemaWithDirectives, printWithComments, pruneSchema, pushComment, relocatedError, removeObjectFields, renameType, resetComments, rewireTypes, selectObjectFields, serializeInputValue, transformCommentsToDescriptions, transformInputValue, updateArgument, validateGraphQlDocuments, valueMatchesCriteria, visitData, visitErrors, visitResult, withCancel };
package/es5/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/utils/es5",
3
- "version": "8.1.0",
3
+ "version": "8.1.2",
4
4
  "description": "Common package containing utils and types for GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
package/es5/rewire.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { GraphQLDirective, GraphQLNamedType } from 'graphql';
2
- import { TypeMap } from 'graphql/type/schema';
3
2
  export declare function rewireTypes(originalTypeMap: Record<string, GraphQLNamedType | null>, directives: ReadonlyArray<GraphQLDirective>): {
4
- typeMap: TypeMap;
3
+ typeMap: Record<string, GraphQLNamedType>;
5
4
  directives: Array<GraphQLDirective>;
6
5
  };
package/helpers.d.ts CHANGED
@@ -1,10 +1,8 @@
1
1
  import { ASTNode } from 'graphql';
2
2
  export declare const asArray: <T>(fns: T | T[]) => T[];
3
- export declare function isEqual<T>(a: T, b: T): boolean;
4
- export declare function isNotEqual<T>(a: T, b: T): boolean;
5
- export declare function isDocumentString(str: string): boolean;
6
- export declare function isValidPath(str: string): boolean;
7
- export declare function compareStrings<A, B>(a: A, b: B): 0 | 1 | -1;
3
+ export declare function isDocumentString(str: any): boolean;
4
+ export declare function isValidPath(str: any): boolean;
5
+ export declare function compareStrings<A, B>(a: A, b: B): 1 | -1 | 0;
8
6
  export declare function nodeToString(a: ASTNode): string;
9
7
  export declare function compareNodes(a: ASTNode, b: ASTNode, customFn?: (a: any, b: any) => number): number;
10
8
  export declare function isSome<T>(input: T): input is Exclude<T, null | undefined>;
package/index.js CHANGED
@@ -10,30 +10,17 @@ const blockString_js = require('graphql/language/blockString.js');
10
10
  const execute_js = require('graphql/execution/execute.js');
11
11
 
12
12
  const asArray = (fns) => (Array.isArray(fns) ? fns : fns ? [fns] : []);
13
- function isEqual(a, b) {
14
- if (Array.isArray(a) && Array.isArray(b)) {
15
- if (a.length !== b.length) {
16
- return false;
17
- }
18
- for (let index = 0; index < a.length; index++) {
19
- if (a[index] !== b[index]) {
20
- return false;
21
- }
22
- }
23
- return true;
24
- }
25
- return a === b || (!a && !b);
26
- }
27
- function isNotEqual(a, b) {
28
- return !isEqual(a, b);
29
- }
13
+ const invalidDocRegex = /\.[a-z0-9]+$/i;
30
14
  function isDocumentString(str) {
15
+ if (typeof str !== 'string') {
16
+ return false;
17
+ }
31
18
  // XXX: is-valid-path or is-glob treat SDL as a valid path
32
19
  // (`scalar Date` for example)
33
20
  // this why checking the extension is fast enough
34
21
  // and prevent from parsing the string in order to find out
35
22
  // if the string is a SDL
36
- if (/\.[a-z0-9]+$/i.test(str)) {
23
+ if (invalidDocRegex.test(str)) {
37
24
  return false;
38
25
  }
39
26
  try {
@@ -1257,19 +1244,21 @@ function resetOperationVariables() {
1257
1244
  function resetFieldMap() {
1258
1245
  fieldTypeMap = new Map();
1259
1246
  }
1260
- function buildOperationNodeForField({ schema, kind, field, models, ignore, depthLimit, circularReferenceDepth, argNames, selectedFields = true, }) {
1247
+ function buildOperationNodeForField({ schema, kind, field, models, ignore = [], depthLimit, circularReferenceDepth, argNames, selectedFields = true, }) {
1261
1248
  resetOperationVariables();
1262
1249
  resetFieldMap();
1250
+ const rootTypeNames = getRootTypeNames(schema);
1263
1251
  const operationNode = buildOperationAndCollectVariables({
1264
1252
  schema,
1265
1253
  fieldName: field,
1266
1254
  kind,
1267
1255
  models: models || [],
1268
- ignore: ignore || [],
1256
+ ignore,
1269
1257
  depthLimit: depthLimit || Infinity,
1270
1258
  circularReferenceDepth: circularReferenceDepth || 1,
1271
1259
  argNames,
1272
1260
  selectedFields,
1261
+ rootTypeNames,
1273
1262
  });
1274
1263
  // attach variables
1275
1264
  operationNode.variableDefinitions = [...operationVariables];
@@ -1277,7 +1266,7 @@ function buildOperationNodeForField({ schema, kind, field, models, ignore, depth
1277
1266
  resetFieldMap();
1278
1267
  return operationNode;
1279
1268
  }
1280
- function buildOperationAndCollectVariables({ schema, fieldName, kind, models, ignore, depthLimit, circularReferenceDepth, argNames, selectedFields, }) {
1269
+ function buildOperationAndCollectVariables({ schema, fieldName, kind, models, ignore, depthLimit, circularReferenceDepth, argNames, selectedFields, rootTypeNames, }) {
1281
1270
  const type = getDefinedRootType(schema, kind);
1282
1271
  const field = type.getFields()[fieldName];
1283
1272
  const operationName = `${fieldName}_${kind}`;
@@ -1314,12 +1303,13 @@ function buildOperationAndCollectVariables({ schema, fieldName, kind, models, ig
1314
1303
  depth: 0,
1315
1304
  argNames,
1316
1305
  selectedFields,
1306
+ rootTypeNames,
1317
1307
  }),
1318
1308
  ],
1319
1309
  },
1320
1310
  };
1321
1311
  }
1322
- function resolveSelectionSet({ parent, type, models, firstCall, path, ancestors, ignore, depthLimit, circularReferenceDepth, schema, depth, argNames, selectedFields, }) {
1312
+ function resolveSelectionSet({ parent, type, models, firstCall, path, ancestors, ignore, depthLimit, circularReferenceDepth, schema, depth, argNames, selectedFields, rootTypeNames, }) {
1323
1313
  if (typeof selectedFields === 'boolean' && depth > depthLimit) {
1324
1314
  return;
1325
1315
  }
@@ -1354,6 +1344,7 @@ function resolveSelectionSet({ parent, type, models, firstCall, path, ancestors,
1354
1344
  depth,
1355
1345
  argNames,
1356
1346
  selectedFields,
1347
+ rootTypeNames,
1357
1348
  }),
1358
1349
  };
1359
1350
  })
@@ -1391,13 +1382,14 @@ function resolveSelectionSet({ parent, type, models, firstCall, path, ancestors,
1391
1382
  depth,
1392
1383
  argNames,
1393
1384
  selectedFields,
1385
+ rootTypeNames,
1394
1386
  }),
1395
1387
  };
1396
1388
  })
1397
1389
  .filter(fragmentNode => { var _a, _b; return ((_b = (_a = fragmentNode === null || fragmentNode === void 0 ? void 0 : fragmentNode.selectionSet) === null || _a === void 0 ? void 0 : _a.selections) === null || _b === void 0 ? void 0 : _b.length) > 0; }),
1398
1390
  };
1399
1391
  }
1400
- if (graphql.isObjectType(type)) {
1392
+ if (graphql.isObjectType(type) && !rootTypeNames.has(type.name)) {
1401
1393
  const isIgnored = ignore.includes(type.name) || ignore.includes(`${parent.name}.${path[path.length - 1]}`);
1402
1394
  const isModel = models.includes(type.name);
1403
1395
  if (!firstCall && isModel && !isIgnored) {
@@ -1439,6 +1431,7 @@ function resolveSelectionSet({ parent, type, models, firstCall, path, ancestors,
1439
1431
  depth,
1440
1432
  argNames,
1441
1433
  selectedFields: selectedSubFields,
1434
+ rootTypeNames,
1442
1435
  });
1443
1436
  }
1444
1437
  return null;
@@ -1493,7 +1486,7 @@ function resolveVariable(arg, name) {
1493
1486
  function getArgumentName(name, path) {
1494
1487
  return [...path, name].join('_');
1495
1488
  }
1496
- function resolveField({ type, field, models, firstCall, path, ancestors, ignore, depthLimit, circularReferenceDepth, schema, depth, argNames, selectedFields, }) {
1489
+ function resolveField({ type, field, models, firstCall, path, ancestors, ignore, depthLimit, circularReferenceDepth, schema, depth, argNames, selectedFields, rootTypeNames, }) {
1497
1490
  const namedType = graphql.getNamedType(field.type);
1498
1491
  let args = [];
1499
1492
  let removeField = false;
@@ -1559,6 +1552,7 @@ function resolveField({ type, field, models, firstCall, path, ancestors, ignore,
1559
1552
  depth: depth + 1,
1560
1553
  argNames,
1561
1554
  selectedFields,
1555
+ rootTypeNames,
1562
1556
  }) || undefined,
1563
1557
  arguments: args,
1564
1558
  };
@@ -3925,9 +3919,7 @@ exports.isAsyncIterable = isAsyncIterable;
3925
3919
  exports.isDescribable = isDescribable;
3926
3920
  exports.isDocumentNode = isDocumentNode;
3927
3921
  exports.isDocumentString = isDocumentString;
3928
- exports.isEqual = isEqual;
3929
3922
  exports.isNamedStub = isNamedStub;
3930
- exports.isNotEqual = isNotEqual;
3931
3923
  exports.isSome = isSome;
3932
3924
  exports.isValidPath = isValidPath;
3933
3925
  exports.makeDeprecatedDirective = makeDeprecatedDirective;
package/index.mjs CHANGED
@@ -4,30 +4,17 @@ import { dedentBlockStringValue } from 'graphql/language/blockString.js';
4
4
  import { collectFields } from 'graphql/execution/execute.js';
5
5
 
6
6
  const asArray = (fns) => (Array.isArray(fns) ? fns : fns ? [fns] : []);
7
- function isEqual(a, b) {
8
- if (Array.isArray(a) && Array.isArray(b)) {
9
- if (a.length !== b.length) {
10
- return false;
11
- }
12
- for (let index = 0; index < a.length; index++) {
13
- if (a[index] !== b[index]) {
14
- return false;
15
- }
16
- }
17
- return true;
18
- }
19
- return a === b || (!a && !b);
20
- }
21
- function isNotEqual(a, b) {
22
- return !isEqual(a, b);
23
- }
7
+ const invalidDocRegex = /\.[a-z0-9]+$/i;
24
8
  function isDocumentString(str) {
9
+ if (typeof str !== 'string') {
10
+ return false;
11
+ }
25
12
  // XXX: is-valid-path or is-glob treat SDL as a valid path
26
13
  // (`scalar Date` for example)
27
14
  // this why checking the extension is fast enough
28
15
  // and prevent from parsing the string in order to find out
29
16
  // if the string is a SDL
30
- if (/\.[a-z0-9]+$/i.test(str)) {
17
+ if (invalidDocRegex.test(str)) {
31
18
  return false;
32
19
  }
33
20
  try {
@@ -1251,19 +1238,21 @@ function resetOperationVariables() {
1251
1238
  function resetFieldMap() {
1252
1239
  fieldTypeMap = new Map();
1253
1240
  }
1254
- function buildOperationNodeForField({ schema, kind, field, models, ignore, depthLimit, circularReferenceDepth, argNames, selectedFields = true, }) {
1241
+ function buildOperationNodeForField({ schema, kind, field, models, ignore = [], depthLimit, circularReferenceDepth, argNames, selectedFields = true, }) {
1255
1242
  resetOperationVariables();
1256
1243
  resetFieldMap();
1244
+ const rootTypeNames = getRootTypeNames(schema);
1257
1245
  const operationNode = buildOperationAndCollectVariables({
1258
1246
  schema,
1259
1247
  fieldName: field,
1260
1248
  kind,
1261
1249
  models: models || [],
1262
- ignore: ignore || [],
1250
+ ignore,
1263
1251
  depthLimit: depthLimit || Infinity,
1264
1252
  circularReferenceDepth: circularReferenceDepth || 1,
1265
1253
  argNames,
1266
1254
  selectedFields,
1255
+ rootTypeNames,
1267
1256
  });
1268
1257
  // attach variables
1269
1258
  operationNode.variableDefinitions = [...operationVariables];
@@ -1271,7 +1260,7 @@ function buildOperationNodeForField({ schema, kind, field, models, ignore, depth
1271
1260
  resetFieldMap();
1272
1261
  return operationNode;
1273
1262
  }
1274
- function buildOperationAndCollectVariables({ schema, fieldName, kind, models, ignore, depthLimit, circularReferenceDepth, argNames, selectedFields, }) {
1263
+ function buildOperationAndCollectVariables({ schema, fieldName, kind, models, ignore, depthLimit, circularReferenceDepth, argNames, selectedFields, rootTypeNames, }) {
1275
1264
  const type = getDefinedRootType(schema, kind);
1276
1265
  const field = type.getFields()[fieldName];
1277
1266
  const operationName = `${fieldName}_${kind}`;
@@ -1308,12 +1297,13 @@ function buildOperationAndCollectVariables({ schema, fieldName, kind, models, ig
1308
1297
  depth: 0,
1309
1298
  argNames,
1310
1299
  selectedFields,
1300
+ rootTypeNames,
1311
1301
  }),
1312
1302
  ],
1313
1303
  },
1314
1304
  };
1315
1305
  }
1316
- function resolveSelectionSet({ parent, type, models, firstCall, path, ancestors, ignore, depthLimit, circularReferenceDepth, schema, depth, argNames, selectedFields, }) {
1306
+ function resolveSelectionSet({ parent, type, models, firstCall, path, ancestors, ignore, depthLimit, circularReferenceDepth, schema, depth, argNames, selectedFields, rootTypeNames, }) {
1317
1307
  if (typeof selectedFields === 'boolean' && depth > depthLimit) {
1318
1308
  return;
1319
1309
  }
@@ -1348,6 +1338,7 @@ function resolveSelectionSet({ parent, type, models, firstCall, path, ancestors,
1348
1338
  depth,
1349
1339
  argNames,
1350
1340
  selectedFields,
1341
+ rootTypeNames,
1351
1342
  }),
1352
1343
  };
1353
1344
  })
@@ -1385,13 +1376,14 @@ function resolveSelectionSet({ parent, type, models, firstCall, path, ancestors,
1385
1376
  depth,
1386
1377
  argNames,
1387
1378
  selectedFields,
1379
+ rootTypeNames,
1388
1380
  }),
1389
1381
  };
1390
1382
  })
1391
1383
  .filter(fragmentNode => { var _a, _b; return ((_b = (_a = fragmentNode === null || fragmentNode === void 0 ? void 0 : fragmentNode.selectionSet) === null || _a === void 0 ? void 0 : _a.selections) === null || _b === void 0 ? void 0 : _b.length) > 0; }),
1392
1384
  };
1393
1385
  }
1394
- if (isObjectType(type)) {
1386
+ if (isObjectType(type) && !rootTypeNames.has(type.name)) {
1395
1387
  const isIgnored = ignore.includes(type.name) || ignore.includes(`${parent.name}.${path[path.length - 1]}`);
1396
1388
  const isModel = models.includes(type.name);
1397
1389
  if (!firstCall && isModel && !isIgnored) {
@@ -1433,6 +1425,7 @@ function resolveSelectionSet({ parent, type, models, firstCall, path, ancestors,
1433
1425
  depth,
1434
1426
  argNames,
1435
1427
  selectedFields: selectedSubFields,
1428
+ rootTypeNames,
1436
1429
  });
1437
1430
  }
1438
1431
  return null;
@@ -1487,7 +1480,7 @@ function resolveVariable(arg, name) {
1487
1480
  function getArgumentName(name, path) {
1488
1481
  return [...path, name].join('_');
1489
1482
  }
1490
- function resolveField({ type, field, models, firstCall, path, ancestors, ignore, depthLimit, circularReferenceDepth, schema, depth, argNames, selectedFields, }) {
1483
+ function resolveField({ type, field, models, firstCall, path, ancestors, ignore, depthLimit, circularReferenceDepth, schema, depth, argNames, selectedFields, rootTypeNames, }) {
1491
1484
  const namedType = getNamedType(field.type);
1492
1485
  let args = [];
1493
1486
  let removeField = false;
@@ -1553,6 +1546,7 @@ function resolveField({ type, field, models, firstCall, path, ancestors, ignore,
1553
1546
  depth: depth + 1,
1554
1547
  argNames,
1555
1548
  selectedFields,
1549
+ rootTypeNames,
1556
1550
  }) || undefined,
1557
1551
  arguments: args,
1558
1552
  };
@@ -3863,4 +3857,4 @@ function isFieldDefinitionNode(node) {
3863
3857
  return node.kind === 'FieldDefinition';
3864
3858
  }
3865
3859
 
3866
- export { AggregateErrorImpl as AggregateError, MapperKind, addTypes, appendObjectFields, asArray, assertSome, astFromArg, astFromDirective, astFromEnumType, astFromEnumValue, astFromField, astFromInputField, astFromInputObjectType, astFromInterfaceType, astFromObjectType, astFromScalarType, astFromSchema, astFromUnionType, astFromValueUntyped, buildOperationNodeForField, checkValidationErrors, collectComment, compareNodes, compareStrings, correctASTNodes, createNamedStub, createSchemaDefinition, createStub, createVariableNameGenerator, filterSchema, fixSchemaAst, forEachDefaultValue, forEachField, getArgumentValues, getBuiltInForStub, getDefinedRootType, getDeprecatableDirectiveNodes, getDirective, getDirectiveInExtensions, getDirectiveNodes, getDirectives, getDirectivesInExtensions, getDocumentNodeFromSchema, getFieldsWithDirectives, getImplementingTypes, getLeadingCommentBlock, getResolversFromSchema, getResponseKeyFromInfo, getRootTypeMap, getRootTypeNames, getRootTypes, getUserTypesFromSchema, healSchema, healTypes, implementsAbstractType, isAsyncIterable, isDescribable, isDocumentNode, isDocumentString, isEqual, isNamedStub, isNotEqual, isSome, isValidPath, makeDeprecatedDirective, makeDirectiveNode, makeDirectiveNodes, mapAsyncIterator, mapSchema, mergeDeep, modifyObjectFields, nodeToString, observableToAsyncIterable, parseGraphQLJSON, parseGraphQLSDL, parseInputValue, parseInputValueLiteral, parseSelectionSet, printComment, printSchemaWithDirectives, printWithComments, pruneSchema, pushComment, relocatedError, removeObjectFields, renameType, resetComments, rewireTypes, selectObjectFields, serializeInputValue, transformCommentsToDescriptions, transformInputValue, updateArgument, validateGraphQlDocuments, valueMatchesCriteria, visitData, visitErrors, visitResult, withCancel };
3860
+ export { AggregateErrorImpl as AggregateError, MapperKind, addTypes, appendObjectFields, asArray, assertSome, astFromArg, astFromDirective, astFromEnumType, astFromEnumValue, astFromField, astFromInputField, astFromInputObjectType, astFromInterfaceType, astFromObjectType, astFromScalarType, astFromSchema, astFromUnionType, astFromValueUntyped, buildOperationNodeForField, checkValidationErrors, collectComment, compareNodes, compareStrings, correctASTNodes, createNamedStub, createSchemaDefinition, createStub, createVariableNameGenerator, filterSchema, fixSchemaAst, forEachDefaultValue, forEachField, getArgumentValues, getBuiltInForStub, getDefinedRootType, getDeprecatableDirectiveNodes, getDirective, getDirectiveInExtensions, getDirectiveNodes, getDirectives, getDirectivesInExtensions, getDocumentNodeFromSchema, getFieldsWithDirectives, getImplementingTypes, getLeadingCommentBlock, getResolversFromSchema, getResponseKeyFromInfo, getRootTypeMap, getRootTypeNames, getRootTypes, getUserTypesFromSchema, healSchema, healTypes, implementsAbstractType, isAsyncIterable, isDescribable, isDocumentNode, isDocumentString, isNamedStub, isSome, isValidPath, makeDeprecatedDirective, makeDirectiveNode, makeDirectiveNodes, mapAsyncIterator, mapSchema, mergeDeep, modifyObjectFields, nodeToString, observableToAsyncIterable, parseGraphQLJSON, parseGraphQLSDL, parseInputValue, parseInputValueLiteral, parseSelectionSet, printComment, printSchemaWithDirectives, printWithComments, pruneSchema, pushComment, relocatedError, removeObjectFields, renameType, resetComments, rewireTypes, selectObjectFields, serializeInputValue, transformCommentsToDescriptions, transformInputValue, updateArgument, validateGraphQlDocuments, valueMatchesCriteria, visitData, visitErrors, visitResult, withCancel };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphql-tools/utils",
3
- "version": "8.1.0",
3
+ "version": "8.1.2",
4
4
  "description": "Common package containing utils and types for GraphQL tools",
5
5
  "sideEffects": false,
6
6
  "peerDependencies": {
package/rewire.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { GraphQLDirective, GraphQLNamedType } from 'graphql';
2
- import { TypeMap } from 'graphql/type/schema';
3
2
  export declare function rewireTypes(originalTypeMap: Record<string, GraphQLNamedType | null>, directives: ReadonlyArray<GraphQLDirective>): {
4
- typeMap: TypeMap;
3
+ typeMap: Record<string, GraphQLNamedType>;
5
4
  directives: Array<GraphQLDirective>;
6
5
  };