graphql-jit 0.8.9 → 0.9.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 (178) hide show
  1. package/README.md +25 -0
  2. package/dist/cjs/ast.d.ts +89 -0
  3. package/dist/cjs/ast.js +766 -0
  4. package/dist/cjs/ast.js.map +1 -0
  5. package/dist/cjs/compat.d.ts +70 -0
  6. package/dist/cjs/compat.js +144 -0
  7. package/dist/cjs/compat.js.map +1 -0
  8. package/dist/cjs/debug.d.ts +29 -0
  9. package/dist/cjs/debug.js +46 -0
  10. package/dist/cjs/debug.js.map +1 -0
  11. package/dist/cjs/error.d.ts +7 -0
  12. package/dist/cjs/error.js +58 -0
  13. package/dist/cjs/error.js.map +1 -0
  14. package/dist/cjs/execution.d.ts +154 -0
  15. package/dist/cjs/execution.js +1240 -0
  16. package/dist/cjs/execution.js.map +1 -0
  17. package/dist/cjs/generate.d.ts +4 -0
  18. package/dist/cjs/generate.js +13 -0
  19. package/dist/cjs/generate.js.map +1 -0
  20. package/dist/cjs/index.d.ts +3 -0
  21. package/dist/cjs/index.js +10 -0
  22. package/dist/cjs/index.js.map +1 -0
  23. package/dist/cjs/inspect.d.ts +5 -0
  24. package/dist/cjs/inspect.js +110 -0
  25. package/dist/cjs/inspect.js.map +1 -0
  26. package/dist/cjs/json.d.ts +9 -0
  27. package/dist/cjs/json.js +144 -0
  28. package/dist/cjs/json.js.map +1 -0
  29. package/dist/cjs/memoize.d.ts +5 -0
  30. package/dist/cjs/memoize.js +28 -0
  31. package/dist/cjs/memoize.js.map +1 -0
  32. package/dist/cjs/non-null.d.ts +9 -0
  33. package/dist/cjs/non-null.js +205 -0
  34. package/dist/cjs/non-null.js.map +1 -0
  35. package/dist/cjs/package.json +3 -0
  36. package/dist/{resolve-info.d.ts → cjs/resolve-info.d.ts} +10 -12
  37. package/dist/cjs/resolve-info.js +232 -0
  38. package/dist/cjs/resolve-info.js.map +1 -0
  39. package/dist/cjs/runtime.d.ts +14 -0
  40. package/dist/cjs/runtime.js +92 -0
  41. package/dist/cjs/runtime.js.map +1 -0
  42. package/dist/cjs/types.d.ts +1 -0
  43. package/dist/cjs/types.js +3 -0
  44. package/dist/cjs/types.js.map +1 -0
  45. package/dist/cjs/variables.d.ts +20 -0
  46. package/dist/cjs/variables.js +357 -0
  47. package/dist/cjs/variables.js.map +1 -0
  48. package/dist/esm/ast.d.ts +89 -0
  49. package/dist/esm/ast.js +751 -0
  50. package/dist/esm/ast.js.map +1 -0
  51. package/dist/esm/compat.d.ts +70 -0
  52. package/dist/esm/compat.js +102 -0
  53. package/dist/esm/compat.js.map +1 -0
  54. package/dist/esm/debug.d.ts +29 -0
  55. package/dist/esm/debug.js +40 -0
  56. package/dist/esm/debug.js.map +1 -0
  57. package/dist/esm/error.d.ts +7 -0
  58. package/dist/esm/error.js +55 -0
  59. package/dist/esm/error.js.map +1 -0
  60. package/dist/esm/execution.d.ts +154 -0
  61. package/dist/esm/execution.js +1227 -0
  62. package/dist/esm/execution.js.map +1 -0
  63. package/dist/esm/generate.d.ts +4 -0
  64. package/dist/esm/generate.js +10 -0
  65. package/dist/esm/generate.js.map +1 -0
  66. package/dist/esm/index.d.ts +3 -0
  67. package/dist/esm/index.js +3 -0
  68. package/dist/esm/index.js.map +1 -0
  69. package/dist/esm/inspect.d.ts +5 -0
  70. package/dist/esm/inspect.js +106 -0
  71. package/dist/esm/inspect.js.map +1 -0
  72. package/dist/esm/json.d.ts +9 -0
  73. package/dist/esm/json.js +141 -0
  74. package/dist/esm/json.js.map +1 -0
  75. package/dist/esm/memoize.d.ts +5 -0
  76. package/dist/esm/memoize.js +20 -0
  77. package/dist/esm/memoize.js.map +1 -0
  78. package/dist/esm/non-null.d.ts +9 -0
  79. package/dist/esm/non-null.js +199 -0
  80. package/dist/esm/non-null.js.map +1 -0
  81. package/dist/esm/package.json +3 -0
  82. package/dist/{resolve-info.d.mts → esm/resolve-info.d.ts} +10 -12
  83. package/dist/esm/resolve-info.js +224 -0
  84. package/dist/esm/resolve-info.js.map +1 -0
  85. package/dist/esm/runtime.d.ts +14 -0
  86. package/dist/esm/runtime.js +89 -0
  87. package/dist/esm/runtime.js.map +1 -0
  88. package/dist/esm/types.d.ts +1 -0
  89. package/dist/esm/types.js +2 -0
  90. package/dist/esm/types.js.map +1 -0
  91. package/dist/esm/variables.d.ts +20 -0
  92. package/dist/esm/variables.js +350 -0
  93. package/dist/esm/variables.js.map +1 -0
  94. package/package.json +39 -35
  95. package/dist/ast.d.mts +0 -7
  96. package/dist/ast.d.ts +0 -7
  97. package/dist/ast.js +0 -635
  98. package/dist/ast.js.map +0 -1
  99. package/dist/ast.mjs +0 -612
  100. package/dist/ast.mjs.map +0 -1
  101. package/dist/compat.d.mts +0 -7
  102. package/dist/compat.d.ts +0 -7
  103. package/dist/compat.js +0 -113
  104. package/dist/compat.js.map +0 -1
  105. package/dist/compat.mjs +0 -75
  106. package/dist/compat.mjs.map +0 -1
  107. package/dist/error.d.mts +0 -11
  108. package/dist/error.d.ts +0 -11
  109. package/dist/error.js +0 -79
  110. package/dist/error.js.map +0 -1
  111. package/dist/error.mjs +0 -57
  112. package/dist/error.mjs.map +0 -1
  113. package/dist/execution.d.mts +0 -7
  114. package/dist/execution.d.ts +0 -7
  115. package/dist/execution.js +0 -1262
  116. package/dist/execution.js.map +0 -1
  117. package/dist/execution.mjs +0 -1248
  118. package/dist/execution.mjs.map +0 -1
  119. package/dist/generate.d.mts +0 -6
  120. package/dist/generate.d.ts +0 -6
  121. package/dist/generate.js +0 -37
  122. package/dist/generate.js.map +0 -1
  123. package/dist/generate.mjs +0 -13
  124. package/dist/generate.mjs.map +0 -1
  125. package/dist/index-CeluTkd4.d.mts +0 -329
  126. package/dist/index-mKv2zpdA.d.ts +0 -329
  127. package/dist/index.d.mts +0 -7
  128. package/dist/index.d.ts +0 -7
  129. package/dist/index.js +0 -36
  130. package/dist/index.js.map +0 -1
  131. package/dist/index.mjs +0 -15
  132. package/dist/index.mjs.map +0 -1
  133. package/dist/inspect.d.mts +0 -7
  134. package/dist/inspect.d.ts +0 -7
  135. package/dist/inspect.js +0 -121
  136. package/dist/inspect.js.map +0 -1
  137. package/dist/inspect.mjs +0 -97
  138. package/dist/inspect.mjs.map +0 -1
  139. package/dist/json.d.mts +0 -18
  140. package/dist/json.d.ts +0 -18
  141. package/dist/json.js +0 -181
  142. package/dist/json.js.map +0 -1
  143. package/dist/json.mjs +0 -164
  144. package/dist/json.mjs.map +0 -1
  145. package/dist/memoize.d.mts +0 -6
  146. package/dist/memoize.d.ts +0 -6
  147. package/dist/memoize.js +0 -67
  148. package/dist/memoize.js.map +0 -1
  149. package/dist/memoize.mjs +0 -31
  150. package/dist/memoize.mjs.map +0 -1
  151. package/dist/non-null.d.mts +0 -7
  152. package/dist/non-null.d.ts +0 -7
  153. package/dist/non-null.js +0 -196
  154. package/dist/non-null.js.map +0 -1
  155. package/dist/non-null.mjs +0 -167
  156. package/dist/non-null.mjs.map +0 -1
  157. package/dist/resolve-info.js +0 -245
  158. package/dist/resolve-info.js.map +0 -1
  159. package/dist/resolve-info.mjs +0 -219
  160. package/dist/resolve-info.mjs.map +0 -1
  161. package/dist/runtime.d.mts +0 -7
  162. package/dist/runtime.d.ts +0 -7
  163. package/dist/runtime.js +0 -115
  164. package/dist/runtime.js.map +0 -1
  165. package/dist/runtime.mjs +0 -91
  166. package/dist/runtime.mjs.map +0 -1
  167. package/dist/types.d.mts +0 -3
  168. package/dist/types.d.ts +0 -3
  169. package/dist/types.js +0 -17
  170. package/dist/types.js.map +0 -1
  171. package/dist/types.mjs +0 -1
  172. package/dist/types.mjs.map +0 -1
  173. package/dist/variables.d.mts +0 -17
  174. package/dist/variables.d.ts +0 -17
  175. package/dist/variables.js +0 -412
  176. package/dist/variables.js.map +0 -1
  177. package/dist/variables.mjs +0 -391
  178. package/dist/variables.mjs.map +0 -1
package/dist/non-null.js DELETED
@@ -1,196 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var non_null_exports = {};
30
- __export(non_null_exports, {
31
- createNullTrimmer: () => createNullTrimmer
32
- });
33
- module.exports = __toCommonJS(non_null_exports);
34
- var import_graphql = require("graphql");
35
- var import_lodash = __toESM(require("lodash.merge"));
36
- var import_ast = require("./ast.js");
37
- var import_compat = require("./compat.js");
38
- function createNullTrimmer(compilationContext) {
39
- return trimData(parseQueryNullables(compilationContext));
40
- }
41
- function trimData(nullable) {
42
- return (data, errors) => {
43
- const finalErrors = [];
44
- const processedErrors = /* @__PURE__ */ new Set();
45
- for (const error of errors) {
46
- if (!error.path) {
47
- throw new Error("no path available for tree trimming");
48
- }
49
- if (processedErrors.has(error.path.join("."))) {
50
- continue;
51
- }
52
- const ancestors = findNullableAncestor(nullable, error.path);
53
- if (ancestors.length === 0) {
54
- data = null;
55
- finalErrors.push(error);
56
- break;
57
- }
58
- removeBranch(data, ancestors);
59
- processedErrors.add(error.path.join("."));
60
- finalErrors.push(error);
61
- }
62
- return { data, errors: finalErrors };
63
- };
64
- }
65
- function removeBranch(tree, branch) {
66
- for (let i = 0; i < branch.length - 1; ++i) {
67
- if (tree[branch[i]] === null) {
68
- return;
69
- }
70
- tree = tree[branch[i]];
71
- }
72
- const toNull = branch[branch.length - 1];
73
- tree[toNull] = null;
74
- }
75
- const ARRAY_CHILD_NAME = "index";
76
- function findNullableAncestor(nullable, paths) {
77
- let lastNullable = 0;
78
- for (let i = 0; i < paths.length; ++i) {
79
- const path = paths[i];
80
- const child = nullable.children[typeof path === "string" ? path : ARRAY_CHILD_NAME];
81
- if (!child) {
82
- break;
83
- }
84
- if (child.isNullable) {
85
- lastNullable = i + 1;
86
- }
87
- nullable = child;
88
- }
89
- return paths.slice(0, lastNullable);
90
- }
91
- function parseQueryNullables(compilationContext) {
92
- const type = (0, import_compat.getOperationRootType)(
93
- compilationContext.schema,
94
- compilationContext.operation
95
- );
96
- const fields = (0, import_ast.collectFields)(
97
- compilationContext,
98
- type,
99
- compilationContext.operation.selectionSet,
100
- /* @__PURE__ */ Object.create(null),
101
- /* @__PURE__ */ Object.create(null)
102
- );
103
- const properties = /* @__PURE__ */ Object.create(null);
104
- for (const responseName of Object.keys(fields)) {
105
- const fieldType = (0, import_ast.resolveFieldDef)(
106
- compilationContext,
107
- type,
108
- fields[responseName]
109
- );
110
- if (!fieldType) {
111
- continue;
112
- }
113
- const property = transformNode(
114
- compilationContext,
115
- fields[responseName],
116
- fieldType.type
117
- );
118
- if (property != null) {
119
- properties[responseName] = property;
120
- }
121
- }
122
- return {
123
- isNullable: true,
124
- children: properties
125
- };
126
- }
127
- function transformNode(compilationContext, fieldNodes, type) {
128
- if ((0, import_graphql.isNonNullType)(type)) {
129
- const nullable = transformNode(compilationContext, fieldNodes, type.ofType);
130
- if (nullable != null) {
131
- nullable.isNullable = false;
132
- return nullable;
133
- }
134
- return null;
135
- }
136
- if ((0, import_graphql.isObjectType)(type)) {
137
- const subfields = (0, import_ast.collectSubfields)(compilationContext, type, fieldNodes);
138
- const properties = /* @__PURE__ */ Object.create(null);
139
- for (const responseName of Object.keys(subfields)) {
140
- const fieldType = (0, import_ast.resolveFieldDef)(
141
- compilationContext,
142
- type,
143
- subfields[responseName]
144
- );
145
- if (!fieldType) {
146
- continue;
147
- }
148
- const property = transformNode(
149
- compilationContext,
150
- subfields[responseName],
151
- fieldType.type
152
- );
153
- if (property != null) {
154
- properties[responseName] = property;
155
- }
156
- }
157
- return {
158
- isNullable: true,
159
- children: properties
160
- };
161
- }
162
- if ((0, import_graphql.isListType)(type)) {
163
- const child = transformNode(compilationContext, fieldNodes, type.ofType);
164
- if (child != null) {
165
- return {
166
- isNullable: true,
167
- children: { [ARRAY_CHILD_NAME]: child }
168
- };
169
- }
170
- return {
171
- isNullable: true,
172
- children: {}
173
- };
174
- }
175
- if ((0, import_graphql.isAbstractType)(type)) {
176
- return compilationContext.schema.getPossibleTypes(type).reduce(
177
- (res, t) => {
178
- const property = transformNode(compilationContext, fieldNodes, t);
179
- if (property != null) {
180
- res.children = (0, import_lodash.default)(res.children, property.children);
181
- }
182
- return res;
183
- },
184
- {
185
- isNullable: true,
186
- children: {}
187
- }
188
- );
189
- }
190
- return null;
191
- }
192
- // Annotate the CommonJS export names for ESM import in node:
193
- 0 && (module.exports = {
194
- createNullTrimmer
195
- });
196
- //# sourceMappingURL=non-null.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/non-null.ts"],"sourcesContent":["import {\n type ExecutionResult,\n type FieldNode,\n type GraphQLError,\n type GraphQLType,\n isListType,\n isNonNullType,\n isObjectType,\n isAbstractType\n} from \"graphql\";\nimport merge from \"lodash.merge\";\nimport { collectFields, collectSubfields, resolveFieldDef } from \"./ast.js\";\nimport { getOperationRootType } from \"./compat.js\";\nimport { type CompilationContext } from \"./execution.js\";\n\ninterface QueryMetadata {\n isNullable: boolean;\n children: { [key: string]: QueryMetadata };\n}\n\nexport type NullTrimmer = (data: any, errors: GraphQLError[]) => any;\n\n/**\n *\n * @param {CompilationContext} compilationContext\n * @returns {(data: any, errors: GraphQLError[]) => {data: any; errors: GraphQLError[]}}\n */\nexport function createNullTrimmer(\n compilationContext: CompilationContext\n): NullTrimmer {\n return trimData(parseQueryNullables(compilationContext));\n}\n\n/**\n * Trims a data response according to the field errors in non null fields.\n *\n * Errors are filtered to ensure a single field error per field.\n *\n * @param {QueryMetadata} nullable Description of the query and their nullability\n * @returns {(data: any, errors: GraphQLError[]) => {data: any; errors: GraphQLError[]}}\n * the trimmed data and a filtered list of errors.\n */\nfunction trimData(nullable: QueryMetadata): NullTrimmer {\n return (data: any, errors: GraphQLError[]): ExecutionResult => {\n const finalErrors = [];\n const processedErrors = new Set<string>();\n for (const error of errors) {\n if (!error.path) {\n // should never happen, it is a bug if it does\n throw new Error(\"no path available for tree trimming\");\n }\n if (processedErrors.has(error.path.join(\".\"))) {\n // there can be multiple field errors in some scenario\n // there is no need to continue processing and it should not be part of the final response\n continue;\n }\n const ancestors = findNullableAncestor(nullable, error.path);\n // The top level field is always nullable\n // http://facebook.github.io/graphql/June2018/#sec-Errors-and-Non-Nullability\n //\n // There is no mention if the following errors need to be present in the response.\n // For now we assume this is not needed.\n if (ancestors.length === 0) {\n data = null;\n finalErrors.push(error);\n break;\n }\n removeBranch(data, ancestors);\n processedErrors.add(error.path.join(\".\"));\n finalErrors.push(error);\n }\n return { data, errors: finalErrors };\n };\n}\n\n/**\n * Removes a branch out of the response data by mutating the original object.\n *\n * @param tree response data\n * @param {Array<number | string>} branch array with the path that should be trimmed\n */\nfunction removeBranch(tree: any, branch: Array<number | string>): void {\n for (let i = 0; i < branch.length - 1; ++i) {\n // if ancestor has already been removed, there's nothing to do\n if (tree[branch[i]] === null) {\n return;\n }\n tree = tree[branch[i]];\n }\n const toNull = branch[branch.length - 1];\n tree[toNull] = null;\n}\n\n/**\n * Name of the child used in array to contain the description.\n *\n * Only used for list to contain the child description.\n */\nconst ARRAY_CHILD_NAME = \"index\";\n\n/**\n *\n * @param {QueryMetadata} nullable Description of the query and their nullability\n * @param {ReadonlyArray<string | number>} paths path of the error location\n * @returns {Array<string | number>} path of the branch to be made null\n */\nfunction findNullableAncestor(\n nullable: QueryMetadata,\n paths: ReadonlyArray<string | number>\n): Array<string | number> {\n let lastNullable = 0;\n for (let i = 0; i < paths.length; ++i) {\n const path = paths[i];\n const child =\n nullable.children[typeof path === \"string\" ? path : ARRAY_CHILD_NAME];\n if (!child) {\n // Stopping the search since we reached a leaf node,\n // the loop should be on its final iteration\n break;\n }\n if (child.isNullable) {\n lastNullable = i + 1;\n }\n nullable = child;\n }\n return paths.slice(0, lastNullable);\n}\n\n/**\n * Produce a description of the query regarding its nullability.\n *\n * Leaf nodes are not present in this representation since they are not\n * interesting for removing branches of the response tree.\n *\n * The structure is recursive like the query.\n * @param {CompilationContext} compilationContext Execution content\n * @returns {QueryMetadata} description of the query\n */\nfunction parseQueryNullables(\n compilationContext: CompilationContext\n): QueryMetadata {\n const type = getOperationRootType(\n compilationContext.schema,\n compilationContext.operation\n );\n const fields = collectFields(\n compilationContext,\n type,\n compilationContext.operation.selectionSet,\n Object.create(null),\n Object.create(null)\n );\n const properties = Object.create(null);\n for (const responseName of Object.keys(fields)) {\n const fieldType = resolveFieldDef(\n compilationContext,\n type,\n fields[responseName]\n );\n if (!fieldType) {\n // if field does not exist, it should be ignored for compatibility concerns.\n // Usually, validation would stop it before getting here but this could be an old query\n continue;\n }\n const property = transformNode(\n compilationContext,\n fields[responseName],\n fieldType.type\n );\n if (property != null) {\n properties[responseName] = property;\n }\n }\n return {\n isNullable: true,\n children: properties\n };\n}\n\n/**\n * Processes a single node to produce a description of itself and its children.\n *\n * Leaf nodes are ignore and removed from the description\n * @param {CompilationContext} compilationContext\n * @param {FieldNode[]} fieldNodes list of fields\n * @param {GraphQLType} type Current type being processed.\n * @returns {QueryMetadata | null} null if node is a leaf, otherwise a description of the node and its children.\n */\nfunction transformNode(\n compilationContext: CompilationContext,\n fieldNodes: FieldNode[],\n type: GraphQLType\n): QueryMetadata | null {\n if (isNonNullType(type)) {\n const nullable = transformNode(compilationContext, fieldNodes, type.ofType);\n if (nullable != null) {\n nullable.isNullable = false;\n return nullable;\n }\n return null;\n }\n if (isObjectType(type)) {\n const subfields = collectSubfields(compilationContext, type, fieldNodes);\n const properties = Object.create(null);\n for (const responseName of Object.keys(subfields)) {\n const fieldType = resolveFieldDef(\n compilationContext,\n type,\n subfields[responseName]\n );\n if (!fieldType) {\n // if field does not exist, it should be ignored for compatibility concerns.\n // Usually, validation would stop it before getting here but this could be an old query\n continue;\n }\n const property = transformNode(\n compilationContext,\n subfields[responseName],\n fieldType.type\n );\n if (property != null) {\n properties[responseName] = property;\n }\n }\n return {\n isNullable: true,\n children: properties\n };\n }\n if (isListType(type)) {\n const child = transformNode(compilationContext, fieldNodes, type.ofType);\n if (child != null) {\n return {\n isNullable: true,\n children: { [ARRAY_CHILD_NAME]: child }\n };\n }\n\n return {\n isNullable: true,\n children: {}\n };\n }\n if (isAbstractType(type)) {\n return compilationContext.schema.getPossibleTypes(type).reduce(\n (res, t) => {\n const property = transformNode(compilationContext, fieldNodes, t);\n if (property != null) {\n // We do a deep merge because children can have subset of properties\n // TODO: Possible bug: two object with different nullability on objects.\n res.children = merge(res.children, property.children);\n }\n return res;\n },\n {\n isNullable: true,\n children: {}\n }\n );\n }\n\n // Scalars and enum are ignored since they are leaf values\n return null;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBASO;AACP,oBAAkB;AAClB,iBAAiE;AACjE,oBAAqC;AAe9B,SAAS,kBACd,oBACa;AACb,SAAO,SAAS,oBAAoB,kBAAkB,CAAC;AACzD;AAWA,SAAS,SAAS,UAAsC;AACtD,SAAO,CAAC,MAAW,WAA4C;A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ACA,WAAO;AAAA,MACL,YAAY;AAAA,MACZ,UAAU;AAAA,IACZ;AAAA,EACF;AACA,UAAI,2BAAW,IAAI,GAAG;AACpB,UAAM,QAAQ,cAAc,oBAAoB,YAAY,KAAK,MAAM;AACvE,QAAI,SAAS,MAAM;AACjB,aAAO;AAAA,QACL,YAAY;AAAA,QACZ,UAAU,EAAE,CAAC,gBAAgB,GAAG,MAAM;AAAA,MACxC;AAAA,IACF;AAEA,WAAO;AAAA,MACL,YAAY;AAAA,MACZ,UAAU,CAAC;AAAA,IACb;AAAA,EACF;AACA,UAAI,+BAAe,IAAI,GAAG;AACxB,WAAO,mBAAmB,OAAO,iBAAiB,IAAI,EAAE;AAAA,MACtD,CAAC,KAAK,MAAM;AACV,cAAM,WAAW,cAAc,oBAAoB,YAAY,CAAC;AAChE,YAAI,YAAY,MAAM;AAGpB,cAAI,eAAW,cAAAA,SAAM,IAAI,UAAU,SAAS,QAAQ;AAAA,QACtD;AACA,eAAO;AAAA,MACT;AAAA,MACA;AAAA,QACE,YAAY;AAAA,QACZ,UAAU,CAAC;AAAA,MACb;AAAA,IACF;AAAA,EACF;AAGA,SAAO;AACT;","names":["merge"]}
package/dist/non-null.mjs DELETED
@@ -1,167 +0,0 @@
1
- import {
2
- isListType,
3
- isNonNullType,
4
- isObjectType,
5
- isAbstractType
6
- } from "graphql";
7
- import merge from "lodash.merge";
8
- import { collectFields, collectSubfields, resolveFieldDef } from "./ast.js";
9
- import { getOperationRootType } from "./compat.js";
10
- function createNullTrimmer(compilationContext) {
11
- return trimData(parseQueryNullables(compilationContext));
12
- }
13
- function trimData(nullable) {
14
- return (data, errors) => {
15
- const finalErrors = [];
16
- const processedErrors = /* @__PURE__ */ new Set();
17
- for (const error of errors) {
18
- if (!error.path) {
19
- throw new Error("no path available for tree trimming");
20
- }
21
- if (processedErrors.has(error.path.join("."))) {
22
- continue;
23
- }
24
- const ancestors = findNullableAncestor(nullable, error.path);
25
- if (ancestors.length === 0) {
26
- data = null;
27
- finalErrors.push(error);
28
- break;
29
- }
30
- removeBranch(data, ancestors);
31
- processedErrors.add(error.path.join("."));
32
- finalErrors.push(error);
33
- }
34
- return { data, errors: finalErrors };
35
- };
36
- }
37
- function removeBranch(tree, branch) {
38
- for (let i = 0; i < branch.length - 1; ++i) {
39
- if (tree[branch[i]] === null) {
40
- return;
41
- }
42
- tree = tree[branch[i]];
43
- }
44
- const toNull = branch[branch.length - 1];
45
- tree[toNull] = null;
46
- }
47
- const ARRAY_CHILD_NAME = "index";
48
- function findNullableAncestor(nullable, paths) {
49
- let lastNullable = 0;
50
- for (let i = 0; i < paths.length; ++i) {
51
- const path = paths[i];
52
- const child = nullable.children[typeof path === "string" ? path : ARRAY_CHILD_NAME];
53
- if (!child) {
54
- break;
55
- }
56
- if (child.isNullable) {
57
- lastNullable = i + 1;
58
- }
59
- nullable = child;
60
- }
61
- return paths.slice(0, lastNullable);
62
- }
63
- function parseQueryNullables(compilationContext) {
64
- const type = getOperationRootType(
65
- compilationContext.schema,
66
- compilationContext.operation
67
- );
68
- const fields = collectFields(
69
- compilationContext,
70
- type,
71
- compilationContext.operation.selectionSet,
72
- /* @__PURE__ */ Object.create(null),
73
- /* @__PURE__ */ Object.create(null)
74
- );
75
- const properties = /* @__PURE__ */ Object.create(null);
76
- for (const responseName of Object.keys(fields)) {
77
- const fieldType = resolveFieldDef(
78
- compilationContext,
79
- type,
80
- fields[responseName]
81
- );
82
- if (!fieldType) {
83
- continue;
84
- }
85
- const property = transformNode(
86
- compilationContext,
87
- fields[responseName],
88
- fieldType.type
89
- );
90
- if (property != null) {
91
- properties[responseName] = property;
92
- }
93
- }
94
- return {
95
- isNullable: true,
96
- children: properties
97
- };
98
- }
99
- function transformNode(compilationContext, fieldNodes, type) {
100
- if (isNonNullType(type)) {
101
- const nullable = transformNode(compilationContext, fieldNodes, type.ofType);
102
- if (nullable != null) {
103
- nullable.isNullable = false;
104
- return nullable;
105
- }
106
- return null;
107
- }
108
- if (isObjectType(type)) {
109
- const subfields = collectSubfields(compilationContext, type, fieldNodes);
110
- const properties = /* @__PURE__ */ Object.create(null);
111
- for (const responseName of Object.keys(subfields)) {
112
- const fieldType = resolveFieldDef(
113
- compilationContext,
114
- type,
115
- subfields[responseName]
116
- );
117
- if (!fieldType) {
118
- continue;
119
- }
120
- const property = transformNode(
121
- compilationContext,
122
- subfields[responseName],
123
- fieldType.type
124
- );
125
- if (property != null) {
126
- properties[responseName] = property;
127
- }
128
- }
129
- return {
130
- isNullable: true,
131
- children: properties
132
- };
133
- }
134
- if (isListType(type)) {
135
- const child = transformNode(compilationContext, fieldNodes, type.ofType);
136
- if (child != null) {
137
- return {
138
- isNullable: true,
139
- children: { [ARRAY_CHILD_NAME]: child }
140
- };
141
- }
142
- return {
143
- isNullable: true,
144
- children: {}
145
- };
146
- }
147
- if (isAbstractType(type)) {
148
- return compilationContext.schema.getPossibleTypes(type).reduce(
149
- (res, t) => {
150
- const property = transformNode(compilationContext, fieldNodes, t);
151
- if (property != null) {
152
- res.children = merge(res.children, property.children);
153
- }
154
- return res;
155
- },
156
- {
157
- isNullable: true,
158
- children: {}
159
- }
160
- );
161
- }
162
- return null;
163
- }
164
- export {
165
- createNullTrimmer
166
- };
167
- //# sourceMappingURL=non-null.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/non-null.ts"],"sourcesContent":["import {\n type ExecutionResult,\n type FieldNode,\n type GraphQLError,\n type GraphQLType,\n isListType,\n isNonNullType,\n isObjectType,\n isAbstractType\n} from \"graphql\";\nimport merge from \"lodash.merge\";\nimport { collectFields, collectSubfields, resolveFieldDef } from \"./ast.js\";\nimport { getOperationRootType } from \"./compat.js\";\nimport { type CompilationContext } from \"./execution.js\";\n\ninterface QueryMetadata {\n isNullable: boolean;\n children: { [key: string]: QueryMetadata };\n}\n\nexport type NullTrimmer = (data: any, errors: GraphQLError[]) => any;\n\n/**\n *\n * @param {CompilationContext} compilationContext\n * @returns {(data: any, errors: GraphQLError[]) => {data: any; errors: GraphQLError[]}}\n */\nexport function createNullTrimmer(\n compilationContext: CompilationContext\n): NullTrimmer {\n return trimData(parseQueryNullables(compilationContext));\n}\n\n/**\n * Trims a data response according to the field errors in non null fields.\n *\n * Errors are filtered to ensure a single field error per field.\n *\n * @param {QueryMetadata} nullable Description of the query and their nullability\n * @returns {(data: any, errors: GraphQLError[]) => {data: any; errors: GraphQLError[]}}\n * the trimmed data and a filtered list of errors.\n */\nfunction trimData(nullable: QueryMetadata): NullTrimmer {\n return (data: any, errors: GraphQLError[]): ExecutionResult => {\n const finalErrors = [];\n const processedErrors = new Set<string>();\n for (const error of errors) {\n if (!error.path) {\n // should never happen, it is a bug if it does\n throw new Error(\"no path available for tree trimming\");\n }\n if (processedErrors.has(error.path.join(\".\"))) {\n // there can be multiple field errors in some scenario\n // there is no need to continue processing and it should not be part of the final response\n continue;\n }\n const ancestors = findNullableAncestor(nullable, error.path);\n // The top level field is always nullable\n // http://facebook.github.io/graphql/June2018/#sec-Errors-and-Non-Nullability\n //\n // There is no mention if the following errors need to be present in the response.\n // For now we assume this is not needed.\n if (ancestors.length === 0) {\n data = null;\n finalErrors.push(error);\n break;\n }\n removeBranch(data, ancestors);\n processedErrors.add(error.path.join(\".\"));\n finalErrors.push(error);\n }\n return { data, errors: finalErrors };\n };\n}\n\n/**\n * Removes a branch out of the response data by mutating the original object.\n *\n * @param tree response data\n * @param {Array<number | string>} branch array with the path that should be trimmed\n */\nfunction removeBranch(tree: any, branch: Array<number | string>): void {\n for (let i = 0; i < branch.length - 1; ++i) {\n // if ancestor has already been removed, there's nothing to do\n if (tree[branch[i]] === null) {\n return;\n }\n tree = tree[branch[i]];\n }\n const toNull = branch[branch.length - 1];\n tree[toNull] = null;\n}\n\n/**\n * Name of the child used in array to contain the description.\n *\n * Only used for list to contain the child description.\n */\nconst ARRAY_CHILD_NAME = \"index\";\n\n/**\n *\n * @param {QueryMetadata} nullable Description of the query and their nullability\n * @param {ReadonlyArray<string | number>} paths path of the error location\n * @returns {Array<string | number>} path of the branch to be made null\n */\nfunction findNullableAncestor(\n nullable: QueryMetadata,\n paths: ReadonlyArray<string | number>\n): Array<string | number> {\n let lastNullable = 0;\n for (let i = 0; i < paths.length; ++i) {\n const path = paths[i];\n const child =\n nullable.children[typeof path === \"string\" ? path : ARRAY_CHILD_NAME];\n if (!child) {\n // Stopping the search since we reached a leaf node,\n // the loop should be on its final iteration\n break;\n }\n if (child.isNullable) {\n lastNullable = i + 1;\n }\n nullable = child;\n }\n return paths.slice(0, lastNullable);\n}\n\n/**\n * Produce a description of the query regarding its nullability.\n *\n * Leaf nodes are not present in this representation since they are not\n * interesting for removing branches of the response tree.\n *\n * The structure is recursive like the query.\n * @param {CompilationContext} compilationContext Execution content\n * @returns {QueryMetadata} description of the query\n */\nfunction parseQueryNullables(\n compilationContext: CompilationContext\n): QueryMetadata {\n const type = getOperationRootType(\n compilationContext.schema,\n compilationContext.operation\n );\n const fields = collectFields(\n compilationContext,\n type,\n compilationContext.operation.selectionSet,\n Object.create(null),\n Object.create(null)\n );\n const properties = Object.create(null);\n for (const responseName of Object.keys(fields)) {\n const fieldType = resolveFieldDef(\n compilationContext,\n type,\n fields[responseName]\n );\n if (!fieldType) {\n // if field does not exist, it should be ignored for compatibility concerns.\n // Usually, validation would stop it before getting here but this could be an old query\n continue;\n }\n const property = transformNode(\n compilationContext,\n fields[responseName],\n fieldType.type\n );\n if (property != null) {\n properties[responseName] = property;\n }\n }\n return {\n isNullable: true,\n children: properties\n };\n}\n\n/**\n * Processes a single node to produce a description of itself and its children.\n *\n * Leaf nodes are ignore and removed from the description\n * @param {CompilationContext} compilationContext\n * @param {FieldNode[]} fieldNodes list of fields\n * @param {GraphQLType} type Current type being processed.\n * @returns {QueryMetadata | null} null if node is a leaf, otherwise a description of the node and its children.\n */\nfunction transformNode(\n compilationContext: CompilationContext,\n fieldNodes: FieldNode[],\n type: GraphQLType\n): QueryMetadata | null {\n if (isNonNullType(type)) {\n const nullable = transformNode(compilationContext, fieldNodes, type.ofType);\n if (nullable != null) {\n nullable.isNullable = false;\n return nullable;\n }\n return null;\n }\n if (isObjectType(type)) {\n const subfields = collectSubfields(compilationContext, type, fieldNodes);\n const properties = Object.create(null);\n for (const responseName of Object.keys(subfields)) {\n const fieldType = resolveFieldDef(\n compilationContext,\n type,\n subfields[responseName]\n );\n if (!fieldType) {\n // if field does not exist, it should be ignored for compatibility concerns.\n // Usually, validation would stop it before getting here but this could be an old query\n continue;\n }\n const property = transformNode(\n compilationContext,\n subfields[responseName],\n fieldType.type\n );\n if (property != null) {\n properties[responseName] = property;\n }\n }\n return {\n isNullable: true,\n children: properties\n };\n }\n if (isListType(type)) {\n const child = transformNode(compilationContext, fieldNodes, type.ofType);\n if (child != null) {\n return {\n isNullable: true,\n children: { [ARRAY_CHILD_NAME]: child }\n };\n }\n\n return {\n isNullable: true,\n children: {}\n };\n }\n if (isAbstractType(type)) {\n return compilationContext.schema.getPossibleTypes(type).reduce(\n (res, t) => {\n const property = transformNode(compilationContext, fieldNodes, t);\n if (property != null) {\n // We do a deep merge because children can have subset of properties\n // TODO: Possible bug: two object with different nullability on objects.\n res.children = merge(res.children, property.children);\n }\n return res;\n },\n {\n isNullable: true,\n children: {}\n }\n );\n }\n\n // Scalars and enum are ignored since they are leaf values\n return null;\n}\n"],"mappings":"AAAA;AAAA,EAKE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,OAAO,WAAW;AAClB,SAAS,eAAe,kBAAkB,uBAAuB;AACjE,SAAS,4BAA4B;AAe9B,SAAS,kBACd,oBACa;AACb,SAAO,SAAS,oBAAoB,kBAAkB,CAAC;AACzD;AAWA,SAAS,SAAS,UAAsC;AACtD,SAAO,CAAC,MAAW,WAA4C;AAC7D,UAAM,cAAc,CAAC;AACrB,UAAM,kBAAkB,oBAAI,IAAY;AACxC,eAAW,SAAS,QAAQ;AAC1B,UAAI,CAAC,MAAM,MAAM;AAEf,cAAM,IAAI,MAAM,qCAAqC;AAAA,MACvD;AACA,UAAI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jB,aAAO;AAAA,QACL,YAAY;AAAA,QACZ,UAAU,EAAE,CAAC,gBAAgB,GAAG,MAAM;AAAA,MACxC;AAAA,IACF;AAEA,WAAO;AAAA,MACL,YAAY;AAAA,MACZ,UAAU,CAAC;AAAA,IACb;AAAA,EACF;AACA,MAAI,eAAe,IAAI,GAAG;AACxB,WAAO,mBAAmB,OAAO,iBAAiB,IAAI,EAAE;AAAA,MACtD,CAAC,KAAK,MAAM;AACV,cAAM,WAAW,cAAc,oBAAoB,YAAY,CAAC;AAChE,YAAI,YAAY,MAAM;AAGpB,cAAI,WAAW,MAAM,IAAI,UAAU,SAAS,QAAQ;AAAA,QACtD;AACA,eAAO;AAAA,MACT;AAAA,MACA;AAAA,QACE,YAAY;AAAA,QACZ,UAAU,CAAC;AAAA,MACb;AAAA,IACF;AAAA,EACF;AAGA,SAAO;AACT;","names":[]}
@@ -1,245 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
- var resolve_info_exports = {};
30
- __export(resolve_info_exports, {
31
- createResolveInfoThunk: () => createResolveInfoThunk,
32
- fieldExpansionEnricher: () => fieldExpansionEnricher,
33
- isLeafField: () => isLeafField
34
- });
35
- module.exports = __toCommonJS(resolve_info_exports);
36
- var import_generate = require("./generate");
37
- var import_graphql = require("graphql");
38
- var import_lodash = __toESM(require("lodash.memoize"));
39
- var import_lodash2 = __toESM(require("lodash.mergewith"));
40
- var import_memoize = require("./memoize.js");
41
- const LeafFieldSymbol = Symbol("LeafFieldSymbol");
42
- function createLeafField(props) {
43
- return {
44
- [LeafFieldSymbol]: true,
45
- ...props
46
- };
47
- }
48
- function isLeafField(obj) {
49
- return obj != null && Object.prototype.hasOwnProperty.call(obj, LeafFieldSymbol);
50
- }
51
- function createResolveInfoThunk({
52
- schema,
53
- fragments,
54
- operation,
55
- parentType,
56
- fieldName,
57
- fieldType,
58
- fieldNodes
59
- }, enricher) {
60
- let enrichedInfo = {};
61
- if (typeof enricher === "function") {
62
- enrichedInfo = enricher({
63
- fieldName,
64
- fieldNodes,
65
- returnType: fieldType,
66
- parentType,
67
- schema,
68
- fragments,
69
- operation
70
- }) || {};
71
- if (typeof enrichedInfo !== "object" || Array.isArray(enrichedInfo)) {
72
- enrichedInfo = {};
73
- }
74
- }
75
- const gen = (0, import_generate.genFn)();
76
- gen(`return function getGraphQLResolveInfo(rootValue, variableValues, path) {
77
- return {
78
- fieldName,
79
- fieldNodes,
80
- returnType: fieldType,
81
- parentType,
82
- path,
83
- schema,
84
- fragments,
85
- rootValue,
86
- operation,
87
- variableValues,`);
88
- Object.keys(enrichedInfo).forEach((key) => {
89
- gen(`${key}: enrichedInfo["${key}"],
90
- `);
91
- });
92
- gen(`};};`);
93
- return new Function(
94
- "fieldName",
95
- "fieldNodes",
96
- "fieldType",
97
- "parentType",
98
- "schema",
99
- "fragments",
100
- "operation",
101
- "enrichedInfo",
102
- gen.toString()
103
- ).call(
104
- null,
105
- fieldName,
106
- fieldNodes,
107
- fieldType,
108
- parentType,
109
- schema,
110
- fragments,
111
- operation,
112
- enrichedInfo
113
- );
114
- }
115
- function fieldExpansionEnricher(input) {
116
- const { schema, fragments, returnType, fieldNodes } = input;
117
- const fieldExpansion = {};
118
- for (const fieldNode of fieldNodes) {
119
- deepMerge(
120
- fieldExpansion,
121
- memoizedExpandFieldNode(schema, fragments, fieldNode, returnType)
122
- );
123
- }
124
- return {
125
- fieldExpansion
126
- };
127
- }
128
- const MEMOIZATION = true;
129
- const memoizedGetReturnType = MEMOIZATION ? (0, import_memoize.memoize2)(getReturnType) : getReturnType;
130
- const memoizedHasField = MEMOIZATION ? (0, import_memoize.memoize2)(hasField) : hasField;
131
- const memoizedResolveEndType = MEMOIZATION ? (0, import_lodash.default)(resolveEndType) : resolveEndType;
132
- const memoizedGetPossibleTypes = MEMOIZATION ? (0, import_memoize.memoize2)(getPossibleTypes) : getPossibleTypes;
133
- const memoizedExpandFieldNodeType = MEMOIZATION ? (0, import_memoize.memoize4)(expandFieldNodeType) : expandFieldNodeType;
134
- const memoizedExpandFieldNode = MEMOIZATION ? (0, import_memoize.memoize4)(expandFieldNode) : expandFieldNode;
135
- function expandFieldNode(schema, fragments, node, fieldType) {
136
- if (node.selectionSet == null) {
137
- return createLeafField({});
138
- }
139
- const typ = memoizedResolveEndType(fieldType);
140
- const possibleTypes = memoizedGetPossibleTypes(schema, typ);
141
- const fieldExpansion = {};
142
- for (const possibleType of possibleTypes) {
143
- if (!(0, import_graphql.isUnionType)(possibleType)) {
144
- fieldExpansion[possibleType.name] = memoizedExpandFieldNodeType(
145
- schema,
146
- fragments,
147
- possibleType,
148
- node.selectionSet
149
- );
150
- }
151
- }
152
- return fieldExpansion;
153
- }
154
- function expandFieldNodeType(schema, fragments, parentType, selectionSet) {
155
- const typeExpansion = {};
156
- for (const selection of selectionSet.selections) {
157
- if (selection.kind === import_graphql.Kind.FIELD) {
158
- if (!(0, import_graphql.isUnionType)(parentType) && memoizedHasField(parentType, selection.name.value)) {
159
- typeExpansion[selection.name.value] = memoizedExpandFieldNode(
160
- schema,
161
- fragments,
162
- selection,
163
- memoizedGetReturnType(parentType, selection.name.value)
164
- );
165
- }
166
- } else {
167
- const selectionSet2 = selection.kind === import_graphql.Kind.INLINE_FRAGMENT ? selection.selectionSet : fragments[selection.name.value].selectionSet;
168
- const nextType = selection.kind === import_graphql.Kind.INLINE_FRAGMENT ? selection.typeCondition ? schema.getType(
169
- selection.typeCondition.name.value
170
- ) : parentType : schema.getType(
171
- fragments[selection.name.value].typeCondition.name.value
172
- );
173
- if (nextType === parentType || (0, import_graphql.isAbstractType)(nextType)) {
174
- deepMerge(
175
- typeExpansion,
176
- memoizedExpandFieldNodeType(
177
- schema,
178
- fragments,
179
- parentType,
180
- selectionSet2
181
- )
182
- );
183
- }
184
- }
185
- }
186
- return typeExpansion;
187
- }
188
- function getPossibleTypes(schema, compositeType) {
189
- if ((0, import_graphql.isObjectType)(compositeType)) {
190
- return [compositeType];
191
- }
192
- const possibleTypes = [];
193
- const types = schema.getTypeMap();
194
- for (const typeName in types) {
195
- if (Object.prototype.hasOwnProperty.call(types, typeName)) {
196
- const typ = types[typeName];
197
- if ((0, import_graphql.isCompositeType)(typ) && (0, import_graphql.doTypesOverlap)(schema, typ, compositeType)) {
198
- possibleTypes.push(typ);
199
- }
200
- }
201
- }
202
- return possibleTypes;
203
- }
204
- function getReturnType(parentType, fieldName) {
205
- const fields = parentType.getFields();
206
- if (!Object.prototype.hasOwnProperty.call(fields, fieldName)) {
207
- throw new import_graphql.GraphQLError(
208
- `Field "${fieldName}" does not exist in "${parentType.name}"`
209
- );
210
- }
211
- const outputType = fields[fieldName].type;
212
- return memoizedResolveEndType(outputType);
213
- }
214
- function resolveEndType(typ) {
215
- if ((0, import_graphql.isListType)(typ) || (0, import_graphql.isNonNullType)(typ)) {
216
- return memoizedResolveEndType(typ.ofType);
217
- }
218
- return typ;
219
- }
220
- function hasField(typ, fieldName) {
221
- return Object.prototype.hasOwnProperty.call(typ.getFields(), fieldName);
222
- }
223
- function deepMerge(obj, src) {
224
- (0, import_lodash2.default)(obj, src, (objValue, srcValue) => {
225
- if (isLeafField(objValue)) {
226
- if (isLeafField(srcValue)) {
227
- return {
228
- ...objValue,
229
- ...srcValue
230
- };
231
- }
232
- return objValue;
233
- } else if (isLeafField(srcValue)) {
234
- return srcValue;
235
- }
236
- return void 0;
237
- });
238
- }
239
- // Annotate the CommonJS export names for ESM import in node:
240
- 0 && (module.exports = {
241
- createResolveInfoThunk,
242
- fieldExpansionEnricher,
243
- isLeafField
244
- });
245
- //# sourceMappingURL=resolve-info.js.map