@graphql-tools/utils 8.7.0 → 8.8.0-alpha-b76ec274.0

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.
Files changed (161) hide show
  1. package/cjs/AggregateError.js +25 -0
  2. package/cjs/Interfaces.js +31 -0
  3. package/cjs/addTypes.js +62 -0
  4. package/cjs/astFromType.js +31 -0
  5. package/cjs/astFromValueUntyped.js +78 -0
  6. package/cjs/build-operation-for-field.js +351 -0
  7. package/cjs/collectFields.js +98 -0
  8. package/cjs/comments.js +380 -0
  9. package/cjs/errors.js +22 -0
  10. package/cjs/executor.js +2 -0
  11. package/cjs/fields.js +115 -0
  12. package/cjs/filterSchema.js +66 -0
  13. package/cjs/fixSchemaAst.js +26 -0
  14. package/cjs/forEachDefaultValue.js +29 -0
  15. package/cjs/forEachField.js +19 -0
  16. package/cjs/get-directives.js +103 -0
  17. package/cjs/get-fields-with-directives.js +52 -0
  18. package/cjs/get-implementing-types.js +19 -0
  19. package/cjs/getArgumentValues.js +76 -0
  20. package/cjs/getObjectTypeFromTypeMap.js +13 -0
  21. package/cjs/getOperationASTFromRequest.js +16 -0
  22. package/cjs/getResolversFromSchema.js +73 -0
  23. package/cjs/getResponseKeyFromInfo.js +12 -0
  24. package/cjs/heal.js +177 -0
  25. package/cjs/helpers.js +76 -0
  26. package/cjs/implementsAbstractType.js +17 -0
  27. package/cjs/index.js +53 -0
  28. package/cjs/inspect.js +107 -0
  29. package/cjs/isAsyncIterable.js +10 -0
  30. package/cjs/isDocumentNode.js +8 -0
  31. package/cjs/loaders.js +2 -0
  32. package/cjs/mapAsyncIterator.js +53 -0
  33. package/cjs/mapSchema.js +470 -0
  34. package/cjs/memoize.js +189 -0
  35. package/cjs/mergeDeep.js +45 -0
  36. package/cjs/observableToAsyncIterable.js +85 -0
  37. package/cjs/package.json +1 -0
  38. package/cjs/parse-graphql-json.js +44 -0
  39. package/cjs/parse-graphql-sdl.js +84 -0
  40. package/cjs/print-schema-with-directives.js +494 -0
  41. package/cjs/prune.js +133 -0
  42. package/cjs/renameType.js +152 -0
  43. package/cjs/rewire.js +159 -0
  44. package/cjs/rootTypes.js +37 -0
  45. package/cjs/selectionSets.js +9 -0
  46. package/cjs/stub.js +68 -0
  47. package/cjs/transformInputValue.js +55 -0
  48. package/cjs/types.js +27 -0
  49. package/cjs/updateArgument.js +54 -0
  50. package/cjs/validate-documents.js +76 -0
  51. package/cjs/valueMatchesCriteria.js +21 -0
  52. package/cjs/visitResult.js +219 -0
  53. package/cjs/withCancel.js +56 -0
  54. package/esm/AggregateError.js +21 -0
  55. package/esm/Interfaces.js +28 -0
  56. package/esm/addTypes.js +58 -0
  57. package/esm/astFromType.js +27 -0
  58. package/esm/astFromValueUntyped.js +74 -0
  59. package/esm/build-operation-for-field.js +347 -0
  60. package/esm/collectFields.js +94 -0
  61. package/esm/comments.js +367 -0
  62. package/esm/errors.js +17 -0
  63. package/esm/executor.js +1 -0
  64. package/esm/fields.js +108 -0
  65. package/esm/filterSchema.js +62 -0
  66. package/esm/fixSchemaAst.js +22 -0
  67. package/esm/forEachDefaultValue.js +25 -0
  68. package/esm/forEachField.js +15 -0
  69. package/esm/get-directives.js +96 -0
  70. package/esm/get-fields-with-directives.js +48 -0
  71. package/esm/get-implementing-types.js +15 -0
  72. package/esm/getArgumentValues.js +72 -0
  73. package/esm/getObjectTypeFromTypeMap.js +9 -0
  74. package/esm/getOperationASTFromRequest.js +12 -0
  75. package/esm/getResolversFromSchema.js +69 -0
  76. package/esm/getResponseKeyFromInfo.js +8 -0
  77. package/esm/heal.js +172 -0
  78. package/esm/helpers.js +65 -0
  79. package/esm/implementsAbstractType.js +13 -0
  80. package/esm/index.js +50 -0
  81. package/esm/inspect.js +103 -0
  82. package/esm/isAsyncIterable.js +6 -0
  83. package/esm/isDocumentNode.js +4 -0
  84. package/esm/loaders.js +1 -0
  85. package/esm/mapAsyncIterator.js +49 -0
  86. package/esm/mapSchema.js +465 -0
  87. package/esm/memoize.js +180 -0
  88. package/esm/mergeDeep.js +41 -0
  89. package/esm/observableToAsyncIterable.js +81 -0
  90. package/esm/parse-graphql-json.js +40 -0
  91. package/esm/parse-graphql-sdl.js +78 -0
  92. package/esm/print-schema-with-directives.js +472 -0
  93. package/esm/prune.js +129 -0
  94. package/esm/renameType.js +148 -0
  95. package/esm/rewire.js +155 -0
  96. package/esm/rootTypes.js +33 -0
  97. package/esm/selectionSets.js +5 -0
  98. package/esm/stub.js +61 -0
  99. package/esm/transformInputValue.js +48 -0
  100. package/esm/types.js +24 -0
  101. package/esm/updateArgument.js +49 -0
  102. package/esm/validate-documents.js +70 -0
  103. package/esm/valueMatchesCriteria.js +17 -0
  104. package/esm/visitResult.js +213 -0
  105. package/esm/withCancel.js +51 -0
  106. package/package.json +31 -10
  107. package/{AggregateError.d.ts → typings/AggregateError.d.ts} +0 -0
  108. package/{Interfaces.d.ts → typings/Interfaces.d.ts} +0 -0
  109. package/{addTypes.d.ts → typings/addTypes.d.ts} +0 -0
  110. package/{astFromType.d.ts → typings/astFromType.d.ts} +0 -0
  111. package/{astFromValueUntyped.d.ts → typings/astFromValueUntyped.d.ts} +0 -0
  112. package/{build-operation-for-field.d.ts → typings/build-operation-for-field.d.ts} +0 -0
  113. package/{collectFields.d.ts → typings/collectFields.d.ts} +0 -0
  114. package/{comments.d.ts → typings/comments.d.ts} +0 -0
  115. package/{errors.d.ts → typings/errors.d.ts} +1 -1
  116. package/{executor.d.ts → typings/executor.d.ts} +1 -1
  117. package/{fields.d.ts → typings/fields.d.ts} +0 -0
  118. package/{filterSchema.d.ts → typings/filterSchema.d.ts} +1 -1
  119. package/{fixSchemaAst.d.ts → typings/fixSchemaAst.d.ts} +1 -1
  120. package/{forEachDefaultValue.d.ts → typings/forEachDefaultValue.d.ts} +1 -1
  121. package/{forEachField.d.ts → typings/forEachField.d.ts} +1 -1
  122. package/{get-directives.d.ts → typings/get-directives.d.ts} +0 -0
  123. package/{get-fields-with-directives.d.ts → typings/get-fields-with-directives.d.ts} +0 -0
  124. package/{get-implementing-types.d.ts → typings/get-implementing-types.d.ts} +0 -0
  125. package/{getArgumentValues.d.ts → typings/getArgumentValues.d.ts} +0 -0
  126. package/{getObjectTypeFromTypeMap.d.ts → typings/getObjectTypeFromTypeMap.d.ts} +1 -1
  127. package/{getOperationASTFromRequest.d.ts → typings/getOperationASTFromRequest.d.ts} +1 -1
  128. package/{getResolversFromSchema.d.ts → typings/getResolversFromSchema.d.ts} +1 -1
  129. package/{getResponseKeyFromInfo.d.ts → typings/getResponseKeyFromInfo.d.ts} +0 -0
  130. package/{heal.d.ts → typings/heal.d.ts} +0 -0
  131. package/{helpers.d.ts → typings/helpers.d.ts} +0 -0
  132. package/{implementsAbstractType.d.ts → typings/implementsAbstractType.d.ts} +1 -1
  133. package/typings/index.d.ts +50 -0
  134. package/{inspect.d.ts → typings/inspect.d.ts} +0 -0
  135. package/{isAsyncIterable.d.ts → typings/isAsyncIterable.d.ts} +0 -0
  136. package/{isDocumentNode.d.ts → typings/isDocumentNode.d.ts} +0 -0
  137. package/{loaders.d.ts → typings/loaders.d.ts} +1 -1
  138. package/{mapAsyncIterator.d.ts → typings/mapAsyncIterator.d.ts} +0 -0
  139. package/{mapSchema.d.ts → typings/mapSchema.d.ts} +1 -1
  140. package/{memoize.d.ts → typings/memoize.d.ts} +0 -0
  141. package/{mergeDeep.d.ts → typings/mergeDeep.d.ts} +0 -0
  142. package/{observableToAsyncIterable.d.ts → typings/observableToAsyncIterable.d.ts} +0 -0
  143. package/{parse-graphql-json.d.ts → typings/parse-graphql-json.d.ts} +2 -2
  144. package/{parse-graphql-sdl.d.ts → typings/parse-graphql-sdl.d.ts} +1 -1
  145. package/{print-schema-with-directives.d.ts → typings/print-schema-with-directives.d.ts} +1 -1
  146. package/{prune.d.ts → typings/prune.d.ts} +1 -1
  147. package/{renameType.d.ts → typings/renameType.d.ts} +0 -0
  148. package/{rewire.d.ts → typings/rewire.d.ts} +0 -0
  149. package/{rootTypes.d.ts → typings/rootTypes.d.ts} +0 -0
  150. package/{selectionSets.d.ts → typings/selectionSets.d.ts} +1 -1
  151. package/{stub.d.ts → typings/stub.d.ts} +0 -0
  152. package/{transformInputValue.d.ts → typings/transformInputValue.d.ts} +1 -1
  153. package/{types.d.ts → typings/types.d.ts} +0 -0
  154. package/{updateArgument.d.ts → typings/updateArgument.d.ts} +0 -0
  155. package/{validate-documents.d.ts → typings/validate-documents.d.ts} +1 -1
  156. package/{valueMatchesCriteria.d.ts → typings/valueMatchesCriteria.d.ts} +0 -0
  157. package/{visitResult.d.ts → typings/visitResult.d.ts} +1 -1
  158. package/{withCancel.d.ts → typings/withCancel.d.ts} +0 -0
  159. package/index.d.ts +0 -50
  160. package/index.js +0 -4428
  161. package/index.mjs +0 -4315
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.renameType = void 0;
4
+ const graphql_1 = require("graphql");
5
+ function renameType(type, newTypeName) {
6
+ if ((0, graphql_1.isObjectType)(type)) {
7
+ return new graphql_1.GraphQLObjectType({
8
+ ...type.toConfig(),
9
+ name: newTypeName,
10
+ astNode: type.astNode == null
11
+ ? type.astNode
12
+ : {
13
+ ...type.astNode,
14
+ name: {
15
+ ...type.astNode.name,
16
+ value: newTypeName,
17
+ },
18
+ },
19
+ extensionASTNodes: type.extensionASTNodes == null
20
+ ? type.extensionASTNodes
21
+ : type.extensionASTNodes.map(node => ({
22
+ ...node,
23
+ name: {
24
+ ...node.name,
25
+ value: newTypeName,
26
+ },
27
+ })),
28
+ });
29
+ }
30
+ else if ((0, graphql_1.isInterfaceType)(type)) {
31
+ return new graphql_1.GraphQLInterfaceType({
32
+ ...type.toConfig(),
33
+ name: newTypeName,
34
+ astNode: type.astNode == null
35
+ ? type.astNode
36
+ : {
37
+ ...type.astNode,
38
+ name: {
39
+ ...type.astNode.name,
40
+ value: newTypeName,
41
+ },
42
+ },
43
+ extensionASTNodes: type.extensionASTNodes == null
44
+ ? type.extensionASTNodes
45
+ : type.extensionASTNodes.map(node => ({
46
+ ...node,
47
+ name: {
48
+ ...node.name,
49
+ value: newTypeName,
50
+ },
51
+ })),
52
+ });
53
+ }
54
+ else if ((0, graphql_1.isUnionType)(type)) {
55
+ return new graphql_1.GraphQLUnionType({
56
+ ...type.toConfig(),
57
+ name: newTypeName,
58
+ astNode: type.astNode == null
59
+ ? type.astNode
60
+ : {
61
+ ...type.astNode,
62
+ name: {
63
+ ...type.astNode.name,
64
+ value: newTypeName,
65
+ },
66
+ },
67
+ extensionASTNodes: type.extensionASTNodes == null
68
+ ? type.extensionASTNodes
69
+ : type.extensionASTNodes.map(node => ({
70
+ ...node,
71
+ name: {
72
+ ...node.name,
73
+ value: newTypeName,
74
+ },
75
+ })),
76
+ });
77
+ }
78
+ else if ((0, graphql_1.isInputObjectType)(type)) {
79
+ return new graphql_1.GraphQLInputObjectType({
80
+ ...type.toConfig(),
81
+ name: newTypeName,
82
+ astNode: type.astNode == null
83
+ ? type.astNode
84
+ : {
85
+ ...type.astNode,
86
+ name: {
87
+ ...type.astNode.name,
88
+ value: newTypeName,
89
+ },
90
+ },
91
+ extensionASTNodes: type.extensionASTNodes == null
92
+ ? type.extensionASTNodes
93
+ : type.extensionASTNodes.map(node => ({
94
+ ...node,
95
+ name: {
96
+ ...node.name,
97
+ value: newTypeName,
98
+ },
99
+ })),
100
+ });
101
+ }
102
+ else if ((0, graphql_1.isEnumType)(type)) {
103
+ return new graphql_1.GraphQLEnumType({
104
+ ...type.toConfig(),
105
+ name: newTypeName,
106
+ astNode: type.astNode == null
107
+ ? type.astNode
108
+ : {
109
+ ...type.astNode,
110
+ name: {
111
+ ...type.astNode.name,
112
+ value: newTypeName,
113
+ },
114
+ },
115
+ extensionASTNodes: type.extensionASTNodes == null
116
+ ? type.extensionASTNodes
117
+ : type.extensionASTNodes.map(node => ({
118
+ ...node,
119
+ name: {
120
+ ...node.name,
121
+ value: newTypeName,
122
+ },
123
+ })),
124
+ });
125
+ }
126
+ else if ((0, graphql_1.isScalarType)(type)) {
127
+ return new graphql_1.GraphQLScalarType({
128
+ ...type.toConfig(),
129
+ name: newTypeName,
130
+ astNode: type.astNode == null
131
+ ? type.astNode
132
+ : {
133
+ ...type.astNode,
134
+ name: {
135
+ ...type.astNode.name,
136
+ value: newTypeName,
137
+ },
138
+ },
139
+ extensionASTNodes: type.extensionASTNodes == null
140
+ ? type.extensionASTNodes
141
+ : type.extensionASTNodes.map(node => ({
142
+ ...node,
143
+ name: {
144
+ ...node.name,
145
+ value: newTypeName,
146
+ },
147
+ })),
148
+ });
149
+ }
150
+ throw new Error(`Unknown type ${type}.`);
151
+ }
152
+ exports.renameType = renameType;
package/cjs/rewire.js ADDED
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.rewireTypes = void 0;
4
+ const graphql_1 = require("graphql");
5
+ const stub_js_1 = require("./stub.js");
6
+ function rewireTypes(originalTypeMap, directives) {
7
+ const referenceTypeMap = Object.create(null);
8
+ for (const typeName in originalTypeMap) {
9
+ referenceTypeMap[typeName] = originalTypeMap[typeName];
10
+ }
11
+ const newTypeMap = Object.create(null);
12
+ for (const typeName in referenceTypeMap) {
13
+ const namedType = referenceTypeMap[typeName];
14
+ if (namedType == null || typeName.startsWith('__')) {
15
+ continue;
16
+ }
17
+ const newName = namedType.name;
18
+ if (newName.startsWith('__')) {
19
+ continue;
20
+ }
21
+ if (newTypeMap[newName] != null) {
22
+ throw new Error(`Duplicate schema type name ${newName}`);
23
+ }
24
+ newTypeMap[newName] = namedType;
25
+ }
26
+ for (const typeName in newTypeMap) {
27
+ newTypeMap[typeName] = rewireNamedType(newTypeMap[typeName]);
28
+ }
29
+ const newDirectives = directives.map(directive => rewireDirective(directive));
30
+ return {
31
+ typeMap: newTypeMap,
32
+ directives: newDirectives,
33
+ };
34
+ function rewireDirective(directive) {
35
+ if ((0, graphql_1.isSpecifiedDirective)(directive)) {
36
+ return directive;
37
+ }
38
+ const directiveConfig = directive.toConfig();
39
+ directiveConfig.args = rewireArgs(directiveConfig.args);
40
+ return new graphql_1.GraphQLDirective(directiveConfig);
41
+ }
42
+ function rewireArgs(args) {
43
+ const rewiredArgs = {};
44
+ for (const argName in args) {
45
+ const arg = args[argName];
46
+ const rewiredArgType = rewireType(arg.type);
47
+ if (rewiredArgType != null) {
48
+ arg.type = rewiredArgType;
49
+ rewiredArgs[argName] = arg;
50
+ }
51
+ }
52
+ return rewiredArgs;
53
+ }
54
+ function rewireNamedType(type) {
55
+ if ((0, graphql_1.isObjectType)(type)) {
56
+ const config = type.toConfig();
57
+ const newConfig = {
58
+ ...config,
59
+ fields: () => rewireFields(config.fields),
60
+ interfaces: () => rewireNamedTypes(config.interfaces),
61
+ };
62
+ return new graphql_1.GraphQLObjectType(newConfig);
63
+ }
64
+ else if ((0, graphql_1.isInterfaceType)(type)) {
65
+ const config = type.toConfig();
66
+ const newConfig = {
67
+ ...config,
68
+ fields: () => rewireFields(config.fields),
69
+ };
70
+ if ('interfaces' in newConfig) {
71
+ newConfig.interfaces = () => rewireNamedTypes(config.interfaces);
72
+ }
73
+ return new graphql_1.GraphQLInterfaceType(newConfig);
74
+ }
75
+ else if ((0, graphql_1.isUnionType)(type)) {
76
+ const config = type.toConfig();
77
+ const newConfig = {
78
+ ...config,
79
+ types: () => rewireNamedTypes(config.types),
80
+ };
81
+ return new graphql_1.GraphQLUnionType(newConfig);
82
+ }
83
+ else if ((0, graphql_1.isInputObjectType)(type)) {
84
+ const config = type.toConfig();
85
+ const newConfig = {
86
+ ...config,
87
+ fields: () => rewireInputFields(config.fields),
88
+ };
89
+ return new graphql_1.GraphQLInputObjectType(newConfig);
90
+ }
91
+ else if ((0, graphql_1.isEnumType)(type)) {
92
+ const enumConfig = type.toConfig();
93
+ return new graphql_1.GraphQLEnumType(enumConfig);
94
+ }
95
+ else if ((0, graphql_1.isScalarType)(type)) {
96
+ if ((0, graphql_1.isSpecifiedScalarType)(type)) {
97
+ return type;
98
+ }
99
+ const scalarConfig = type.toConfig();
100
+ return new graphql_1.GraphQLScalarType(scalarConfig);
101
+ }
102
+ throw new Error(`Unexpected schema type: ${type}`);
103
+ }
104
+ function rewireFields(fields) {
105
+ const rewiredFields = {};
106
+ for (const fieldName in fields) {
107
+ const field = fields[fieldName];
108
+ const rewiredFieldType = rewireType(field.type);
109
+ if (rewiredFieldType != null && field.args) {
110
+ field.type = rewiredFieldType;
111
+ field.args = rewireArgs(field.args);
112
+ rewiredFields[fieldName] = field;
113
+ }
114
+ }
115
+ return rewiredFields;
116
+ }
117
+ function rewireInputFields(fields) {
118
+ const rewiredFields = {};
119
+ for (const fieldName in fields) {
120
+ const field = fields[fieldName];
121
+ const rewiredFieldType = rewireType(field.type);
122
+ if (rewiredFieldType != null) {
123
+ field.type = rewiredFieldType;
124
+ rewiredFields[fieldName] = field;
125
+ }
126
+ }
127
+ return rewiredFields;
128
+ }
129
+ function rewireNamedTypes(namedTypes) {
130
+ const rewiredTypes = [];
131
+ for (const namedType of namedTypes) {
132
+ const rewiredType = rewireType(namedType);
133
+ if (rewiredType != null) {
134
+ rewiredTypes.push(rewiredType);
135
+ }
136
+ }
137
+ return rewiredTypes;
138
+ }
139
+ function rewireType(type) {
140
+ if ((0, graphql_1.isListType)(type)) {
141
+ const rewiredType = rewireType(type.ofType);
142
+ return rewiredType != null ? new graphql_1.GraphQLList(rewiredType) : null;
143
+ }
144
+ else if ((0, graphql_1.isNonNullType)(type)) {
145
+ const rewiredType = rewireType(type.ofType);
146
+ return rewiredType != null ? new graphql_1.GraphQLNonNull(rewiredType) : null;
147
+ }
148
+ else if ((0, graphql_1.isNamedType)(type)) {
149
+ let rewiredType = referenceTypeMap[type.name];
150
+ if (rewiredType === undefined) {
151
+ rewiredType = (0, stub_js_1.isNamedStub)(type) ? (0, stub_js_1.getBuiltInForStub)(type) : rewireNamedType(type);
152
+ newTypeMap[rewiredType.name] = referenceTypeMap[type.name] = rewiredType;
153
+ }
154
+ return rewiredType != null ? newTypeMap[rewiredType.name] : null;
155
+ }
156
+ return null;
157
+ }
158
+ }
159
+ exports.rewireTypes = rewireTypes;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getRootTypeMap = exports.getRootTypes = exports.getRootTypeNames = exports.getDefinedRootType = void 0;
4
+ const memoize_js_1 = require("./memoize.js");
5
+ function getDefinedRootType(schema, operation) {
6
+ const rootTypeMap = (0, exports.getRootTypeMap)(schema);
7
+ const rootType = rootTypeMap.get(operation);
8
+ if (rootType == null) {
9
+ throw new Error(`Root type for operation "${operation}" not defined by the given schema.`);
10
+ }
11
+ return rootType;
12
+ }
13
+ exports.getDefinedRootType = getDefinedRootType;
14
+ exports.getRootTypeNames = (0, memoize_js_1.memoize1)(function getRootTypeNames(schema) {
15
+ const rootTypes = (0, exports.getRootTypes)(schema);
16
+ return new Set([...rootTypes].map(type => type.name));
17
+ });
18
+ exports.getRootTypes = (0, memoize_js_1.memoize1)(function getRootTypes(schema) {
19
+ const rootTypeMap = (0, exports.getRootTypeMap)(schema);
20
+ return new Set(rootTypeMap.values());
21
+ });
22
+ exports.getRootTypeMap = (0, memoize_js_1.memoize1)(function getRootTypeMap(schema) {
23
+ const rootTypeMap = new Map();
24
+ const queryType = schema.getQueryType();
25
+ if (queryType) {
26
+ rootTypeMap.set('query', queryType);
27
+ }
28
+ const mutationType = schema.getMutationType();
29
+ if (mutationType) {
30
+ rootTypeMap.set('mutation', mutationType);
31
+ }
32
+ const subscriptionType = schema.getSubscriptionType();
33
+ if (subscriptionType) {
34
+ rootTypeMap.set('subscription', subscriptionType);
35
+ }
36
+ return rootTypeMap;
37
+ });
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseSelectionSet = void 0;
4
+ const graphql_1 = require("graphql");
5
+ function parseSelectionSet(selectionSet, options) {
6
+ const query = (0, graphql_1.parse)(selectionSet, options).definitions[0];
7
+ return query.selectionSet;
8
+ }
9
+ exports.parseSelectionSet = parseSelectionSet;
package/cjs/stub.js ADDED
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getBuiltInForStub = exports.isNamedStub = exports.createStub = exports.createNamedStub = void 0;
4
+ const graphql_1 = require("graphql");
5
+ function createNamedStub(name, type) {
6
+ let constructor;
7
+ if (type === 'object') {
8
+ constructor = graphql_1.GraphQLObjectType;
9
+ }
10
+ else if (type === 'interface') {
11
+ constructor = graphql_1.GraphQLInterfaceType;
12
+ }
13
+ else {
14
+ constructor = graphql_1.GraphQLInputObjectType;
15
+ }
16
+ return new constructor({
17
+ name,
18
+ fields: {
19
+ _fake: {
20
+ type: graphql_1.GraphQLString,
21
+ },
22
+ },
23
+ });
24
+ }
25
+ exports.createNamedStub = createNamedStub;
26
+ function createStub(node, type) {
27
+ switch (node.kind) {
28
+ case graphql_1.Kind.LIST_TYPE:
29
+ return new graphql_1.GraphQLList(createStub(node.type, type));
30
+ case graphql_1.Kind.NON_NULL_TYPE:
31
+ return new graphql_1.GraphQLNonNull(createStub(node.type, type));
32
+ default:
33
+ if (type === 'output') {
34
+ return createNamedStub(node.name.value, 'object');
35
+ }
36
+ return createNamedStub(node.name.value, 'input');
37
+ }
38
+ }
39
+ exports.createStub = createStub;
40
+ function isNamedStub(type) {
41
+ if ('getFields' in type) {
42
+ const fields = type.getFields();
43
+ // eslint-disable-next-line no-unreachable-loop
44
+ for (const fieldName in fields) {
45
+ const field = fields[fieldName];
46
+ return field.name === '_fake';
47
+ }
48
+ }
49
+ return false;
50
+ }
51
+ exports.isNamedStub = isNamedStub;
52
+ function getBuiltInForStub(type) {
53
+ switch (type.name) {
54
+ case graphql_1.GraphQLInt.name:
55
+ return graphql_1.GraphQLInt;
56
+ case graphql_1.GraphQLFloat.name:
57
+ return graphql_1.GraphQLFloat;
58
+ case graphql_1.GraphQLString.name:
59
+ return graphql_1.GraphQLString;
60
+ case graphql_1.GraphQLBoolean.name:
61
+ return graphql_1.GraphQLBoolean;
62
+ case graphql_1.GraphQLID.name:
63
+ return graphql_1.GraphQLID;
64
+ default:
65
+ return type;
66
+ }
67
+ }
68
+ exports.getBuiltInForStub = getBuiltInForStub;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseInputValueLiteral = exports.parseInputValue = exports.serializeInputValue = exports.transformInputValue = void 0;
4
+ const graphql_1 = require("graphql");
5
+ function transformInputValue(type, value, inputLeafValueTransformer = null, inputObjectValueTransformer = null) {
6
+ if (value == null) {
7
+ return value;
8
+ }
9
+ const nullableType = (0, graphql_1.getNullableType)(type);
10
+ if ((0, graphql_1.isLeafType)(nullableType)) {
11
+ return inputLeafValueTransformer != null ? inputLeafValueTransformer(nullableType, value) : value;
12
+ }
13
+ else if ((0, graphql_1.isListType)(nullableType)) {
14
+ return value.map((listMember) => transformInputValue(nullableType.ofType, listMember, inputLeafValueTransformer, inputObjectValueTransformer));
15
+ }
16
+ else if ((0, graphql_1.isInputObjectType)(nullableType)) {
17
+ const fields = nullableType.getFields();
18
+ const newValue = {};
19
+ for (const key in value) {
20
+ const field = fields[key];
21
+ if (field != null) {
22
+ newValue[key] = transformInputValue(field.type, value[key], inputLeafValueTransformer, inputObjectValueTransformer);
23
+ }
24
+ }
25
+ return inputObjectValueTransformer != null ? inputObjectValueTransformer(nullableType, newValue) : newValue;
26
+ }
27
+ // unreachable, no other possible return value
28
+ }
29
+ exports.transformInputValue = transformInputValue;
30
+ function serializeInputValue(type, value) {
31
+ return transformInputValue(type, value, (t, v) => {
32
+ try {
33
+ return t.serialize(v);
34
+ }
35
+ catch (_a) {
36
+ return v;
37
+ }
38
+ });
39
+ }
40
+ exports.serializeInputValue = serializeInputValue;
41
+ function parseInputValue(type, value) {
42
+ return transformInputValue(type, value, (t, v) => {
43
+ try {
44
+ return t.parseValue(v);
45
+ }
46
+ catch (_a) {
47
+ return v;
48
+ }
49
+ });
50
+ }
51
+ exports.parseInputValue = parseInputValue;
52
+ function parseInputValueLiteral(type, value) {
53
+ return transformInputValue(type, value, (t, v) => t.parseLiteral(v, {}));
54
+ }
55
+ exports.parseInputValueLiteral = parseInputValueLiteral;
package/cjs/types.js ADDED
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DirectiveLocation = void 0;
4
+ var DirectiveLocation;
5
+ (function (DirectiveLocation) {
6
+ /** Request Definitions */
7
+ DirectiveLocation["QUERY"] = "QUERY";
8
+ DirectiveLocation["MUTATION"] = "MUTATION";
9
+ DirectiveLocation["SUBSCRIPTION"] = "SUBSCRIPTION";
10
+ DirectiveLocation["FIELD"] = "FIELD";
11
+ DirectiveLocation["FRAGMENT_DEFINITION"] = "FRAGMENT_DEFINITION";
12
+ DirectiveLocation["FRAGMENT_SPREAD"] = "FRAGMENT_SPREAD";
13
+ DirectiveLocation["INLINE_FRAGMENT"] = "INLINE_FRAGMENT";
14
+ DirectiveLocation["VARIABLE_DEFINITION"] = "VARIABLE_DEFINITION";
15
+ /** Type System Definitions */
16
+ DirectiveLocation["SCHEMA"] = "SCHEMA";
17
+ DirectiveLocation["SCALAR"] = "SCALAR";
18
+ DirectiveLocation["OBJECT"] = "OBJECT";
19
+ DirectiveLocation["FIELD_DEFINITION"] = "FIELD_DEFINITION";
20
+ DirectiveLocation["ARGUMENT_DEFINITION"] = "ARGUMENT_DEFINITION";
21
+ DirectiveLocation["INTERFACE"] = "INTERFACE";
22
+ DirectiveLocation["UNION"] = "UNION";
23
+ DirectiveLocation["ENUM"] = "ENUM";
24
+ DirectiveLocation["ENUM_VALUE"] = "ENUM_VALUE";
25
+ DirectiveLocation["INPUT_OBJECT"] = "INPUT_OBJECT";
26
+ DirectiveLocation["INPUT_FIELD_DEFINITION"] = "INPUT_FIELD_DEFINITION";
27
+ })(DirectiveLocation = exports.DirectiveLocation || (exports.DirectiveLocation = {}));
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createVariableNameGenerator = exports.updateArgument = void 0;
4
+ const graphql_1 = require("graphql");
5
+ const astFromType_js_1 = require("./astFromType.js");
6
+ function updateArgument(argumentNodes, variableDefinitionsMap, variableValues, argName, varName, type, value) {
7
+ argumentNodes[argName] = {
8
+ kind: graphql_1.Kind.ARGUMENT,
9
+ name: {
10
+ kind: graphql_1.Kind.NAME,
11
+ value: argName,
12
+ },
13
+ value: {
14
+ kind: graphql_1.Kind.VARIABLE,
15
+ name: {
16
+ kind: graphql_1.Kind.NAME,
17
+ value: varName,
18
+ },
19
+ },
20
+ };
21
+ variableDefinitionsMap[varName] = {
22
+ kind: graphql_1.Kind.VARIABLE_DEFINITION,
23
+ variable: {
24
+ kind: graphql_1.Kind.VARIABLE,
25
+ name: {
26
+ kind: graphql_1.Kind.NAME,
27
+ value: varName,
28
+ },
29
+ },
30
+ type: (0, astFromType_js_1.astFromType)(type),
31
+ };
32
+ if (value !== undefined) {
33
+ variableValues[varName] = value;
34
+ return;
35
+ }
36
+ // including the variable in the map with value of `undefined`
37
+ // will actually be translated by graphql-js into `null`
38
+ // see https://github.com/graphql/graphql-js/issues/2533
39
+ if (varName in variableValues) {
40
+ delete variableValues[varName];
41
+ }
42
+ }
43
+ exports.updateArgument = updateArgument;
44
+ function createVariableNameGenerator(variableDefinitionMap) {
45
+ let varCounter = 0;
46
+ return (argName) => {
47
+ let varName;
48
+ do {
49
+ varName = `_v${(varCounter++).toString()}_${argName}`;
50
+ } while (varName in variableDefinitionMap);
51
+ return varName;
52
+ };
53
+ }
54
+ exports.createVariableNameGenerator = createVariableNameGenerator;
@@ -0,0 +1,76 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createDefaultRules = exports.checkValidationErrors = exports.validateGraphQlDocuments = void 0;
4
+ const graphql_1 = require("graphql");
5
+ const AggregateError_js_1 = require("./AggregateError.js");
6
+ async function validateGraphQlDocuments(schema, documentFiles, effectiveRules = createDefaultRules()) {
7
+ const allFragmentMap = new Map();
8
+ const documentFileObjectsToValidate = [];
9
+ for (const documentFile of documentFiles) {
10
+ if (documentFile.document) {
11
+ const definitionsToValidate = [];
12
+ for (const definitionNode of documentFile.document.definitions) {
13
+ if (definitionNode.kind === graphql_1.Kind.FRAGMENT_DEFINITION) {
14
+ allFragmentMap.set(definitionNode.name.value, definitionNode);
15
+ }
16
+ else {
17
+ definitionsToValidate.push(definitionNode);
18
+ }
19
+ }
20
+ documentFileObjectsToValidate.push({
21
+ location: documentFile.location,
22
+ document: {
23
+ kind: graphql_1.Kind.DOCUMENT,
24
+ definitions: definitionsToValidate,
25
+ },
26
+ });
27
+ }
28
+ }
29
+ const allErrors = [];
30
+ const allFragmentsDocument = {
31
+ kind: graphql_1.Kind.DOCUMENT,
32
+ definitions: [...allFragmentMap.values()],
33
+ };
34
+ await Promise.all(documentFileObjectsToValidate.map(async (documentFile) => {
35
+ const documentToValidate = (0, graphql_1.concatAST)([allFragmentsDocument, documentFile.document]);
36
+ const errors = (0, graphql_1.validate)(schema, documentToValidate, effectiveRules);
37
+ if (errors.length > 0) {
38
+ allErrors.push({
39
+ filePath: documentFile.location,
40
+ errors,
41
+ });
42
+ }
43
+ }));
44
+ return allErrors;
45
+ }
46
+ exports.validateGraphQlDocuments = validateGraphQlDocuments;
47
+ function checkValidationErrors(loadDocumentErrors) {
48
+ if (loadDocumentErrors.length > 0) {
49
+ const errors = [];
50
+ for (const loadDocumentError of loadDocumentErrors) {
51
+ for (const graphQLError of loadDocumentError.errors) {
52
+ const error = new Error();
53
+ error.name = 'GraphQLDocumentError';
54
+ error.message = `${error.name}: ${graphQLError.message}`;
55
+ error.stack = error.message;
56
+ if (graphQLError.locations) {
57
+ for (const location of graphQLError.locations) {
58
+ error.stack += `\n at ${loadDocumentError.filePath}:${location.line}:${location.column}`;
59
+ }
60
+ }
61
+ errors.push(error);
62
+ }
63
+ }
64
+ throw new AggregateError_js_1.AggregateError(errors, `GraphQL Document Validation failed with ${errors.length} errors;
65
+ ${errors.map((error, index) => `Error ${index}: ${error.stack}`).join('\n\n')}`);
66
+ }
67
+ }
68
+ exports.checkValidationErrors = checkValidationErrors;
69
+ function createDefaultRules() {
70
+ let ignored = ['NoUnusedFragmentsRule', 'NoUnusedVariablesRule', 'KnownDirectivesRule'];
71
+ if (graphql_1.versionInfo.major < 15) {
72
+ ignored = ignored.map(rule => rule.replace(/Rule$/, ''));
73
+ }
74
+ return graphql_1.specifiedRules.filter((f) => !ignored.includes(f.name));
75
+ }
76
+ exports.createDefaultRules = createDefaultRules;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.valueMatchesCriteria = void 0;
4
+ function valueMatchesCriteria(value, criteria) {
5
+ if (value == null) {
6
+ return value === criteria;
7
+ }
8
+ else if (Array.isArray(value)) {
9
+ return Array.isArray(criteria) && value.every((val, index) => valueMatchesCriteria(val, criteria[index]));
10
+ }
11
+ else if (typeof value === 'object') {
12
+ return (typeof criteria === 'object' &&
13
+ criteria &&
14
+ Object.keys(criteria).every(propertyName => valueMatchesCriteria(value[propertyName], criteria[propertyName])));
15
+ }
16
+ else if (criteria instanceof RegExp) {
17
+ return criteria.test(value);
18
+ }
19
+ return value === criteria;
20
+ }
21
+ exports.valueMatchesCriteria = valueMatchesCriteria;