@grafema/api 0.2.5-beta

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 (70) hide show
  1. package/LICENSE +190 -0
  2. package/README.md +219 -0
  3. package/dist/context.d.ts +22 -0
  4. package/dist/context.d.ts.map +1 -0
  5. package/dist/context.js +18 -0
  6. package/dist/context.js.map +1 -0
  7. package/dist/dataloaders/index.d.ts +18 -0
  8. package/dist/dataloaders/index.d.ts.map +1 -0
  9. package/dist/dataloaders/index.js +17 -0
  10. package/dist/dataloaders/index.js.map +1 -0
  11. package/dist/dataloaders/nodeLoader.d.ts +19 -0
  12. package/dist/dataloaders/nodeLoader.d.ts.map +1 -0
  13. package/dist/dataloaders/nodeLoader.js +31 -0
  14. package/dist/dataloaders/nodeLoader.js.map +1 -0
  15. package/dist/index.d.ts +11 -0
  16. package/dist/index.d.ts.map +1 -0
  17. package/dist/index.js +9 -0
  18. package/dist/index.js.map +1 -0
  19. package/dist/pagination.d.ts +50 -0
  20. package/dist/pagination.d.ts.map +1 -0
  21. package/dist/pagination.js +71 -0
  22. package/dist/pagination.js.map +1 -0
  23. package/dist/resolvers/edge.d.ts +22 -0
  24. package/dist/resolvers/edge.d.ts.map +1 -0
  25. package/dist/resolvers/edge.js +36 -0
  26. package/dist/resolvers/edge.js.map +1 -0
  27. package/dist/resolvers/index.d.ts +159 -0
  28. package/dist/resolvers/index.d.ts.map +1 -0
  29. package/dist/resolvers/index.js +21 -0
  30. package/dist/resolvers/index.js.map +1 -0
  31. package/dist/resolvers/mutation.d.ts +69 -0
  32. package/dist/resolvers/mutation.d.ts.map +1 -0
  33. package/dist/resolvers/mutation.js +82 -0
  34. package/dist/resolvers/mutation.js.map +1 -0
  35. package/dist/resolvers/node.d.ts +50 -0
  36. package/dist/resolvers/node.d.ts.map +1 -0
  37. package/dist/resolvers/node.js +69 -0
  38. package/dist/resolvers/node.js.map +1 -0
  39. package/dist/resolvers/query.d.ts +169 -0
  40. package/dist/resolvers/query.d.ts.map +1 -0
  41. package/dist/resolvers/query.js +188 -0
  42. package/dist/resolvers/query.js.map +1 -0
  43. package/dist/schema/enums.graphql +27 -0
  44. package/dist/schema/mutations.graphql +53 -0
  45. package/dist/schema/queries.graphql +213 -0
  46. package/dist/schema/scalars.graphql +2 -0
  47. package/dist/schema/subscriptions.graphql +84 -0
  48. package/dist/schema/types.graphql +440 -0
  49. package/dist/server.d.ts +31 -0
  50. package/dist/server.d.ts.map +1 -0
  51. package/dist/server.js +109 -0
  52. package/dist/server.js.map +1 -0
  53. package/package.json +51 -0
  54. package/src/context.ts +33 -0
  55. package/src/dataloaders/index.ts +24 -0
  56. package/src/dataloaders/nodeLoader.ts +41 -0
  57. package/src/index.ts +11 -0
  58. package/src/pagination.ts +109 -0
  59. package/src/resolvers/edge.ts +39 -0
  60. package/src/resolvers/index.ts +24 -0
  61. package/src/resolvers/mutation.ts +108 -0
  62. package/src/resolvers/node.ts +118 -0
  63. package/src/resolvers/query.ts +307 -0
  64. package/src/schema/enums.graphql +27 -0
  65. package/src/schema/mutations.graphql +53 -0
  66. package/src/schema/queries.graphql +213 -0
  67. package/src/schema/scalars.graphql +2 -0
  68. package/src/schema/subscriptions.graphql +84 -0
  69. package/src/schema/types.graphql +440 -0
  70. package/src/server.ts +140 -0
package/LICENSE ADDED
@@ -0,0 +1,190 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to the Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ Copyright 2026 Vadim Reshetnikov
179
+
180
+ Licensed under the Apache License, Version 2.0 (the "License");
181
+ you may not use this file except in compliance with the License.
182
+ You may obtain a copy of the License at
183
+
184
+ http://www.apache.org/licenses/LICENSE-2.0
185
+
186
+ Unless required by applicable law or agreed to in writing, software
187
+ distributed under the License is distributed on an "AS IS" BASIS,
188
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
189
+ See the License for the specific language governing permissions and
190
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,219 @@
1
+ # @grafema/api
2
+
3
+ GraphQL API server for Grafema code analysis toolkit.
4
+
5
+ ## Overview
6
+
7
+ This package provides a GraphQL endpoint on top of Grafema's graph database. It enables external tools, IDE extensions, and AI agents to query the code graph through a standard, self-documenting protocol.
8
+
9
+ **Key features:**
10
+ - Cursor-based pagination (Relay Connection spec)
11
+ - DataLoader pattern for N+1 query prevention
12
+ - GraphiQL IDE for interactive exploration
13
+ - Datalog query passthrough for advanced use cases
14
+
15
+ ## Prerequisites
16
+
17
+ - RFDB server must be running (`grafema server start`)
18
+ - Project must be analyzed (`grafema analyze`)
19
+
20
+ ## Usage
21
+
22
+ ### Via CLI
23
+
24
+ ```bash
25
+ # Start GraphQL server (requires RFDB server running)
26
+ grafema server graphql --port 4000
27
+
28
+ # GraphiQL IDE available at http://localhost:4000/graphql
29
+ ```
30
+
31
+ ### Programmatic
32
+
33
+ ```typescript
34
+ import { createGraphQLServer, startServer } from '@grafema/api';
35
+ import { RFDBServerBackend } from '@grafema/core';
36
+
37
+ // Connect to RFDB
38
+ const backend = new RFDBServerBackend({ socketPath: '/tmp/grafema.sock' });
39
+ await backend.connect();
40
+
41
+ // Start server
42
+ const server = startServer({
43
+ backend,
44
+ port: 4000,
45
+ hostname: 'localhost',
46
+ });
47
+ ```
48
+
49
+ ## GraphQL Schema
50
+
51
+ ### Queries
52
+
53
+ #### Node Lookups
54
+
55
+ ```graphql
56
+ # Get single node by ID
57
+ node(id: ID!): Node
58
+
59
+ # Find nodes with filtering and pagination
60
+ nodes(filter: NodeFilter, first: Int, after: String): NodeConnection!
61
+ ```
62
+
63
+ #### Graph Traversal
64
+
65
+ ```graphql
66
+ # BFS/DFS traversal
67
+ bfs(startIds: [ID!]!, maxDepth: Int!, edgeTypes: [String!]!): [ID!]!
68
+ dfs(startIds: [ID!]!, maxDepth: Int!, edgeTypes: [String!]): [ID!]!
69
+
70
+ # Check if path exists between nodes
71
+ reachability(from: ID!, to: ID!, edgeTypes: [String!], maxDepth: Int): Boolean!
72
+ ```
73
+
74
+ #### Datalog Queries
75
+
76
+ ```graphql
77
+ # Execute Datalog query
78
+ datalog(query: String!, limit: Int, offset: Int): DatalogResult!
79
+ ```
80
+
81
+ #### High-Level Queries
82
+
83
+ ```graphql
84
+ findCalls(target: String!, className: String, limit: Int): [CallInfo!]!
85
+ getFunctionDetails(name: String!, file: String): FunctionDetails
86
+ findGuards(nodeId: ID!): [GuardInfo!]!
87
+ traceAlias(variableName: String!, file: String!): [Node!]!
88
+ traceDataFlow(source: String!, direction: TraversalDirection): [[String!]!]!
89
+ ```
90
+
91
+ #### Statistics
92
+
93
+ ```graphql
94
+ stats: GraphStats!
95
+ analysisStatus: AnalysisStatus!
96
+ ```
97
+
98
+ ### Mutations
99
+
100
+ ```graphql
101
+ # Run analysis
102
+ analyzeProject(service: String, force: Boolean): AnalysisResult!
103
+
104
+ # Guarantee management
105
+ checkGuarantees(names: [String!]): GuaranteeCheckResult!
106
+ checkInvariant(rule: String!, description: String): GuaranteeResult!
107
+ ```
108
+
109
+ ## Example Queries
110
+
111
+ ### Get all functions
112
+
113
+ ```graphql
114
+ query {
115
+ nodes(filter: { type: "FUNCTION" }, first: 10) {
116
+ edges {
117
+ node {
118
+ id
119
+ name
120
+ file
121
+ line
122
+ }
123
+ }
124
+ pageInfo {
125
+ hasNextPage
126
+ endCursor
127
+ }
128
+ totalCount
129
+ }
130
+ }
131
+ ```
132
+
133
+ ### Find async functions using Datalog
134
+
135
+ ```graphql
136
+ query {
137
+ datalog(query: """
138
+ violation(X) :-
139
+ node(X, "FUNCTION"),
140
+ attr(X, "async", true).
141
+ """) {
142
+ count
143
+ results {
144
+ node {
145
+ name
146
+ file
147
+ }
148
+ }
149
+ }
150
+ }
151
+ ```
152
+
153
+ ### Check reachability
154
+
155
+ ```graphql
156
+ query {
157
+ reachability(
158
+ from: "MODULE:src/index.ts"
159
+ to: "FUNCTION:src/utils.ts->helper"
160
+ edgeTypes: ["CALLS", "IMPORTS"]
161
+ maxDepth: 5
162
+ )
163
+ }
164
+ ```
165
+
166
+ ### Get graph statistics
167
+
168
+ ```graphql
169
+ query {
170
+ stats {
171
+ nodeCount
172
+ edgeCount
173
+ nodesByType
174
+ }
175
+ }
176
+ ```
177
+
178
+ ## Pagination
179
+
180
+ All collection queries use cursor-based pagination following the Relay Connection spec:
181
+
182
+ ```graphql
183
+ query {
184
+ nodes(filter: { type: "CALL" }, first: 20, after: "Y3Vyc29yOm5vZGUtMTA=") {
185
+ edges {
186
+ node { id name }
187
+ cursor
188
+ }
189
+ pageInfo {
190
+ hasNextPage
191
+ hasPreviousPage
192
+ startCursor
193
+ endCursor
194
+ }
195
+ totalCount
196
+ }
197
+ }
198
+ ```
199
+
200
+ **Limits:**
201
+ - Default: 50 items
202
+ - Maximum: 250 items per request
203
+
204
+ ## Configuration
205
+
206
+ ```typescript
207
+ interface GraphQLServerOptions {
208
+ backend: RFDBServerBackend; // Required: graph backend
209
+ port?: number; // Default: 4000
210
+ hostname?: string; // Default: 'localhost'
211
+ maxDepth?: number; // Default: 10 (query depth limit)
212
+ maxComplexity?: number; // Default: 1000 (query cost limit)
213
+ timeout?: number; // Default: 30000ms
214
+ }
215
+ ```
216
+
217
+ ## License
218
+
219
+ Apache-2.0
@@ -0,0 +1,22 @@
1
+ /**
2
+ * GraphQL Context
3
+ *
4
+ * Request-scoped context containing backend connection and DataLoaders.
5
+ */
6
+ import type { IncomingMessage } from 'node:http';
7
+ import type { RFDBServerBackend } from '@grafema/core';
8
+ import { type DataLoaders } from './dataloaders/index.js';
9
+ export interface GraphQLContext {
10
+ /** Graph backend connection */
11
+ backend: RFDBServerBackend;
12
+ /** DataLoaders for batching (per-request) */
13
+ loaders: DataLoaders;
14
+ /** Request start time for timeout tracking */
15
+ startTime: number;
16
+ }
17
+ /**
18
+ * Create context for a GraphQL request.
19
+ * Creates fresh DataLoaders to ensure no cross-request caching.
20
+ */
21
+ export declare function createContext(backend: RFDBServerBackend, _req: IncomingMessage): GraphQLContext;
22
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AACjD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAqB,KAAK,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE7E,MAAM,WAAW,cAAc;IAC7B,+BAA+B;IAC/B,OAAO,EAAE,iBAAiB,CAAC;IAC3B,6CAA6C;IAC7C,OAAO,EAAE,WAAW,CAAC;IACrB,8CAA8C;IAC9C,SAAS,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAC3B,OAAO,EAAE,iBAAiB,EAC1B,IAAI,EAAE,eAAe,GACpB,cAAc,CAMhB"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * GraphQL Context
3
+ *
4
+ * Request-scoped context containing backend connection and DataLoaders.
5
+ */
6
+ import { createDataLoaders } from './dataloaders/index.js';
7
+ /**
8
+ * Create context for a GraphQL request.
9
+ * Creates fresh DataLoaders to ensure no cross-request caching.
10
+ */
11
+ export function createContext(backend, _req) {
12
+ return {
13
+ backend,
14
+ loaders: createDataLoaders(backend),
15
+ startTime: Date.now(),
16
+ };
17
+ }
18
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,EAAE,iBAAiB,EAAoB,MAAM,wBAAwB,CAAC;AAW7E;;;GAGG;AACH,MAAM,UAAU,aAAa,CAC3B,OAA0B,EAC1B,IAAqB;IAErB,OAAO;QACL,OAAO;QACP,OAAO,EAAE,iBAAiB,CAAC,OAAO,CAAC;QACnC,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;KACtB,CAAC;AACJ,CAAC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * DataLoader Factory
3
+ *
4
+ * Creates all DataLoaders for a request context.
5
+ * DataLoaders batch and cache database requests within a single GraphQL request.
6
+ */
7
+ import type { RFDBServerBackend } from '@grafema/core';
8
+ import { createNodeLoader } from './nodeLoader.js';
9
+ export interface DataLoaders {
10
+ /** Batch node lookups by ID */
11
+ node: ReturnType<typeof createNodeLoader>;
12
+ }
13
+ /**
14
+ * Create all DataLoaders for a request.
15
+ * DataLoaders are per-request to prevent cross-request caching issues.
16
+ */
17
+ export declare function createDataLoaders(backend: RFDBServerBackend): DataLoaders;
18
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/dataloaders/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,MAAM,WAAW,WAAW;IAC1B,+BAA+B;IAC/B,IAAI,EAAE,UAAU,CAAC,OAAO,gBAAgB,CAAC,CAAC;CAC3C;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,iBAAiB,GAAG,WAAW,CAIzE"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * DataLoader Factory
3
+ *
4
+ * Creates all DataLoaders for a request context.
5
+ * DataLoaders batch and cache database requests within a single GraphQL request.
6
+ */
7
+ import { createNodeLoader } from './nodeLoader.js';
8
+ /**
9
+ * Create all DataLoaders for a request.
10
+ * DataLoaders are per-request to prevent cross-request caching issues.
11
+ */
12
+ export function createDataLoaders(backend) {
13
+ return {
14
+ node: createNodeLoader(backend),
15
+ };
16
+ }
17
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/dataloaders/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAOnD;;;GAGG;AACH,MAAM,UAAU,iBAAiB,CAAC,OAA0B;IAC1D,OAAO;QACL,IAAI,EAAE,gBAAgB,CAAC,OAAO,CAAC;KAChC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Node DataLoader
3
+ *
4
+ * Batches multiple getNode() calls into efficient parallel lookups.
5
+ * Critical for preventing N+1 queries in GraphQL.
6
+ */
7
+ import DataLoader from 'dataloader';
8
+ import type { BaseNodeRecord } from '@grafema/types';
9
+ import type { RFDBServerBackend } from '@grafema/core';
10
+ /**
11
+ * Create a DataLoader for batching node lookups.
12
+ *
13
+ * The loader batches all node ID requests made within a single tick
14
+ * and resolves them with parallel backend calls.
15
+ *
16
+ * Complexity: O(n) where n = unique node IDs requested
17
+ */
18
+ export declare function createNodeLoader(backend: RFDBServerBackend): DataLoader<string, BaseNodeRecord | null>;
19
+ //# sourceMappingURL=nodeLoader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodeLoader.d.ts","sourceRoot":"","sources":["../../src/dataloaders/nodeLoader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAEvD;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAC9B,OAAO,EAAE,iBAAiB,GACzB,UAAU,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAAC,CAmB3C"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Node DataLoader
3
+ *
4
+ * Batches multiple getNode() calls into efficient parallel lookups.
5
+ * Critical for preventing N+1 queries in GraphQL.
6
+ */
7
+ import DataLoader from 'dataloader';
8
+ /**
9
+ * Create a DataLoader for batching node lookups.
10
+ *
11
+ * The loader batches all node ID requests made within a single tick
12
+ * and resolves them with parallel backend calls.
13
+ *
14
+ * Complexity: O(n) where n = unique node IDs requested
15
+ */
16
+ export function createNodeLoader(backend) {
17
+ return new DataLoader(async (ids) => {
18
+ // Parallelize individual lookups
19
+ // Future optimization: add batch getNodes() to RFDB protocol
20
+ const results = await Promise.all(ids.map((id) => backend.getNode(id).catch(() => null)));
21
+ return results;
22
+ }, {
23
+ // Cache results within this request
24
+ cache: true,
25
+ // Use identity function for cache key
26
+ cacheKeyFn: (id) => id,
27
+ // Max batch size to prevent overwhelming backend
28
+ maxBatchSize: 100,
29
+ });
30
+ }
31
+ //# sourceMappingURL=nodeLoader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodeLoader.js","sourceRoot":"","sources":["../../src/dataloaders/nodeLoader.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,UAAU,MAAM,YAAY,CAAC;AAIpC;;;;;;;GAOG;AACH,MAAM,UAAU,gBAAgB,CAC9B,OAA0B;IAE1B,OAAO,IAAI,UAAU,CACnB,KAAK,EAAE,GAAsB,EAAE,EAAE;QAC/B,iCAAiC;QACjC,6DAA6D;QAC7D,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,CAC/B,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,CAAC,CACvD,CAAC;QACF,OAAO,OAAO,CAAC;IACjB,CAAC,EACD;QACE,oCAAoC;QACpC,KAAK,EAAE,IAAI;QACX,sCAAsC;QACtC,UAAU,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE;QACtB,iDAAiD;QACjD,YAAY,EAAE,GAAG;KAClB,CACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @grafema/api - GraphQL API for Grafema code graph
3
+ *
4
+ * Provides a GraphQL endpoint for querying the code graph.
5
+ * Supports cursor-based pagination, subscriptions for streaming,
6
+ * and Datalog query passthrough.
7
+ */
8
+ export { createGraphQLServer, startServer } from './server.js';
9
+ export type { GraphQLServerOptions } from './server.js';
10
+ export type { GraphQLContext } from './context.js';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/D,YAAY,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AACxD,YAAY,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,9 @@
1
+ /**
2
+ * @grafema/api - GraphQL API for Grafema code graph
3
+ *
4
+ * Provides a GraphQL endpoint for querying the code graph.
5
+ * Supports cursor-based pagination, subscriptions for streaming,
6
+ * and Datalog query passthrough.
7
+ */
8
+ export { createGraphQLServer, startServer } from './server.js';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Cursor-based Pagination Utilities
3
+ *
4
+ * Implements Relay Connection spec for cursor-based pagination.
5
+ */
6
+ /**
7
+ * Encode a cursor from an ID.
8
+ * Format: base64("cursor:${id}")
9
+ */
10
+ export declare function encodeCursor(id: string): string;
11
+ /**
12
+ * Decode a cursor to get the ID.
13
+ * Returns null if cursor is invalid.
14
+ */
15
+ export declare function decodeCursor(cursor: string): string | null;
16
+ /**
17
+ * PageInfo structure per Relay spec.
18
+ */
19
+ export interface PageInfo {
20
+ hasNextPage: boolean;
21
+ hasPreviousPage: boolean;
22
+ startCursor: string | null;
23
+ endCursor: string | null;
24
+ }
25
+ /**
26
+ * Edge structure for connections.
27
+ */
28
+ export interface Edge<T> {
29
+ node: T;
30
+ cursor: string;
31
+ }
32
+ /**
33
+ * Connection structure per Relay spec.
34
+ */
35
+ export interface Connection<T> {
36
+ edges: Edge<T>[];
37
+ pageInfo: PageInfo;
38
+ totalCount: number;
39
+ }
40
+ /**
41
+ * Apply cursor-based pagination to an array.
42
+ *
43
+ * @param items - All items (already filtered)
44
+ * @param first - Number of items to return (default: 50, max: 250)
45
+ * @param after - Cursor to start after
46
+ * @param getId - Function to get ID from item for cursor encoding
47
+ * @returns Connection structure
48
+ */
49
+ export declare function paginateArray<T>(items: T[], first: number | null | undefined, after: string | null | undefined, getId: (item: T) => string): Connection<T>;
50
+ //# sourceMappingURL=pagination.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pagination.d.ts","sourceRoot":"","sources":["../src/pagination.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,CAE/C;AAED;;;GAGG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAU1D;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACvB,WAAW,EAAE,OAAO,CAAC;IACrB,eAAe,EAAE,OAAO,CAAC;IACzB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,IAAI,CAAC,CAAC;IACrB,IAAI,EAAE,CAAC,CAAC;IACR,MAAM,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU,CAAC,CAAC;IAC3B,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IACjB,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAC7B,KAAK,EAAE,CAAC,EAAE,EACV,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAChC,KAAK,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,EAChC,KAAK,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,GACzB,UAAU,CAAC,CAAC,CAAC,CAqCf"}