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/README.md CHANGED
@@ -123,6 +123,31 @@ Compiles the `document` AST, using an optional operationName and compiler option
123
123
  - `customSerializers` {Object as Map, default: {}} - Replace serializer functions for specific types. Can be used as a safer alternative
124
124
  for overly expensive serializers
125
125
  - `customJSONSerializer` {boolean, default: false} - Whether to produce also a JSON serializer function using `fast-json-stringify`. The default stringifier function is `JSON.stringify`
126
+ - `debug` {object, optional} - Publishes formatted generated executors as virtual JavaScript sources. This is intended for local development.
127
+ - `enabled` {boolean, required} - Enables all debug-only work. Set this to `false` to skip formatting and generated-source changes.
128
+ - `querySourceName` {string, optional} - A stable name for the generated query source, such as `graphql-jit://graphql-jit/my-service/GetProduct.query.js`.
129
+ - `variablesSourceName` {string, optional} - A stable name for the generated variable-coercion source, such as `graphql-jit://graphql-jit/my-service/GetProduct.variables.js`.
130
+ - `formatSourceCode` {(source: string) => string, optional} - A synchronous formatter that runs before compilation. e.g. `@prettier/sync`.
131
+
132
+ ### Debugging generated executors
133
+
134
+ Start Node with `--inspect` and enable `debug` for the operation being investigated:
135
+
136
+ ```js
137
+ const { format } = require("@prettier/sync");
138
+
139
+ const compiledQuery = compileQuery(schema, document, "GetProduct", {
140
+ debug: {
141
+ enabled: true,
142
+ querySourceName: "graphql-jit://graphql-jit/shop/GetProduct.query.js",
143
+ variablesSourceName:
144
+ "graphql-jit://graphql-jit/shop/GetProduct.variables.js",
145
+ formatSourceCode: (source) => format(source, { parser: "babel" })
146
+ }
147
+ });
148
+ ```
149
+
150
+ The debugger exposes separate query and variable-coercion scripts. Set breakpoints directly in those generated JavaScript sources.
126
151
 
127
152
  #### compiledQuery.query(root: any, context: any, variables: Maybe<{ [key: string]: any }>)
128
153
 
@@ -0,0 +1,89 @@
1
+ import { type ArgumentNode, type ASTNode, type DirectiveNode, type FieldNode, type GraphQLArgument, GraphQLDirective, type GraphQLField, type GraphQLInputType, GraphQLObjectType, type SelectionSetNode, type SourceLocation, type ValueNode, type VariableNode } from "graphql";
2
+ import { type CompilationContext } from "./execution.js";
3
+ import { resolveFieldDef } from "./compat.js";
4
+ export interface JitFieldNode extends FieldNode {
5
+ /**
6
+ * @deprecated Use __internalShouldIncludePath instead
7
+ * @see __internalShouldIncludePath
8
+ */
9
+ __internalShouldInclude?: string[];
10
+ __internalShouldIncludePath?: {
11
+ [path: string]: string[];
12
+ };
13
+ }
14
+ export interface FieldsAndNodes {
15
+ [key: string]: JitFieldNode[];
16
+ }
17
+ /**
18
+ * Given a selectionSet, adds all of the fields in that selection to
19
+ * the passed in map of fields, and returns it at the end.
20
+ *
21
+ * CollectFields requires the "runtime type" of an object. For a field which
22
+ * returns an Interface or Union type, the "runtime type" will be the actual
23
+ * Object type returned by that field.
24
+ */
25
+ export declare function collectFields(compilationContext: CompilationContext, runtimeType: GraphQLObjectType, selectionSet: SelectionSetNode, fields: FieldsAndNodes, visitedFragmentNames: {
26
+ [key: string]: boolean;
27
+ }, parentResponsePath?: ObjectPath): FieldsAndNodes;
28
+ export { resolveFieldDef };
29
+ export declare function collectSubfields(compilationContext: CompilationContext, returnType: GraphQLObjectType, fieldNodes: FieldNode[], parentResponsePath?: ObjectPath): {
30
+ [key: string]: FieldNode[];
31
+ };
32
+ type ResponsePathType = "variable" | "literal" | "meta";
33
+ export interface ObjectPath {
34
+ prev: ObjectPath | undefined;
35
+ key: string;
36
+ type: ResponsePathType;
37
+ }
38
+ interface MissingVariablePath {
39
+ valueNode: VariableNode;
40
+ path?: ObjectPath;
41
+ argument?: {
42
+ definition: GraphQLArgument;
43
+ node: ArgumentNode;
44
+ };
45
+ }
46
+ export interface Arguments {
47
+ values: {
48
+ [argument: string]: any;
49
+ };
50
+ missing: MissingVariablePath[];
51
+ }
52
+ /**
53
+ * Prepares an object map of argument values given a list of argument
54
+ * definitions and list of argument AST nodes.
55
+ *
56
+ * Note: The returned value is a plain Object with a prototype, since it is
57
+ * exposed to user code. Care should be taken to not pull values from the
58
+ * Object prototype.
59
+ */
60
+ export declare function getArgumentDefs(def: GraphQLField<any, any> | GraphQLDirective, node: FieldNode | DirectiveNode): Arguments;
61
+ interface ASTValueWithVariables {
62
+ value: object | string | boolean | symbol | number | null | any[];
63
+ variables: MissingVariablePath[];
64
+ }
65
+ interface ASTValue {
66
+ value: object | string | boolean | symbol | number | null | any[];
67
+ }
68
+ export declare function valueFromAST(valueNode: ValueNode, type: GraphQLInputType): undefined | ASTValue | ASTValueWithVariables;
69
+ export declare function computeLocations(nodes: ASTNode[]): SourceLocation[];
70
+ export declare function addPath(responsePath: ObjectPath | undefined, key: string, type?: ResponsePathType): ObjectPath;
71
+ export declare function flattenPath(path: ObjectPath): Array<{
72
+ key: string;
73
+ type: ResponsePathType;
74
+ }>;
75
+ /**
76
+ * Serialize a path for use in the skip/include directives.
77
+ *
78
+ * @param path The path to serialize
79
+ * @returns The path serialized as a string, with the root path first.
80
+ */
81
+ export declare function serializeObjectPathForSkipInclude(path: ObjectPath | undefined): string;
82
+ /**
83
+ * join two path segments to a dot notation, handling empty strings
84
+ *
85
+ * @param a path segment
86
+ * @param b path segment
87
+ * @returns combined path in dot notation
88
+ */
89
+ export declare function joinSkipIncludePath(a: string, b: string): string;