@rayfold/cli 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
package/NOTICE ADDED
@@ -0,0 +1,10 @@
1
+ Rayfold
2
+ Copyright 2026 The Rayfold Authors
3
+
4
+ This product is licensed under the Apache License, Version 2.0 (see LICENSE).
5
+
6
+ The data in data/gutenberg.json.gz is derived from the Project Gutenberg catalogue
7
+ (https://www.gutenberg.org/ebooks/offline_catalogs.html) and is not covered by this
8
+ project's copyright. See data/README.md for its source. Project Gutenberg is a
9
+ registered trademark of the Project Gutenberg Literary Archive Foundation; Rayfold is
10
+ not affiliated with or endorsed by Project Gutenberg.
package/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # @rayfold/cli
2
+
3
+ The `rayfold` command: validate schemas, catch breaking changes before they ship, see how a query will run, and
4
+ generate types.
5
+
6
+ ```sh
7
+ npm install --save-dev @rayfold/cli
8
+ npx rayfold check schema.rayfold
9
+ ```
10
+
11
+ | Command | What it does |
12
+ |---|---|
13
+ | `check <schema> [--against <old schema or lock file>] [--strict]` | Validates the schema. With `--against`, lists every change and fails on breaking ones (a removed field before its sunset date, a narrowed type, ...). |
14
+ | `check <schema> --resolvers <module>` | Do the resolvers cover the schema? Every operation wired, a loader for every field that takes arguments, and a warning for a resolver the schema no longer has. |
15
+ | `lock <schema> [--out rayfold.lock.json]` | Records field ordinals and the schema hash. Commit it and check later versions against it. |
16
+ | `hash <schema>` | Prints the schema hash. |
17
+ | `explain <schema> <op> [--shape "{...}"] [--args '{...}']` | Shows the plan: cost, depth, one loader call per level, and which policies push down to the data source. |
18
+ | `gen ts\|kotlin\|java <schema> [--out file] [--package pkg] [--class Name]` | Generates TypeScript types, Kotlin data classes, or Java records (one file, one class). |
19
+ | `shapes <schema> <file>` | Prints the shape id of each shape in the file, for registering trusted shapes. |
20
+ | `import openapi\|graphql <file> [--out schema.rayfold]` | Reads a first draft of a schema from an OpenAPI document or a GraphQL SDL. What the source cannot say is listed on stderr. |
21
+ | `mock <schema.rayfold> [--port 4500]` | Serves the schema with data the schema itself describes, and the explorer beside it, before any resolver exists. The same call always gives the same answer. |
22
+ | `lsp` | Runs the language server for `.rayfold` over stdin and stdout: errors as you type, completion, hover, go to definition and an outline, for any editor that speaks LSP. |
23
+ | `dev <dir> [--port 4400]` | Runs an example from a Rayfold repository checkout (a folder whose `src/index.ts` exports `createBookstore()`) with the explorer, WebSocket and MCP. |
24
+
25
+ In CI, `rayfold check schema.rayfold --against rayfold.lock.json` exits non-zero on a breaking change.
26
+
27
+ Apache-2.0.
@@ -0,0 +1,201 @@
1
+ /**
2
+ * A GraphQL SDL as a Rayfold schema.
3
+ *
4
+ * `Query` fields become queries, `Mutation` fields commands, `Subscription` fields streams, and the type system maps
5
+ * across almost whole. The one change that touches every line is nullability: GraphQL is nullable by default and marks
6
+ * the exceptions with `!`, Rayfold is the other way round and marks them with `?`.
7
+ *
8
+ * Reading the SDL needs the `graphql` package, which the CLI declares as an optional peer: it is only loaded when this
9
+ * command runs. What cannot be mapped is reported in `notes` rather than guessed at - a mutation says nothing about
10
+ * which errors it throws or what it emits, and a Relay connection is not a `Page`.
11
+ */
12
+ import { RESERVED_OP_NAMES, assertValid, builtinTypes, list, named } from "@rayfold/schema";
13
+ const ROOTS = { Query: "query", Mutation: "command", Subscription: "stream" };
14
+ export async function irFromGraphql(sdl) {
15
+ let parse;
16
+ try {
17
+ ({ parse } = await import("graphql"));
18
+ }
19
+ catch {
20
+ throw new Error("Reading a GraphQL schema needs the graphql package in this project: npm install graphql");
21
+ }
22
+ const notes = [];
23
+ const ir = { rayfold: "0.1", types: builtinTypes(), ops: {}, views: {} };
24
+ const document = parse(sdl);
25
+ // `schema { query: Root }` renames the roots; without one they are the usual names
26
+ const roots = { ...ROOTS };
27
+ for (const definition of document.definitions) {
28
+ if (definition.kind !== "SchemaDefinition")
29
+ continue;
30
+ for (const operation of definition.operationTypes) {
31
+ const kind = operation.operation === "query" ? "query" : operation.operation === "mutation" ? "command" : "stream";
32
+ roots[operation.type.name.value] = kind;
33
+ }
34
+ }
35
+ const rootNodes = [];
36
+ for (const definition of document.definitions) {
37
+ switch (definition.kind) {
38
+ case "ObjectTypeDefinition": {
39
+ const kind = roots[definition.name.value];
40
+ if (kind) {
41
+ rootNodes.push({ node: definition, kind });
42
+ break;
43
+ }
44
+ const fields = fieldsOf(definition, notes);
45
+ const identified = fields.find((f) => f.name === "id" && !f.type.nullable);
46
+ const implemented = (definition.interfaces ?? []).map((i) => i.name.value);
47
+ if (identified) {
48
+ ir.types[definition.name.value] = { kind: "entity", name: definition.name.value, ...describe(definition), annotations: [], fields, implements: implemented };
49
+ }
50
+ else {
51
+ if (implemented.length)
52
+ notes.push(`${definition.name.value}: implements ${implemented.join(", ")}, but only an entity can, so the interface was dropped.`);
53
+ ir.types[definition.name.value] = { kind: "object", name: definition.name.value, ...describe(definition), annotations: [], fields };
54
+ }
55
+ if (definition.name.value.endsWith("Connection")) {
56
+ notes.push(`${definition.name.value}: a connection is not a page. Rayfold pages are Page<T> with @page(cursor) on the field.`);
57
+ }
58
+ break;
59
+ }
60
+ case "InterfaceTypeDefinition":
61
+ ir.types[definition.name.value] = {
62
+ kind: "object",
63
+ name: definition.name.value,
64
+ ...describe(definition),
65
+ interface: true, // the flag the runtime reads; the annotation is how the schema text says it
66
+ annotations: [{ name: "interface", args: {} }],
67
+ fields: fieldsOf(definition, notes),
68
+ };
69
+ break;
70
+ case "InputObjectTypeDefinition":
71
+ ir.types[definition.name.value] = { kind: "input", name: definition.name.value, ...describe(definition), annotations: [], fields: fieldsOf(definition, notes) };
72
+ break;
73
+ case "EnumTypeDefinition":
74
+ ir.types[definition.name.value] = enumType(definition);
75
+ break;
76
+ case "UnionTypeDefinition":
77
+ ir.types[definition.name.value] = {
78
+ kind: "union",
79
+ name: definition.name.value,
80
+ ...describe(definition),
81
+ annotations: [],
82
+ members: (definition.types ?? []).map((t) => t.name.value),
83
+ };
84
+ break;
85
+ case "ScalarTypeDefinition":
86
+ if (!ir.types[definition.name.value]) {
87
+ ir.types[definition.name.value] = { kind: "scalar", name: definition.name.value, ...describe(definition), annotations: [] };
88
+ }
89
+ break;
90
+ case "SchemaDefinition":
91
+ case "DirectiveDefinition":
92
+ break;
93
+ default:
94
+ notes.push(`${definition.kind} was not read; extensions and executable documents are not part of a schema.`);
95
+ }
96
+ }
97
+ for (const { node, kind } of rootNodes) {
98
+ for (const field of node.fields ?? []) {
99
+ const name = opName(field.name.value, ir, notes);
100
+ ir.ops[name] = {
101
+ kind,
102
+ name,
103
+ ...describe(field),
104
+ args: (field.arguments ?? []).map((a) => argOf(a, notes)),
105
+ returns: typeRef(field.type),
106
+ throws: [],
107
+ emits: [],
108
+ annotations: deprecations(field),
109
+ };
110
+ if (kind === "command") {
111
+ notes.push(`${name}: a mutation says nothing about what it can fail with; add "throws" once you know.`);
112
+ }
113
+ }
114
+ }
115
+ if (!Object.keys(ir.ops).length)
116
+ notes.push("No Query, Mutation or Subscription type was found, so the schema has no operations.");
117
+ assertValid(ir);
118
+ return { ir, notes };
119
+ }
120
+ function enumType(node) {
121
+ return {
122
+ kind: "enum",
123
+ name: node.name.value,
124
+ ...describe(node),
125
+ annotations: [],
126
+ values: (node.values ?? []).map((v, i) => ({ name: v.name.value, ...describe(v), annotations: deprecations(v), ordinal: i + 1 })),
127
+ };
128
+ }
129
+ function fieldsOf(node, notes) {
130
+ const nodes = node.kind === "InputObjectTypeDefinition" ? (node.fields ?? []) : (node.fields ?? []);
131
+ return nodes.map((f, i) => {
132
+ const field = {
133
+ name: f.name.value,
134
+ ...describe(f),
135
+ type: typeRef(f.type),
136
+ args: f.kind === "FieldDefinition" ? (f.arguments ?? []).map((a) => argOf(a, notes)) : [],
137
+ annotations: deprecations(f),
138
+ ordinal: i + 1,
139
+ };
140
+ if (f.kind === "InputValueDefinition") {
141
+ const fallback = valueOf(f.defaultValue, notes);
142
+ if (fallback !== undefined)
143
+ field.default = fallback;
144
+ }
145
+ return field;
146
+ });
147
+ }
148
+ function argOf(node, notes) {
149
+ const arg = { name: node.name.value, ...describe(node), type: typeRef(node.type), annotations: deprecations(node) };
150
+ const fallback = valueOf(node.defaultValue, notes);
151
+ if (fallback !== undefined)
152
+ arg.default = fallback;
153
+ return arg;
154
+ }
155
+ /** GraphQL is nullable until `!` says otherwise; Rayfold is the other way round. */
156
+ function typeRef(node, nullable = true) {
157
+ if (node.kind === "NonNullType")
158
+ return typeRef(node.type, false);
159
+ if (node.kind === "ListType")
160
+ return list(typeRef(node.type), nullable);
161
+ return named(node.name.value, nullable);
162
+ }
163
+ function valueOf(node, notes) {
164
+ if (!node)
165
+ return undefined;
166
+ switch (node.kind) {
167
+ case "IntValue":
168
+ case "FloatValue":
169
+ return Number(node.value);
170
+ case "StringValue":
171
+ case "EnumValue":
172
+ return node.value;
173
+ case "BooleanValue":
174
+ return node.value;
175
+ case "NullValue":
176
+ return null;
177
+ case "ListValue":
178
+ return node.values.map((v) => valueOf(v, notes) ?? null);
179
+ case "ObjectValue":
180
+ return Object.fromEntries(node.fields.map((f) => [f.name.value, valueOf(f.value, notes) ?? null]));
181
+ default:
182
+ notes.push("A variable was used as a default value; it was left out.");
183
+ return undefined;
184
+ }
185
+ }
186
+ function deprecations(node) {
187
+ return (node.directives ?? []).some((d) => d.name.value === "deprecated") ? [{ name: "deprecated", args: {} }] : [];
188
+ }
189
+ function describe(node) {
190
+ const text = node.description?.value?.trim();
191
+ return text ? { description: text } : {};
192
+ }
193
+ function opName(name, ir, notes) {
194
+ let unique = RESERVED_OP_NAMES.has(name) ? `${name}Op` : name;
195
+ if (unique !== name)
196
+ notes.push(`${name}: the name is reserved by the protocol, so the operation is ${unique}.`);
197
+ for (let n = 2; ir.ops[unique]; n++)
198
+ unique = `${name}${n}`;
199
+ return unique;
200
+ }
201
+ //# sourceMappingURL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C,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IAC9D,IAAI,MAAM,KAAK,IAAI;QAAE,KAAK,CAAC,IAAI,CAAC,GAAG,IAAI,+DAA+D,MAAM,GAAG,CAAC,CAAC;IACjH,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;QAAE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,EAAE,CAAC;IAC5D,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/**\n * A GraphQL SDL as a Rayfold schema.\n *\n * `Query` fields become queries, `Mutation` fields commands, `Subscription` fields streams, and the type system maps\n * across almost whole. The one change that touches every line is nullability: GraphQL is nullable by default and marks\n * the exceptions with `!`, Rayfold is the other way round and marks them with `?`.\n *\n * Reading the SDL needs the `graphql` package, which the CLI declares as an optional peer: it is only loaded when this\n * command runs. What cannot be mapped is reported in `notes` rather than guessed at - a mutation says nothing about\n * which errors it throws or what it emits, and a Relay connection is not a `Page`.\n */\nimport { RESERVED_OP_NAMES, assertValid, builtinTypes, list, named, type ArgDef, type FieldDef, type JsonValue, type RayfoldSchemaIR, type TypeDef, type TypeRef } from \"@rayfold/schema\";\nimport type {\n DocumentNode,\n EnumTypeDefinitionNode,\n FieldDefinitionNode,\n InputObjectTypeDefinitionNode,\n InputValueDefinitionNode,\n InterfaceTypeDefinitionNode,\n ObjectTypeDefinitionNode,\n TypeNode,\n ValueNode,\n} from \"graphql\";\nimport type { Imported } from \"./import-openapi.ts\";\n\ntype Fielded = ObjectTypeDefinitionNode | InterfaceTypeDefinitionNode | InputObjectTypeDefinitionNode;\n\nconst ROOTS: Record<string, \"query\" | \"command\" | \"stream\"> = { Query: \"query\", Mutation: \"command\", Subscription: \"stream\" };\n\nexport async function irFromGraphql(sdl: string): Promise<Imported> {\n let parse: (text: string) => DocumentNode;\n try {\n ({ parse } = await import(\"graphql\"));\n } catch {\n throw new Error(\"Reading a GraphQL schema needs the graphql package in this project: npm install graphql\");\n }\n\n const notes: string[] = [];\n const ir: RayfoldSchemaIR = { rayfold: \"0.1\", types: builtinTypes(), ops: {}, views: {} };\n const document = parse(sdl);\n\n // `schema { query: Root }` renames the roots; without one they are the usual names\n const roots: Record<string, \"query\" | \"command\" | \"stream\"> = { ...ROOTS };\n for (const definition of document.definitions) {\n if (definition.kind !== \"SchemaDefinition\") continue;\n for (const operation of definition.operationTypes) {\n const kind = operation.operation === \"query\" ? \"query\" : operation.operation === \"mutation\" ? \"command\" : \"stream\";\n roots[operation.type.name.value] = kind;\n }\n }\n\n const rootNodes: Array<{ node: ObjectTypeDefinitionNode; kind: \"query\" | \"command\" | \"stream\" }> = [];\n for (const definition of document.definitions) {\n switch (definition.kind) {\n case \"ObjectTypeDefinition\": {\n const kind = roots[definition.name.value];\n if (kind) {\n rootNodes.push({ node: definition, kind });\n break;\n }\n const fields = fieldsOf(definition, notes);\n const identified = fields.find((f) => f.name === \"id\" && !f.type.nullable);\n const implemented = (definition.interfaces ?? []).map((i) => i.name.value);\n if (identified) {\n ir.types[definition.name.value] = { kind: \"entity\", name: definition.name.value, ...describe(definition), annotations: [], fields, implements: implemented };\n } else {\n if (implemented.length) notes.push(`${definition.name.value}: implements ${implemented.join(\", \")}, but only an entity can, so the interface was dropped.`);\n ir.types[definition.name.value] = { kind: \"object\", name: definition.name.value, ...describe(definition), annotations: [], fields };\n }\n if (definition.name.value.endsWith(\"Connection\")) {\n notes.push(`${definition.name.value}: a connection is not a page. Rayfold pages are Page<T> with @page(cursor) on the field.`);\n }\n break;\n }\n case \"InterfaceTypeDefinition\":\n ir.types[definition.name.value] = {\n kind: \"object\",\n name: definition.name.value,\n ...describe(definition),\n interface: true, // the flag the runtime reads; the annotation is how the schema text says it\n annotations: [{ name: \"interface\", args: {} }],\n fields: fieldsOf(definition, notes),\n };\n break;\n case \"InputObjectTypeDefinition\":\n ir.types[definition.name.value] = { kind: \"input\", name: definition.name.value, ...describe(definition), annotations: [], fields: fieldsOf(definition, notes) };\n break;\n case \"EnumTypeDefinition\":\n ir.types[definition.name.value] = enumType(definition);\n break;\n case \"UnionTypeDefinition\":\n ir.types[definition.name.value] = {\n kind: \"union\",\n name: definition.name.value,\n ...describe(definition),\n annotations: [],\n members: (definition.types ?? []).map((t) => t.name.value),\n };\n break;\n case \"ScalarTypeDefinition\":\n if (!ir.types[definition.name.value]) {\n ir.types[definition.name.value] = { kind: \"scalar\", name: definition.name.value, ...describe(definition), annotations: [] };\n }\n break;\n case \"SchemaDefinition\":\n case \"DirectiveDefinition\":\n break;\n default:\n notes.push(`${definition.kind} was not read; extensions and executable documents are not part of a schema.`);\n }\n }\n\n for (const { node, kind } of rootNodes) {\n for (const field of node.fields ?? []) {\n const name = opName(field.name.value, ir, notes);\n ir.ops[name] = {\n kind,\n name,\n ...describe(field),\n args: (field.arguments ?? []).map((a) => argOf(a, notes)),\n returns: typeRef(field.type),\n throws: [],\n emits: [],\n annotations: deprecations(field),\n };\n if (kind === \"command\") {\n notes.push(`${name}: a mutation says nothing about what it can fail with; add \"throws\" once you know.`);\n }\n }\n }\n\n if (!Object.keys(ir.ops).length) notes.push(\"No Query, Mutation or Subscription type was found, so the schema has no operations.\");\n assertValid(ir);\n return { ir, notes };\n}\n\nfunction enumType(node: EnumTypeDefinitionNode): TypeDef {\n return {\n kind: \"enum\",\n name: node.name.value,\n ...describe(node),\n annotations: [],\n values: (node.values ?? []).map((v, i) => ({ name: v.name.value, ...describe(v), annotations: deprecations(v), ordinal: i + 1 })),\n };\n}\n\nfunction fieldsOf(node: Fielded, notes: string[]): FieldDef[] {\n const nodes = node.kind === \"InputObjectTypeDefinition\" ? (node.fields ?? []) : (node.fields ?? []);\n return nodes.map((f, i) => {\n const field: FieldDef = {\n name: f.name.value,\n ...describe(f),\n type: typeRef(f.type),\n args: f.kind === \"FieldDefinition\" ? (f.arguments ?? []).map((a) => argOf(a, notes)) : [],\n annotations: deprecations(f),\n ordinal: i + 1,\n };\n if (f.kind === \"InputValueDefinition\") {\n const fallback = valueOf(f.defaultValue, notes);\n if (fallback !== undefined) field.default = fallback;\n }\n return field;\n });\n}\n\nfunction argOf(node: InputValueDefinitionNode, notes: string[]): ArgDef {\n const arg: ArgDef = { name: node.name.value, ...describe(node), type: typeRef(node.type), annotations: deprecations(node) };\n const fallback = valueOf(node.defaultValue, notes);\n if (fallback !== undefined) arg.default = fallback;\n return arg;\n}\n\n/** GraphQL is nullable until `!` says otherwise; Rayfold is the other way round. */\nfunction typeRef(node: TypeNode, nullable = true): TypeRef {\n if (node.kind === \"NonNullType\") return typeRef(node.type, false);\n if (node.kind === \"ListType\") return list(typeRef(node.type), nullable);\n return named(node.name.value, nullable);\n}\n\nfunction valueOf(node: ValueNode | undefined, notes: string[]): JsonValue | undefined {\n if (!node) return undefined;\n switch (node.kind) {\n case \"IntValue\":\n case \"FloatValue\":\n return Number(node.value);\n case \"StringValue\":\n case \"EnumValue\":\n return node.value;\n case \"BooleanValue\":\n return node.value;\n case \"NullValue\":\n return null;\n case \"ListValue\":\n return node.values.map((v) => valueOf(v, notes) ?? null);\n case \"ObjectValue\":\n return Object.fromEntries(node.fields.map((f) => [f.name.value, valueOf(f.value, notes) ?? null]));\n default:\n notes.push(\"A variable was used as a default value; it was left out.\");\n return undefined;\n }\n}\n\nfunction deprecations(node: { directives?: readonly { name: { value: string } }[] | undefined }): Array<{ name: string; args: Record<string, never> }> {\n return (node.directives ?? []).some((d) => d.name.value === \"deprecated\") ? [{ name: \"deprecated\", args: {} }] : [];\n}\n\nfunction describe(node: { description?: { value: string } | undefined }): { description?: string } {\n const text = node.description?.value?.trim();\n return text ? { description: text } : {};\n}\n\nfunction opName(name: string, ir: RayfoldSchemaIR, notes: string[]): string {\n let unique = RESERVED_OP_NAMES.has(name) ? `${name}Op` : name;\n if (unique !== name) notes.push(`${name}: the name is reserved by the protocol, so the operation is ${unique}.`);\n for (let n = 2; ir.ops[unique]; n++) unique = `${name}${n}`;\n return unique;\n}\n"]}