@distilled.cloud/core 1.0.0-rc.1 → 1.0.0-rc.10
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 +201 -0
- package/lib/api.d.ts.map +1 -1
- package/lib/api.js +16 -4
- package/lib/api.js.map +1 -1
- package/lib/category.d.ts +4 -4
- package/lib/category.js +4 -4
- package/lib/codegen/boolean-string-enums.d.ts +36 -0
- package/lib/codegen/boolean-string-enums.d.ts.map +1 -0
- package/lib/codegen/boolean-string-enums.js +94 -0
- package/lib/codegen/boolean-string-enums.js.map +1 -0
- package/lib/codegen/boolean-string-enums.test.d.ts +2 -0
- package/lib/codegen/boolean-string-enums.test.d.ts.map +1 -0
- package/lib/codegen/boolean-string-enums.test.js +147 -0
- package/lib/codegen/boolean-string-enums.test.js.map +1 -0
- package/lib/codegen/cli.d.ts +56 -6
- package/lib/codegen/cli.d.ts.map +1 -1
- package/lib/codegen/cli.js +59 -75
- package/lib/codegen/cli.js.map +1 -1
- package/lib/codegen/emit.d.ts +3 -7
- package/lib/codegen/emit.d.ts.map +1 -1
- package/lib/codegen/emit.js +6 -10
- package/lib/codegen/emit.js.map +1 -1
- package/lib/codegen/generator.d.ts.map +1 -1
- package/lib/codegen/generator.js +142 -20
- package/lib/codegen/generator.js.map +1 -1
- package/lib/codegen/graphql-client.d.ts +62 -0
- package/lib/codegen/graphql-client.d.ts.map +1 -0
- package/lib/codegen/graphql-client.js +294 -0
- package/lib/codegen/graphql-client.js.map +1 -0
- package/lib/codegen/graphql-client.test.d.ts +2 -0
- package/lib/codegen/graphql-client.test.d.ts.map +1 -0
- package/lib/codegen/graphql-client.test.js +311 -0
- package/lib/codegen/graphql-client.test.js.map +1 -0
- package/lib/codegen/graphql.d.ts +207 -0
- package/lib/codegen/graphql.d.ts.map +1 -0
- package/lib/codegen/graphql.js +799 -0
- package/lib/codegen/graphql.js.map +1 -0
- package/lib/codegen/openapi-cli.d.ts +17 -3
- package/lib/codegen/openapi-cli.d.ts.map +1 -1
- package/lib/codegen/openapi-cli.js +50 -48
- package/lib/codegen/openapi-cli.js.map +1 -1
- package/lib/codegen/openapi.d.ts +69 -6
- package/lib/codegen/openapi.d.ts.map +1 -1
- package/lib/codegen/openapi.js +173 -16
- package/lib/codegen/openapi.js.map +1 -1
- package/lib/codegen/patches.d.ts +65 -0
- package/lib/codegen/patches.d.ts.map +1 -0
- package/lib/codegen/patches.js +236 -0
- package/lib/codegen/patches.js.map +1 -0
- package/lib/codegen/patches.test.d.ts +2 -0
- package/lib/codegen/patches.test.d.ts.map +1 -0
- package/lib/codegen/patches.test.js +105 -0
- package/lib/codegen/patches.test.js.map +1 -0
- package/lib/codegen/proto.d.ts +121 -0
- package/lib/codegen/proto.d.ts.map +1 -0
- package/lib/codegen/proto.js +962 -0
- package/lib/codegen/proto.js.map +1 -0
- package/lib/codegen/rewrite-operation-ids.d.ts +131 -0
- package/lib/codegen/rewrite-operation-ids.d.ts.map +1 -0
- package/lib/codegen/rewrite-operation-ids.js +1079 -0
- package/lib/codegen/rewrite-operation-ids.js.map +1 -0
- package/lib/codegen/rewrite-operation-ids.test.d.ts +2 -0
- package/lib/codegen/rewrite-operation-ids.test.d.ts.map +1 -0
- package/lib/codegen/rewrite-operation-ids.test.js +533 -0
- package/lib/codegen/rewrite-operation-ids.test.js.map +1 -0
- package/lib/codegen/spec-path.d.ts +16 -0
- package/lib/codegen/spec-path.d.ts.map +1 -0
- package/lib/codegen/spec-path.js +101 -0
- package/lib/codegen/spec-path.js.map +1 -0
- package/lib/errors.d.ts.map +1 -1
- package/lib/errors.js +17 -13
- package/lib/errors.js.map +1 -1
- package/lib/graphql.d.ts +284 -0
- package/lib/graphql.d.ts.map +1 -0
- package/lib/graphql.fixture.d.ts +249 -0
- package/lib/graphql.fixture.d.ts.map +1 -0
- package/lib/graphql.fixture.js +240 -0
- package/lib/graphql.fixture.js.map +1 -0
- package/lib/graphql.js +718 -0
- package/lib/graphql.js.map +1 -0
- package/lib/graphql.test.d.ts +2 -0
- package/lib/graphql.test.d.ts.map +1 -0
- package/lib/graphql.test.js +780 -0
- package/lib/graphql.test.js.map +1 -0
- package/lib/graphql.types.d.ts +2 -0
- package/lib/graphql.types.d.ts.map +1 -0
- package/lib/graphql.types.js +45 -0
- package/lib/graphql.types.js.map +1 -0
- package/lib/json-patch.d.ts +18 -11
- package/lib/json-patch.d.ts.map +1 -1
- package/lib/json-patch.js +63 -25
- package/lib/json-patch.js.map +1 -1
- package/lib/pagination.d.ts +43 -3
- package/lib/pagination.d.ts.map +1 -1
- package/lib/pagination.js +91 -5
- package/lib/pagination.js.map +1 -1
- package/lib/protocol-http.d.ts.map +1 -1
- package/lib/protocol-http.js +62 -26
- package/lib/protocol-http.js.map +1 -1
- package/lib/protocol-http.test.d.ts +2 -0
- package/lib/protocol-http.test.d.ts.map +1 -0
- package/lib/protocol-http.test.js +88 -0
- package/lib/protocol-http.test.js.map +1 -0
- package/lib/protocol-rest.d.ts +12 -2
- package/lib/protocol-rest.d.ts.map +1 -1
- package/lib/protocol-rest.js +17 -3
- package/lib/protocol-rest.js.map +1 -1
- package/lib/retry.js +1 -1
- package/lib/schema.d.ts +1 -1
- package/lib/schema.d.ts.map +1 -1
- package/lib/schema.js +1 -1
- package/lib/schema.js.map +1 -1
- package/lib/trait.d.ts +27 -3
- package/lib/trait.d.ts.map +1 -1
- package/lib/trait.js +17 -1
- package/lib/trait.js.map +1 -1
- package/package.json +13 -10
- package/src/api.ts +18 -4
- package/src/category.ts +4 -4
- package/src/codegen/boolean-string-enums.test.ts +168 -0
- package/src/codegen/boolean-string-enums.ts +106 -0
- package/src/codegen/cli.ts +127 -110
- package/src/codegen/emit.ts +6 -10
- package/src/codegen/generator.ts +151 -21
- package/src/codegen/graphql-client.test.ts +386 -0
- package/src/codegen/graphql-client.ts +419 -0
- package/src/codegen/graphql.ts +1217 -0
- package/src/codegen/openapi-cli.ts +75 -59
- package/src/codegen/openapi.ts +255 -16
- package/src/codegen/patches.test.ts +130 -0
- package/src/codegen/patches.ts +291 -0
- package/src/codegen/proto.ts +1128 -0
- package/src/codegen/rewrite-operation-ids.test.ts +563 -0
- package/src/codegen/rewrite-operation-ids.ts +1206 -0
- package/src/codegen/spec-path.ts +115 -0
- package/src/errors.ts +20 -25
- package/src/graphql.fixture.ts +371 -0
- package/src/graphql.test.ts +974 -0
- package/src/graphql.ts +1321 -0
- package/src/graphql.types.ts +185 -0
- package/src/json-patch.ts +82 -25
- package/src/pagination.ts +134 -7
- package/src/protocol-http.test.ts +107 -0
- package/src/protocol-http.ts +67 -31
- package/src/protocol-rest.ts +28 -4
- package/src/retry.ts +1 -1
- package/src/schema.ts +2 -2
- package/src/trait.ts +39 -3
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/** GraphQL-native introspection compiler. No traversal limits or RPC projection. */
|
|
2
|
+
import { readIntrospection } from "./graphql.js";
|
|
3
|
+
export const graphqlTypeString = (ref) => {
|
|
4
|
+
if (ref.kind === "NON_NULL" || ref.kind === "LIST") {
|
|
5
|
+
if (!ref.ofType)
|
|
6
|
+
throw new Error(`Incomplete GraphQL ${ref.kind} reference`);
|
|
7
|
+
const inner = graphqlTypeString(ref.ofType);
|
|
8
|
+
return ref.kind === "NON_NULL" ? `${inner}!` : `[${inner}]`;
|
|
9
|
+
}
|
|
10
|
+
if (!ref.name)
|
|
11
|
+
throw new Error("Unnamed GraphQL type reference");
|
|
12
|
+
return ref.name;
|
|
13
|
+
};
|
|
14
|
+
/** Retain every schema coordinate, wrapper, default and abstract-type relationship. */
|
|
15
|
+
export const convertGraphQLClient = (introspection, options = {}) => {
|
|
16
|
+
const schema = readIntrospection(introspection);
|
|
17
|
+
const scalars = {
|
|
18
|
+
String: "string",
|
|
19
|
+
ID: "string",
|
|
20
|
+
Int: "number",
|
|
21
|
+
Float: "number",
|
|
22
|
+
Boolean: "boolean",
|
|
23
|
+
...options.scalars,
|
|
24
|
+
};
|
|
25
|
+
const argument = (value) => ({
|
|
26
|
+
type: graphqlTypeString(value.type),
|
|
27
|
+
...(value.description ? { description: value.description } : {}),
|
|
28
|
+
...(value.defaultValue != null ? { defaultValue: value.defaultValue } : {}),
|
|
29
|
+
});
|
|
30
|
+
const types = {};
|
|
31
|
+
for (const type of [...schema.types].sort((a, b) => a.name.localeCompare(b.name))) {
|
|
32
|
+
if (type.name.startsWith("__"))
|
|
33
|
+
continue;
|
|
34
|
+
types[type.name] = {
|
|
35
|
+
kind: type.kind,
|
|
36
|
+
...(type.description ? { description: type.description } : {}),
|
|
37
|
+
...(type.kind === "SCALAR"
|
|
38
|
+
? { scalar: scalars[type.name] ?? "unknown" }
|
|
39
|
+
: {}),
|
|
40
|
+
...(type.fields
|
|
41
|
+
? {
|
|
42
|
+
fields: Object.fromEntries([...type.fields]
|
|
43
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
44
|
+
.map((field) => [
|
|
45
|
+
field.name,
|
|
46
|
+
{
|
|
47
|
+
type: graphqlTypeString(field.type),
|
|
48
|
+
args: Object.fromEntries(field.args.map((arg) => [arg.name, argument(arg)])),
|
|
49
|
+
errors: [],
|
|
50
|
+
...(field.description
|
|
51
|
+
? { description: field.description }
|
|
52
|
+
: {}),
|
|
53
|
+
...(field.isDeprecated
|
|
54
|
+
? {
|
|
55
|
+
deprecated: field.deprecationReason || true,
|
|
56
|
+
}
|
|
57
|
+
: {}),
|
|
58
|
+
},
|
|
59
|
+
])),
|
|
60
|
+
}
|
|
61
|
+
: {}),
|
|
62
|
+
...(type.inputFields
|
|
63
|
+
? {
|
|
64
|
+
inputFields: Object.fromEntries(type.inputFields.map((field) => [field.name, argument(field)])),
|
|
65
|
+
}
|
|
66
|
+
: {}),
|
|
67
|
+
...(type.enumValues
|
|
68
|
+
? { enumValues: type.enumValues.map((value) => value.name) }
|
|
69
|
+
: {}),
|
|
70
|
+
...(type.possibleTypes
|
|
71
|
+
? { possibleTypes: type.possibleTypes.map((ref) => ref.name) }
|
|
72
|
+
: {}),
|
|
73
|
+
...("interfaces" in type && Array.isArray(type.interfaces)
|
|
74
|
+
? {
|
|
75
|
+
interfaces: type.interfaces.map((ref) => ref.name),
|
|
76
|
+
}
|
|
77
|
+
: {}),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
version: 1,
|
|
82
|
+
queryType: schema.queryType.name,
|
|
83
|
+
...(schema.mutationType ? { mutationType: schema.mutationType.name } : {}),
|
|
84
|
+
...(schema.subscriptionType
|
|
85
|
+
? { subscriptionType: schema.subscriptionType.name }
|
|
86
|
+
: {}),
|
|
87
|
+
types,
|
|
88
|
+
errors: {},
|
|
89
|
+
globalErrors: [],
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
/** Reject dangling schema/error references after patches, before generating code. */
|
|
93
|
+
export const validateGraphQLModel = (model) => {
|
|
94
|
+
const checkType = (ref, coordinate) => {
|
|
95
|
+
const name = ref.replace(/[\[\]!]/g, "");
|
|
96
|
+
if (!model.types[name])
|
|
97
|
+
throw new Error(`${coordinate}: unknown GraphQL type ${name}`);
|
|
98
|
+
};
|
|
99
|
+
const checkError = (error, coordinate) => {
|
|
100
|
+
if (!model.errors[error])
|
|
101
|
+
throw new Error(`${coordinate}: unknown GraphQL error ${error}`);
|
|
102
|
+
};
|
|
103
|
+
for (const name of [
|
|
104
|
+
model.queryType,
|
|
105
|
+
model.mutationType,
|
|
106
|
+
model.subscriptionType,
|
|
107
|
+
]) {
|
|
108
|
+
if (name && !model.types[name])
|
|
109
|
+
throw new Error(`Unknown GraphQL root ${name}`);
|
|
110
|
+
}
|
|
111
|
+
for (const error of model.globalErrors)
|
|
112
|
+
checkError(error, "globalErrors");
|
|
113
|
+
for (const [name, type] of Object.entries(model.types)) {
|
|
114
|
+
for (const [fieldName, field] of Object.entries(type.fields ?? {})) {
|
|
115
|
+
const coordinate = `${name}.${fieldName}`;
|
|
116
|
+
checkType(field.type, coordinate);
|
|
117
|
+
for (const [argName, arg] of Object.entries(field.args))
|
|
118
|
+
checkType(arg.type, `${coordinate}(${argName})`);
|
|
119
|
+
for (const error of field.errors)
|
|
120
|
+
checkError(error, coordinate);
|
|
121
|
+
}
|
|
122
|
+
for (const [fieldName, field] of Object.entries(type.inputFields ?? {}))
|
|
123
|
+
checkType(field.type, `${name}.${fieldName}`);
|
|
124
|
+
for (const member of [
|
|
125
|
+
...(type.possibleTypes ?? []),
|
|
126
|
+
...(type.interfaces ?? []),
|
|
127
|
+
])
|
|
128
|
+
checkType(member, name);
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
const literal = (value) => JSON.stringify(value);
|
|
132
|
+
const union = (values) => values.length ? values.join(" | ") : "never";
|
|
133
|
+
const documentation = (description) => description ? `/** ${description.replaceAll("*/", "* /")} */\n` : "";
|
|
134
|
+
/** Emit schema-indexed types and the matching runtime graph from one patched model. */
|
|
135
|
+
export const generateGraphQLClient = (model, options) => {
|
|
136
|
+
validateGraphQLModel(model);
|
|
137
|
+
const inputType = (ref) => {
|
|
138
|
+
if (ref.endsWith("!"))
|
|
139
|
+
return requiredInput(ref.slice(0, -1));
|
|
140
|
+
return `${requiredInput(ref)} | null`;
|
|
141
|
+
};
|
|
142
|
+
const requiredInput = (ref) => {
|
|
143
|
+
if (ref.startsWith("["))
|
|
144
|
+
return `ReadonlyArray<${inputType(ref.slice(1, -1))}>`;
|
|
145
|
+
const type = model.types[ref];
|
|
146
|
+
return type.kind === "INPUT_OBJECT"
|
|
147
|
+
? `Inputs[${literal(ref)}]`
|
|
148
|
+
: `Scalars[${literal(ref)}]`;
|
|
149
|
+
};
|
|
150
|
+
const argsType = (args) => `{ ${Object.entries(args)
|
|
151
|
+
.map(([name, arg]) => `${literal(name)}${arg.type.endsWith("!") && arg.defaultValue === undefined ? "" : "?"}: ${inputType(arg.type)}`)
|
|
152
|
+
.join("; ")} }`;
|
|
153
|
+
// GraphQL names are not necessarily valid or unoccupied TypeScript symbols.
|
|
154
|
+
// Schema names remain quoted map keys; exported values get stable safe names.
|
|
155
|
+
const occupied = new Set([
|
|
156
|
+
..."await break case catch class const continue debugger default delete do else enum export extends false finally for function if import in instanceof new null return super switch this throw true try typeof var void while with yield implements interface let package private protected public static arguments eval abstract any as asserts async bigint boolean constructor declare from get global infer intrinsic is keyof module namespace never number object of override readonly require satisfies set string symbol type undefined unique unknown using".split(" "),
|
|
157
|
+
"G",
|
|
158
|
+
"S",
|
|
159
|
+
"Category",
|
|
160
|
+
"Scalars",
|
|
161
|
+
"Inputs",
|
|
162
|
+
"Errors",
|
|
163
|
+
"Types",
|
|
164
|
+
"PossibleTypes",
|
|
165
|
+
"Schema",
|
|
166
|
+
"Selection",
|
|
167
|
+
"Result",
|
|
168
|
+
"SelectedErrors",
|
|
169
|
+
"GraphQLIssue",
|
|
170
|
+
"Report",
|
|
171
|
+
"catchTags",
|
|
172
|
+
"isErrorTag",
|
|
173
|
+
"GraphQLFailure",
|
|
174
|
+
"GraphQLTransportError",
|
|
175
|
+
"GraphQLDecodeError",
|
|
176
|
+
"GraphQLRequestError",
|
|
177
|
+
"UnknownGraphQLError",
|
|
178
|
+
"query",
|
|
179
|
+
"mutation",
|
|
180
|
+
"report",
|
|
181
|
+
"client",
|
|
182
|
+
"schema",
|
|
183
|
+
"errorClasses",
|
|
184
|
+
options.transportName ?? "transport",
|
|
185
|
+
options.requirementsType,
|
|
186
|
+
]);
|
|
187
|
+
const identifier = (name) => name.replace(/[^A-Za-z0-9_$]/g, "_").replace(/^(?=[0-9])/, "_") ||
|
|
188
|
+
"generated";
|
|
189
|
+
const allocate = (preferred, fallback) => {
|
|
190
|
+
let name = identifier(preferred);
|
|
191
|
+
if (occupied.has(name))
|
|
192
|
+
name = identifier(fallback);
|
|
193
|
+
const base = name;
|
|
194
|
+
for (let suffix = 2; occupied.has(name); suffix++)
|
|
195
|
+
name = `${base}${suffix}`;
|
|
196
|
+
occupied.add(name);
|
|
197
|
+
return name;
|
|
198
|
+
};
|
|
199
|
+
const errorNames = new Map(Object.keys(model.errors).map((tag) => [
|
|
200
|
+
tag,
|
|
201
|
+
allocate(tag, `${identifier(tag)}Error`),
|
|
202
|
+
]));
|
|
203
|
+
const lines = [
|
|
204
|
+
"// Generated by @distilled.cloud/core/codegen/graphql-client. DO NOT EDIT.",
|
|
205
|
+
'import * as G from "@distilled.cloud/core/graphql";',
|
|
206
|
+
'import * as S from "effect/Schema";',
|
|
207
|
+
'import * as Category from "@distilled.cloud/core/category";',
|
|
208
|
+
`import { ${options.transportName ?? "transport"} } from ${literal(options.transportImport)};`,
|
|
209
|
+
`import type { ${options.requirementsType} } from ${literal(options.requirementsImport)};`,
|
|
210
|
+
`export type { ${options.requirementsType} } from ${literal(options.requirementsImport)};`,
|
|
211
|
+
'export { catchTags, isErrorTag, GraphQLFailure, GraphQLTransportError, GraphQLDecodeError, GraphQLRequestError, UnknownGraphQLError, type GraphQLIssue, type Report } from "@distilled.cloud/core/graphql";',
|
|
212
|
+
"",
|
|
213
|
+
"export type Scalars = {",
|
|
214
|
+
];
|
|
215
|
+
for (const [name, type] of Object.entries(model.types)) {
|
|
216
|
+
if (type.kind === "SCALAR" || type.kind === "ENUM")
|
|
217
|
+
lines.push(`${literal(name)}: ${type.kind === "SCALAR" ? (type.scalar ?? "unknown") : union(type.enumValues.map(literal))};`);
|
|
218
|
+
}
|
|
219
|
+
lines.push("}", "export type Inputs = {");
|
|
220
|
+
for (const [name, type] of Object.entries(model.types)) {
|
|
221
|
+
if (type.kind === "INPUT_OBJECT")
|
|
222
|
+
lines.push(documentation(type.description), `${literal(name)}: ${argsType(type.inputFields ?? {})};`);
|
|
223
|
+
}
|
|
224
|
+
lines.push("}");
|
|
225
|
+
const categories = {
|
|
226
|
+
auth: "withAuthError",
|
|
227
|
+
badRequest: "withBadRequestError",
|
|
228
|
+
notFound: "withNotFoundError",
|
|
229
|
+
throttling: "withThrottlingError",
|
|
230
|
+
quota: "withQuotaError",
|
|
231
|
+
server: "withServerError",
|
|
232
|
+
conflict: "withConflictError",
|
|
233
|
+
};
|
|
234
|
+
for (const [tag, error] of Object.entries(model.errors)) {
|
|
235
|
+
const name = errorNames.get(tag);
|
|
236
|
+
const pipes = [
|
|
237
|
+
error.category
|
|
238
|
+
? categories[error.category] && `Category.${categories[error.category]}`
|
|
239
|
+
: undefined,
|
|
240
|
+
error.retryable
|
|
241
|
+
? `Category.withRetryable(${error.category === "throttling" ? "{ throttling: true }" : ""})`
|
|
242
|
+
: undefined,
|
|
243
|
+
].filter(Boolean);
|
|
244
|
+
lines.push(documentation(error.description), `export class ${name} extends S.TaggedError<${name}>()(${literal(tag)}, G.errorFields)${pipes.length ? `.pipe(${pipes.join(", ")})` : ""} {}`);
|
|
245
|
+
}
|
|
246
|
+
lines.push("export type Errors = {");
|
|
247
|
+
for (const [tag, name] of errorNames)
|
|
248
|
+
lines.push(`${literal(tag)}: ${name};`);
|
|
249
|
+
lines.push("}", "export type Types = {");
|
|
250
|
+
for (const [name, type] of Object.entries(model.types)) {
|
|
251
|
+
if (!["OBJECT", "INTERFACE", "UNION"].includes(type.kind))
|
|
252
|
+
continue;
|
|
253
|
+
lines.push(documentation(type.description), `${literal(name)}: {`);
|
|
254
|
+
for (const [fieldName, field] of Object.entries(type.fields ?? {})) {
|
|
255
|
+
lines.push(documentation(field.description), `${literal(fieldName)}: G.Field<${argsType(field.args)}, ${literal(field.type)}, ${union(field.errors.map(literal))}>;`);
|
|
256
|
+
}
|
|
257
|
+
lines.push("};");
|
|
258
|
+
}
|
|
259
|
+
lines.push("}", "export type PossibleTypes = {");
|
|
260
|
+
for (const [name, type] of Object.entries(model.types)) {
|
|
261
|
+
if (type.kind === "INTERFACE" || type.kind === "UNION")
|
|
262
|
+
lines.push(`${literal(name)}: ${union((type.possibleTypes ?? []).map(literal))};`);
|
|
263
|
+
}
|
|
264
|
+
lines.push("}", "export type Schema = {", "types: Types; scalars: Scalars; errors: Errors; possibleTypes: PossibleTypes;", `query: ${literal(model.queryType)};`, `mutation: ${model.mutationType ? literal(model.mutationType) : "never"};`, `subscription: ${model.subscriptionType ? literal(model.subscriptionType) : "never"};`, `globalErrors: ${union(model.globalErrors.map(literal))};`, "};");
|
|
265
|
+
lines.push("export type Selection<Name extends keyof Types> = G.Selection<Schema, Name>;", "export type Result<Name extends string, Select> = G.Result<Schema, Name, Select>;", "export type SelectedErrors<Name extends keyof Types, Select> = G.Errors<Schema, Name, Select>;");
|
|
266
|
+
lines.push(`export const schema: G.GraphQLModel = ${JSON.stringify(model)};`);
|
|
267
|
+
lines.push(`export const errorClasses = { ${[...errorNames].map(([tag, name]) => `${literal(tag)}: ${name}`).join(", ")} };`);
|
|
268
|
+
lines.push(`export const client = G.makeClient<Schema, ${options.requirementsType}>(schema, ${options.transportName ?? "transport"}, errorClasses);`, "export const query = client.query;", "export const mutation = client.mutation;", "export const report = client.report;");
|
|
269
|
+
const operationNames = new Map();
|
|
270
|
+
for (const [kind, name] of [
|
|
271
|
+
["query", model.queryType],
|
|
272
|
+
["mutation", model.mutationType],
|
|
273
|
+
]) {
|
|
274
|
+
for (const field of Object.keys(model.types[name ?? ""]?.fields ?? {})) {
|
|
275
|
+
const exportName = allocate(field, `${kind}${field[0].toUpperCase()}${field.slice(1)}`);
|
|
276
|
+
if (!operationNames.has(field))
|
|
277
|
+
operationNames.set(field, exportName);
|
|
278
|
+
lines.push(`export const ${exportName} = client.operation(${literal(kind)}, ${literal(field)});`);
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
for (const [alias, target] of Object.entries(options.operationAliases ?? {})) {
|
|
282
|
+
const targetName = operationNames.get(target);
|
|
283
|
+
// Legacy aliases are optional conveniences; never displace a real export.
|
|
284
|
+
if (targetName &&
|
|
285
|
+
alias !== target &&
|
|
286
|
+
identifier(alias) === alias &&
|
|
287
|
+
!occupied.has(alias)) {
|
|
288
|
+
occupied.add(alias);
|
|
289
|
+
lines.push(`export const ${alias} = ${targetName};`);
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return lines.join("\n") + "\n";
|
|
293
|
+
};
|
|
294
|
+
//# source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C,GAAG,IAAI,CAAC;AACjC,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graphql-client.test.d.ts","sourceRoot":"","sources":["../../src/codegen/graphql-client.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,311 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { buildSchema, introspectionFromSchema, parse, validate } from "graphql";
|
|
3
|
+
import { compile } from "../graphql.js";
|
|
4
|
+
import { fixtureSDL } from "../graphql.fixture.js";
|
|
5
|
+
import { applyOperation } from "../json-patch.js";
|
|
6
|
+
import { convertGraphQLClient, generateGraphQLClient, graphqlTypeString, validateGraphQLModel, } from "./graphql-client.js";
|
|
7
|
+
const named = (name, kind = "OBJECT") => ({ kind, name });
|
|
8
|
+
const required = (ofType) => ({ kind: "NON_NULL", ofType });
|
|
9
|
+
const list = (ofType) => ({ kind: "LIST", ofType });
|
|
10
|
+
const field = (name, type, args = []) => ({
|
|
11
|
+
name,
|
|
12
|
+
type,
|
|
13
|
+
args,
|
|
14
|
+
});
|
|
15
|
+
const fixture = {
|
|
16
|
+
queryType: { name: "Query" },
|
|
17
|
+
mutationType: { name: "Mutation" },
|
|
18
|
+
types: [
|
|
19
|
+
{ kind: "SCALAR", name: "String" },
|
|
20
|
+
{ kind: "SCALAR", name: "Int" },
|
|
21
|
+
{ kind: "SCALAR", name: "JSON" },
|
|
22
|
+
{
|
|
23
|
+
kind: "ENUM",
|
|
24
|
+
name: "Status",
|
|
25
|
+
enumValues: [{ name: "ACTIVE" }, { name: "OLD", isDeprecated: true }],
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
kind: "INPUT_OBJECT",
|
|
29
|
+
name: "Filter",
|
|
30
|
+
inputFields: [
|
|
31
|
+
{
|
|
32
|
+
name: "status",
|
|
33
|
+
type: named("Status", "ENUM"),
|
|
34
|
+
defaultValue: "ACTIVE",
|
|
35
|
+
},
|
|
36
|
+
],
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
kind: "OBJECT",
|
|
40
|
+
name: "Query",
|
|
41
|
+
fields: [
|
|
42
|
+
field("project", required(named("Project")), [
|
|
43
|
+
{ name: "id", type: required(named("String", "SCALAR")) },
|
|
44
|
+
]),
|
|
45
|
+
field("search", list(named("Search", "UNION"))),
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
kind: "OBJECT",
|
|
50
|
+
name: "Mutation",
|
|
51
|
+
fields: [
|
|
52
|
+
field("projectCreate", named("Project"), [
|
|
53
|
+
{ name: "filter", type: named("Filter", "INPUT_OBJECT") },
|
|
54
|
+
]),
|
|
55
|
+
],
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
kind: "OBJECT",
|
|
59
|
+
name: "Project",
|
|
60
|
+
interfaces: [named("Node", "INTERFACE")],
|
|
61
|
+
fields: [
|
|
62
|
+
field("id", required(named("String", "SCALAR"))),
|
|
63
|
+
field("children", required(list(required(named("Project")))), [
|
|
64
|
+
{
|
|
65
|
+
name: "first",
|
|
66
|
+
type: required(named("Int", "SCALAR")),
|
|
67
|
+
defaultValue: "20",
|
|
68
|
+
},
|
|
69
|
+
{ name: "filter", type: named("Filter", "INPUT_OBJECT") },
|
|
70
|
+
]),
|
|
71
|
+
{
|
|
72
|
+
...field("legacy", named("String", "SCALAR")),
|
|
73
|
+
isDeprecated: true,
|
|
74
|
+
deprecationReason: "Use id",
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
kind: "OBJECT",
|
|
80
|
+
name: "Service",
|
|
81
|
+
fields: [field("id", required(named("String", "SCALAR")))],
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
kind: "INTERFACE",
|
|
85
|
+
name: "Node",
|
|
86
|
+
fields: [field("id", required(named("String", "SCALAR")))],
|
|
87
|
+
possibleTypes: [named("Project")],
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
kind: "UNION",
|
|
91
|
+
name: "Search",
|
|
92
|
+
possibleTypes: [named("Project"), named("Service")],
|
|
93
|
+
},
|
|
94
|
+
],
|
|
95
|
+
};
|
|
96
|
+
const options = {
|
|
97
|
+
transportImport: "./transport.ts",
|
|
98
|
+
requirementsImport: "./transport.ts",
|
|
99
|
+
requirementsType: "Requirements",
|
|
100
|
+
operationAliases: { createProject: "projectCreate" },
|
|
101
|
+
};
|
|
102
|
+
describe("GraphQL-native compiler", () => {
|
|
103
|
+
test("root helpers allocate safe unique names without hiding schema operations", () => {
|
|
104
|
+
const source = buildSchema(`
|
|
105
|
+
type Query {
|
|
106
|
+
query: String report: String schema: String transport: String G: String
|
|
107
|
+
catchTags: String delete: String Scalars: String Selection: String
|
|
108
|
+
same: String mutationSame: String
|
|
109
|
+
}
|
|
110
|
+
type Mutation { same: String }
|
|
111
|
+
`);
|
|
112
|
+
const model = convertGraphQLClient(introspectionFromSchema(source));
|
|
113
|
+
const output = generateGraphQLClient(model, {
|
|
114
|
+
...options,
|
|
115
|
+
operationAliases: {
|
|
116
|
+
default: "delete",
|
|
117
|
+
deleteField: "delete",
|
|
118
|
+
transport: "report",
|
|
119
|
+
readReport: "report",
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
expect(output).toContain('export const queryQuery = client.operation("query", "query");');
|
|
123
|
+
expect(output).toContain('export const queryReport = client.operation("query", "report");');
|
|
124
|
+
expect(output).toContain('export const queryTransport = client.operation("query", "transport");');
|
|
125
|
+
expect(output).toContain('export const queryDelete = client.operation("query", "delete");');
|
|
126
|
+
expect(output).toContain('export const queryScalars = client.operation("query", "Scalars");');
|
|
127
|
+
expect(output).toContain('export const mutationSame2 = client.operation("mutation", "same");');
|
|
128
|
+
expect(output).toContain("export const deleteField = queryDelete;");
|
|
129
|
+
expect(output).toContain("export const readReport = queryReport;");
|
|
130
|
+
expect(output).not.toContain("export const default =");
|
|
131
|
+
expect([...output.matchAll(/export const ([A-Za-z_$][\w$]*) =/g)].map((match) => match[1])).toEqual(expect.arrayContaining(["query", "report", "queryCatchTags"]));
|
|
132
|
+
const declarations = [
|
|
133
|
+
...output.matchAll(/export (?:const|class|type) ([A-Za-z_$][\w$]*)/g),
|
|
134
|
+
].map((match) => match[1]);
|
|
135
|
+
expect(new Set(declarations).size).toBe(declarations.length);
|
|
136
|
+
expect(output.match(/client\.operation\(/g)).toHaveLength(12);
|
|
137
|
+
expect(() => new Bun.Transpiler({ loader: "ts" }).transformSync(output)).not.toThrow();
|
|
138
|
+
expect(generateGraphQLClient(model, {
|
|
139
|
+
...options,
|
|
140
|
+
operationAliases: {
|
|
141
|
+
default: "delete",
|
|
142
|
+
deleteField: "delete",
|
|
143
|
+
transport: "report",
|
|
144
|
+
readReport: "report",
|
|
145
|
+
},
|
|
146
|
+
})).toBe(output);
|
|
147
|
+
});
|
|
148
|
+
test("schema type names and patched error tags cannot shadow generated support symbols", () => {
|
|
149
|
+
const model = convertGraphQLClient(introspectionFromSchema(buildSchema(`
|
|
150
|
+
type Query { data: Schema }
|
|
151
|
+
type Schema { selection: Selection }
|
|
152
|
+
type Selection { id: ID! }
|
|
153
|
+
`)));
|
|
154
|
+
for (const tag of ["Schema", "catchTags", "class"]) {
|
|
155
|
+
applyOperation(model, {
|
|
156
|
+
op: "add",
|
|
157
|
+
path: `/errors/${tag}`,
|
|
158
|
+
value: { matchers: [{ code: tag }] },
|
|
159
|
+
});
|
|
160
|
+
applyOperation(model, {
|
|
161
|
+
op: "add",
|
|
162
|
+
path: "/types/Query/fields/data/errors/-",
|
|
163
|
+
value: tag,
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
const output = generateGraphQLClient(model, options);
|
|
167
|
+
expect(output).toContain('export class SchemaError extends S.TaggedError<SchemaError>()("Schema", G.errorFields)');
|
|
168
|
+
expect(output).toContain('export class catchTagsError extends S.TaggedError<catchTagsError>()("catchTags", G.errorFields)');
|
|
169
|
+
expect(output).toContain('export class classError extends S.TaggedError<classError>()("class", G.errorFields)');
|
|
170
|
+
expect(output).toContain('"Schema": SchemaError;');
|
|
171
|
+
expect(output).toContain('"Schema": {');
|
|
172
|
+
expect(output).toContain('"Selection": {');
|
|
173
|
+
expect(() => new Bun.Transpiler({ loader: "ts" }).transformSync(output)).not.toThrow();
|
|
174
|
+
});
|
|
175
|
+
test("real introspection round-trips abstract fragments, recursive selections and defaulted required arguments", () => {
|
|
176
|
+
const schema = buildSchema(fixtureSDL.replaceAll("first: Int = 20", "first: Int! = 20"));
|
|
177
|
+
const model = convertGraphQLClient(introspectionFromSchema(schema));
|
|
178
|
+
const compiled = compile(model, "query", {
|
|
179
|
+
node: {
|
|
180
|
+
where: { id: "node-id" },
|
|
181
|
+
select: {
|
|
182
|
+
id: true,
|
|
183
|
+
__typename: true,
|
|
184
|
+
__on: {
|
|
185
|
+
Project: {
|
|
186
|
+
services: { select: { edges: { node: { id: true } } } },
|
|
187
|
+
},
|
|
188
|
+
Service: { status: true, project: { parent: { name: true } } },
|
|
189
|
+
},
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
search: {
|
|
193
|
+
where: { text: "query" },
|
|
194
|
+
select: {
|
|
195
|
+
__typename: true,
|
|
196
|
+
__on: { Project: { name: true }, Service: { status: true } },
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
});
|
|
200
|
+
expect(validate(schema, parse(compiled.query))).toEqual([]);
|
|
201
|
+
expect(compiled.query).not.toContain("first:");
|
|
202
|
+
expect(model.types.Project.fields.services.args.first).toEqual({
|
|
203
|
+
type: "Int!",
|
|
204
|
+
defaultValue: "20",
|
|
205
|
+
});
|
|
206
|
+
expect(model.types.ProjectFilter.inputFields.statuses).toEqual({
|
|
207
|
+
type: "[Status!]",
|
|
208
|
+
defaultValue: "[ACTIVE]",
|
|
209
|
+
});
|
|
210
|
+
const output = generateGraphQLClient(model, options);
|
|
211
|
+
expect(output).toContain('"first"?: Scalars["Int"]');
|
|
212
|
+
expect(output).toContain('"Node": "Project" | "Service"');
|
|
213
|
+
expect(output).toContain('"SearchResult": "Project" | "Service"');
|
|
214
|
+
});
|
|
215
|
+
test("required input fields with defaults are omittable but other required fields stay required", () => {
|
|
216
|
+
const schema = buildSchema(`
|
|
217
|
+
input Paging { limit: Int! = 20, owner: ID!, statuses: [String!]! = [] }
|
|
218
|
+
type Query { names(paging: Paging!): [String!]! }
|
|
219
|
+
`);
|
|
220
|
+
const model = convertGraphQLClient(introspectionFromSchema(schema));
|
|
221
|
+
const output = generateGraphQLClient(model, options);
|
|
222
|
+
expect(output).toContain('"limit"?: Scalars["Int"]');
|
|
223
|
+
expect(output).toContain('"owner": Scalars["ID"]');
|
|
224
|
+
expect(output).toContain('"statuses"?: ReadonlyArray<Scalars["String"]>');
|
|
225
|
+
const compiled = compile(model, "query", {
|
|
226
|
+
names: { where: { paging: { owner: "account" } } },
|
|
227
|
+
});
|
|
228
|
+
expect(Object.values(compiled.variables)).toEqual([{ owner: "account" }]);
|
|
229
|
+
expect(validate(schema, parse(compiled.query))).toEqual([]);
|
|
230
|
+
expect(() => compile(model, "query", { names: { where: { paging: {} } } })).toThrow("owner is required");
|
|
231
|
+
});
|
|
232
|
+
test("provider scalar overrides stay aligned in runtime metadata and generated scalar types", () => {
|
|
233
|
+
const schema = buildSchema(`scalar DateTime scalar JSON type Query { date: DateTime! blob: JSON! }`);
|
|
234
|
+
const model = convertGraphQLClient(introspectionFromSchema(schema), {
|
|
235
|
+
scalars: { DateTime: "string" },
|
|
236
|
+
});
|
|
237
|
+
const output = generateGraphQLClient(model, options);
|
|
238
|
+
expect(model.types.DateTime.scalar).toBe("string");
|
|
239
|
+
expect(model.types.JSON.scalar).toBe("unknown");
|
|
240
|
+
expect(output).toContain('"DateTime": string;');
|
|
241
|
+
expect(output).toContain('"JSON": unknown;');
|
|
242
|
+
expect(validate(schema, parse(compile(model, "query", { date: true, blob: true }).query))).toEqual([]);
|
|
243
|
+
});
|
|
244
|
+
test("preserves nested required arguments, defaults, recursion, union/interface members and deprecated fields", () => {
|
|
245
|
+
const model = convertGraphQLClient({ data: { __schema: fixture } });
|
|
246
|
+
expect(model.types.Project.fields.children).toEqual({
|
|
247
|
+
type: "[Project!]!",
|
|
248
|
+
args: {
|
|
249
|
+
first: { type: "Int!", defaultValue: "20" },
|
|
250
|
+
filter: { type: "Filter" },
|
|
251
|
+
},
|
|
252
|
+
errors: [],
|
|
253
|
+
});
|
|
254
|
+
expect(model.types.Project.interfaces).toEqual(["Node"]);
|
|
255
|
+
expect(model.types.Node.possibleTypes).toEqual(["Project"]);
|
|
256
|
+
expect(model.types.Search.possibleTypes).toEqual(["Project", "Service"]);
|
|
257
|
+
expect(model.types.Project.fields.legacy.deprecated).toBe("Use id");
|
|
258
|
+
expect(model.types.Status.enumValues).toEqual(["ACTIVE", "OLD"]);
|
|
259
|
+
expect(model.types.Filter.inputFields.status.defaultValue).toBe("ACTIVE");
|
|
260
|
+
expect(model.types.JSON.scalar).toBe("unknown");
|
|
261
|
+
validateGraphQLModel(model);
|
|
262
|
+
});
|
|
263
|
+
test("field errors patch the one model used by emitted type unions and runtime classification", () => {
|
|
264
|
+
const model = convertGraphQLClient(fixture);
|
|
265
|
+
applyOperation(model, {
|
|
266
|
+
op: "add",
|
|
267
|
+
path: "/errors/ChildrenUnavailable",
|
|
268
|
+
value: {
|
|
269
|
+
category: "server",
|
|
270
|
+
matchers: [{ code: "CHILDREN_UNAVAILABLE" }],
|
|
271
|
+
},
|
|
272
|
+
});
|
|
273
|
+
applyOperation(model, {
|
|
274
|
+
op: "add",
|
|
275
|
+
path: "/types/Project/fields/children/errors/-",
|
|
276
|
+
value: "ChildrenUnavailable",
|
|
277
|
+
});
|
|
278
|
+
const output = generateGraphQLClient(model, options);
|
|
279
|
+
expect(output).toContain('"children": G.Field<{ "first"?: Scalars["Int"]; "filter"?: Inputs["Filter"] | null }, "[Project!]!", "ChildrenUnavailable">;');
|
|
280
|
+
expect(output).toContain('export class ChildrenUnavailable extends S.TaggedError<ChildrenUnavailable>()("ChildrenUnavailable", G.errorFields).pipe(Category.withServerError)');
|
|
281
|
+
expect(output).toContain('"errors":["ChildrenUnavailable"]');
|
|
282
|
+
expect(output).toContain('"matchers":[{"code":"CHILDREN_UNAVAILABLE"}]');
|
|
283
|
+
expect(output).toContain('export const projectCreate = client.operation("mutation", "projectCreate");');
|
|
284
|
+
expect(output).toContain("export const createProject = projectCreate;");
|
|
285
|
+
});
|
|
286
|
+
test("generation has no fixed depth projection or artificial output optionality", () => {
|
|
287
|
+
const output = generateGraphQLClient(convertGraphQLClient(fixture), options);
|
|
288
|
+
expect(output).toContain('"Project": {');
|
|
289
|
+
expect(output).toContain('"Search": "Project" | "Service";');
|
|
290
|
+
expect(output).toContain('"Node": "Project";');
|
|
291
|
+
expect(output).toContain('"id": G.Field<{ }, "String!", never>;');
|
|
292
|
+
expect(output).not.toContain('"id"?: G.Field');
|
|
293
|
+
expect(output).not.toContain("maxDepth");
|
|
294
|
+
});
|
|
295
|
+
test("unknown coordinates, incomplete references and stale patches fail immediately", () => {
|
|
296
|
+
const model = convertGraphQLClient(fixture);
|
|
297
|
+
applyOperation(model, {
|
|
298
|
+
op: "add",
|
|
299
|
+
path: "/types/Project/fields/children/errors/-",
|
|
300
|
+
value: "MissingError",
|
|
301
|
+
});
|
|
302
|
+
expect(() => validateGraphQLModel(model)).toThrow("Project.children: unknown GraphQL error MissingError");
|
|
303
|
+
expect(() => graphqlTypeString({ kind: "NON_NULL" })).toThrow("Incomplete GraphQL NON_NULL");
|
|
304
|
+
expect(() => applyOperation(model, {
|
|
305
|
+
op: "replace",
|
|
306
|
+
path: "/types/Project/fields/removed/errors",
|
|
307
|
+
value: [],
|
|
308
|
+
})).toThrow();
|
|
309
|
+
});
|
|
310
|
+
});
|
|
311
|
+
//# sourceMappingURL=graphql-client.test.js.map
|