@contello/client 1.1.1 → 1.2.1
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/dist/cli.js +1 -1
- package/dist/{generate-GMV2AJ66.js → generate-AVDKBRM7.js} +40 -3
- package/dist/index.cjs +19 -5
- package/dist/index.js +19 -5
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
var command = process.argv[2];
|
|
5
5
|
switch (command) {
|
|
6
6
|
case "generate":
|
|
7
|
-
await import("./generate-
|
|
7
|
+
await import("./generate-AVDKBRM7.js");
|
|
8
8
|
break;
|
|
9
9
|
default:
|
|
10
10
|
console.error(command ? `unknown command: ${command}` : "usage: contello-client <command>");
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { mkdirSync, readFileSync, rmSync, writeFileSync } from "fs";
|
|
5
5
|
import { glob } from "fs/promises";
|
|
6
6
|
import { dirname, relative, resolve as resolve2 } from "path";
|
|
7
|
-
import { parse as parse2 } from "graphql";
|
|
7
|
+
import { Source, parse as parse2 } from "graphql";
|
|
8
8
|
|
|
9
9
|
// src/generate/config.ts
|
|
10
10
|
import { resolve } from "path";
|
|
@@ -38,7 +38,17 @@ async function loadConfig(cwd) {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
// src/generate/documents.ts
|
|
41
|
-
import {
|
|
41
|
+
import {
|
|
42
|
+
Kind,
|
|
43
|
+
NoFragmentCyclesRule,
|
|
44
|
+
NoUnusedFragmentsRule,
|
|
45
|
+
getLocation,
|
|
46
|
+
print,
|
|
47
|
+
specifiedRules,
|
|
48
|
+
validate
|
|
49
|
+
} from "graphql";
|
|
50
|
+
var SUPPRESSED_RULE_NAMES = /* @__PURE__ */ new Set([NoFragmentCyclesRule.name, NoUnusedFragmentsRule.name]);
|
|
51
|
+
var VALIDATION_RULES = specifiedRules.filter((rule) => !SUPPRESSED_RULE_NAMES.has(rule.name));
|
|
42
52
|
function collectFragments(documents) {
|
|
43
53
|
const fragments = /* @__PURE__ */ new Map();
|
|
44
54
|
for (const doc of documents) {
|
|
@@ -116,6 +126,32 @@ function sortFragmentsByDependency(fragments) {
|
|
|
116
126
|
}
|
|
117
127
|
return sorted;
|
|
118
128
|
}
|
|
129
|
+
function validateDocuments(schema, fragments, operations) {
|
|
130
|
+
const combined = {
|
|
131
|
+
kind: Kind.DOCUMENT,
|
|
132
|
+
definitions: [...fragments.values(), ...operations]
|
|
133
|
+
};
|
|
134
|
+
const errors = validate(schema, combined, VALIDATION_RULES);
|
|
135
|
+
if (errors.length === 0) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
const formatted = errors.map((err) => {
|
|
139
|
+
const locations = (err.nodes ?? []).map((node) => {
|
|
140
|
+
if (!node.loc) {
|
|
141
|
+
return null;
|
|
142
|
+
}
|
|
143
|
+
const { source, start } = node.loc;
|
|
144
|
+
const { line, column } = getLocation(source, start);
|
|
145
|
+
return ` at ${source.name}:${line}:${column}`;
|
|
146
|
+
}).filter((s) => s !== null);
|
|
147
|
+
return locations.length > 0 ? ` ${err.message}
|
|
148
|
+
${locations.join("\n")}` : ` ${err.message}`;
|
|
149
|
+
});
|
|
150
|
+
throw new Error(`graphql validation failed:
|
|
151
|
+
|
|
152
|
+
${formatted.join("\n\n")}
|
|
153
|
+
`);
|
|
154
|
+
}
|
|
119
155
|
function generateDocumentString(operation, allFragments) {
|
|
120
156
|
const usedFragments = /* @__PURE__ */ new Map();
|
|
121
157
|
collectUsedFragments(operation, allFragments, usedFragments);
|
|
@@ -802,9 +838,10 @@ async function main() {
|
|
|
802
838
|
console.warn(` ${yellow("\u26A0")} no documents found matching "${project.documents}"`);
|
|
803
839
|
continue;
|
|
804
840
|
}
|
|
805
|
-
const documents = documentPaths.map((p) => parse2(readFileSync(resolve2(cwd, p), "utf-8")));
|
|
841
|
+
const documents = documentPaths.map((p) => parse2(new Source(readFileSync(resolve2(cwd, p), "utf-8"), p)));
|
|
806
842
|
const fragments = collectFragments(documents);
|
|
807
843
|
const operations = collectOperations(documents);
|
|
844
|
+
validateDocuments(schema, fragments, operations);
|
|
808
845
|
const transformedFragments = new Map(
|
|
809
846
|
[...fragments].map(([name, frag]) => [name, transformFragment(schema, frag, fragments)])
|
|
810
847
|
);
|
package/dist/index.cjs
CHANGED
|
@@ -339,15 +339,29 @@ function resolveRefs(refs, flatMap) {
|
|
|
339
339
|
if (!ref._flatId) return [];
|
|
340
340
|
const component = flatMap.get(ref._flatId);
|
|
341
341
|
if (!component) return [];
|
|
342
|
-
|
|
343
|
-
if (Array.isArray(value) && value.length > 0 && value[0]?._flatId !== void 0) {
|
|
344
|
-
component[key] = resolveRefs(value, flatMap);
|
|
345
|
-
}
|
|
346
|
-
}
|
|
342
|
+
resolveNestedRefs(component, flatMap);
|
|
347
343
|
transformResponse(component);
|
|
348
344
|
return [component];
|
|
349
345
|
});
|
|
350
346
|
}
|
|
347
|
+
function resolveNestedRefs(value, flatMap) {
|
|
348
|
+
if (!value || typeof value !== "object") return;
|
|
349
|
+
if (Array.isArray(value)) {
|
|
350
|
+
for (const item of value) {
|
|
351
|
+
resolveNestedRefs(item, flatMap);
|
|
352
|
+
}
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
const obj = value;
|
|
356
|
+
for (const key of Object.keys(obj)) {
|
|
357
|
+
const inner = obj[key];
|
|
358
|
+
if (Array.isArray(inner) && inner.length > 0 && inner[0]?._flatId !== void 0) {
|
|
359
|
+
obj[key] = resolveRefs(inner, flatMap);
|
|
360
|
+
} else if (inner && typeof inner === "object") {
|
|
361
|
+
resolveNestedRefs(inner, flatMap);
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
351
365
|
|
|
352
366
|
// src/rpc.ts
|
|
353
367
|
function buildRpc(operations, client) {
|
package/dist/index.js
CHANGED
|
@@ -302,15 +302,29 @@ function resolveRefs(refs, flatMap) {
|
|
|
302
302
|
if (!ref._flatId) return [];
|
|
303
303
|
const component = flatMap.get(ref._flatId);
|
|
304
304
|
if (!component) return [];
|
|
305
|
-
|
|
306
|
-
if (Array.isArray(value) && value.length > 0 && value[0]?._flatId !== void 0) {
|
|
307
|
-
component[key] = resolveRefs(value, flatMap);
|
|
308
|
-
}
|
|
309
|
-
}
|
|
305
|
+
resolveNestedRefs(component, flatMap);
|
|
310
306
|
transformResponse(component);
|
|
311
307
|
return [component];
|
|
312
308
|
});
|
|
313
309
|
}
|
|
310
|
+
function resolveNestedRefs(value, flatMap) {
|
|
311
|
+
if (!value || typeof value !== "object") return;
|
|
312
|
+
if (Array.isArray(value)) {
|
|
313
|
+
for (const item of value) {
|
|
314
|
+
resolveNestedRefs(item, flatMap);
|
|
315
|
+
}
|
|
316
|
+
return;
|
|
317
|
+
}
|
|
318
|
+
const obj = value;
|
|
319
|
+
for (const key of Object.keys(obj)) {
|
|
320
|
+
const inner = obj[key];
|
|
321
|
+
if (Array.isArray(inner) && inner.length > 0 && inner[0]?._flatId !== void 0) {
|
|
322
|
+
obj[key] = resolveRefs(inner, flatMap);
|
|
323
|
+
} else if (inner && typeof inner === "object") {
|
|
324
|
+
resolveNestedRefs(inner, flatMap);
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
}
|
|
314
328
|
|
|
315
329
|
// src/rpc.ts
|
|
316
330
|
function buildRpc(operations, client) {
|