@xyd-js/gql 0.1.0-xyd.9 → 0.1.0-xyd.96
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/CHANGELOG.md +810 -0
- package/LICENSE +21 -0
- package/TODO.md +8 -0
- package/__fixtures__/-1.opendocs.docs-nested/input.graphql +66 -0
- package/__fixtures__/-1.opendocs.docs-nested/output.json +554 -0
- package/__fixtures__/-1.opendocs.flat/input.graphql +19 -0
- package/__fixtures__/-1.opendocs.flat/output.json +243 -0
- package/__fixtures__/-1.opendocs.scopes/input.graphql +33 -0
- package/__fixtures__/-1.opendocs.scopes/output.json +378 -0
- package/__fixtures__/-1.opendocs.sidebar/input.graphql +44 -0
- package/__fixtures__/-1.opendocs.sort/input.graphql +92 -0
- package/__fixtures__/-1.opendocs.sort/output.json +1078 -0
- package/__fixtures__/-1.opendocs.sort+group/input.graphql +111 -0
- package/__fixtures__/-1.opendocs.sort+group/output.json +1114 -0
- package/__fixtures__/-1.opendocs.sort+group+path/input.graphql +118 -0
- package/__fixtures__/-1.opendocs.sort+group+path/output.json +1114 -0
- package/__fixtures__/-2.complex.github/input.graphql +69424 -0
- package/__fixtures__/-2.complex.github/output.json +269874 -0
- package/__fixtures__/-2.complex.livesession/input.graphql +23 -0
- package/__fixtures__/-2.complex.livesession/output.json +302 -0
- package/__fixtures__/-2.complex.monday/input.graphql +6089 -0
- package/__fixtures__/-2.complex.monday/output.json +1 -0
- package/__fixtures__/-3.array-non-null-return/input.graphql +9 -0
- package/__fixtures__/-3.array-non-null-return/output.json +151 -0
- package/__fixtures__/1.basic/input.graphql +118 -0
- package/__fixtures__/1.basic/output.json +630 -0
- package/__fixtures__/2.circular/input.graphql +17 -0
- package/__fixtures__/2.circular/output.json +248 -0
- package/__fixtures__/3.opendocs/input.graphql +27 -0
- package/__fixtures__/3.opendocs/output.json +338 -0
- package/__fixtures__/4.union/input.graphql +19 -0
- package/__fixtures__/4.union/output.json +344 -0
- package/__fixtures__/5.flat/input.graphql +27 -0
- package/__fixtures__/5.flat/output.json +383 -0
- package/__fixtures__/6.default-values/input.graphql +47 -0
- package/__fixtures__/6.default-values/output.json +655 -0
- package/__fixtures__/7.type-args/input.graphql +19 -0
- package/__fixtures__/7.type-args/output.json +301 -0
- package/__fixtures__/8.default-sort/input.graphql +60 -0
- package/__fixtures__/8.default-sort/output.json +1078 -0
- package/__tests__/gqlSchemaToReferences.test.ts +109 -0
- package/__tests__/utils.ts +45 -0
- package/declarations.d.ts +4 -0
- package/dist/index.d.ts +17 -1
- package/dist/index.js +1334 -19871
- package/dist/index.js.map +1 -1
- package/dist/opendocs.graphql +56 -0
- package/package.json +7 -9
- package/src/context.ts +17 -0
- package/src/converters/gql-arg.ts +51 -0
- package/src/converters/gql-enum.ts +27 -0
- package/src/converters/gql-field.ts +164 -0
- package/src/converters/gql-input.ts +34 -0
- package/src/converters/gql-interface.ts +35 -0
- package/src/converters/gql-mutation.ts +36 -0
- package/src/converters/gql-object.ts +83 -0
- package/src/converters/gql-operation.ts +128 -0
- package/src/converters/gql-query.ts +36 -0
- package/src/converters/gql-sample.ts +159 -0
- package/src/converters/gql-scalar.ts +16 -0
- package/src/converters/gql-subscription.ts +36 -0
- package/src/converters/gql-types.ts +195 -0
- package/src/converters/gql-union.ts +40 -0
- package/src/gql-core.ts +362 -0
- package/src/opendocs.graphql +56 -0
- package/src/opendocs.ts +253 -0
- package/src/schema.ts +253 -67
- package/src/types.ts +103 -0
- package/src/utils.ts +21 -96
- package/tsconfig.json +1 -1
- package/tsup.config.ts +15 -1
- package/vitest.config.ts +15 -1
- package/examples/basic/index.ts +0 -12
- package/examples/basic/schema.graphqls +0 -89
- package/examples/basic/todo-app.graphqls +0 -184
- package/examples/graphql-types/graphql-types.0.basic.graphqls +0 -28
- package/examples/nested/nested-arg.0.not-required.graphqls +0 -8
- package/examples/nested/nested-arg.0.required.graphqls +0 -8
- package/examples/nested/nested-arg.1.deep.graphqls +0 -12
- package/src/hydration/README.md +0 -1
- package/src/hydration/gql-arg.ts +0 -53
- package/src/hydration/gql-field.ts +0 -206
- package/src/hydration/gql-input.ts +0 -67
- package/src/hydration/gql-object.ts +0 -35
- package/src/hydration/gql-types.ts +0 -50
- package/src/samples/index.ts +0 -95
- package/test/graphql-types.0.test.ts +0 -125
- package/test/nested-arg.0.test.ts +0 -208
- package/test/nested-arg.1.test.ts +0 -19
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import {describe, expect, it} from 'vitest'
|
|
2
|
+
|
|
3
|
+
import {testGqlSchemaToReferences} from "./utils";
|
|
4
|
+
|
|
5
|
+
const tests: {
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
options?: {
|
|
9
|
+
flat?: boolean;
|
|
10
|
+
};
|
|
11
|
+
}[] = [
|
|
12
|
+
{
|
|
13
|
+
name: "1.basic",
|
|
14
|
+
description: "A basic example",
|
|
15
|
+
},
|
|
16
|
+
{
|
|
17
|
+
name: "2.circular",
|
|
18
|
+
description: "A circular dependency reference example",
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
name: "3.opendocs",
|
|
22
|
+
description: "An opendocs directive example",
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
name: "4.union",
|
|
26
|
+
description: "An opendocs directive example",
|
|
27
|
+
},
|
|
28
|
+
{
|
|
29
|
+
name: "5.flat",
|
|
30
|
+
description: "Flat generation only via code options",
|
|
31
|
+
options: {
|
|
32
|
+
flat: true
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
name: "6.default-values",
|
|
37
|
+
description: "Default values example",
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "7.type-args",
|
|
41
|
+
description: "Type args",
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
name: "8.default-sort",
|
|
45
|
+
description: "Default sort example",
|
|
46
|
+
},
|
|
47
|
+
//
|
|
48
|
+
{
|
|
49
|
+
name: "-1.opendocs.flat",
|
|
50
|
+
description: "OpenDocs GraphQL Schema directive example with flat generation",
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
name: "-1.opendocs.sort",
|
|
54
|
+
description: "OpenDocs GraphQL Schema directive example with sort generation",
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "-1.opendocs.sort+group",
|
|
58
|
+
description: "OpenDocs GraphQL Schema directive example with group sort generation",
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
name: "-1.opendocs.sort+group+path",
|
|
62
|
+
description: "OpenDocs GraphQL Schema directive example with group + path sort generation",
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: "-1.opendocs.scopes",
|
|
66
|
+
description: "OpenDocs GraphQL Schema directive example with scopes generation",
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: "-1.opendocs.docs-nested",
|
|
70
|
+
description: "OpenDocs GraphQL Schema directive example with nested docs",
|
|
71
|
+
},
|
|
72
|
+
// //
|
|
73
|
+
// {
|
|
74
|
+
// name: "-3.array-non-null-return",
|
|
75
|
+
// description: "case: Array non-null return",
|
|
76
|
+
// options: {
|
|
77
|
+
// flat: true
|
|
78
|
+
// }
|
|
79
|
+
// },
|
|
80
|
+
|
|
81
|
+
// TODO: uncomment when ready
|
|
82
|
+
// {
|
|
83
|
+
// name: "-2.complex.monday",
|
|
84
|
+
// description: "Monday.com GraphQL API example",
|
|
85
|
+
// options: {
|
|
86
|
+
// flat: true
|
|
87
|
+
// }
|
|
88
|
+
// },
|
|
89
|
+
// {
|
|
90
|
+
// name: "-2.complex.github",
|
|
91
|
+
// description: "Github GraphQL API example",
|
|
92
|
+
// // TODO: Github API is very, very huge. Currently. xyd does not support such big schemas well so we need to flat all types.
|
|
93
|
+
// options: {
|
|
94
|
+
// flat: true
|
|
95
|
+
// }
|
|
96
|
+
// }
|
|
97
|
+
// {
|
|
98
|
+
// name: "-2.complex.livesession",
|
|
99
|
+
// description: "LiveSession GraphQL API example"
|
|
100
|
+
// }
|
|
101
|
+
]
|
|
102
|
+
|
|
103
|
+
describe("gqlSchemaToReferences", () => {
|
|
104
|
+
tests.forEach((test) => {
|
|
105
|
+
it(`[${test.name}]: ${test.description}`, async () => {
|
|
106
|
+
await testGqlSchemaToReferences(test.name, test.options);
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
|
|
5
|
+
import {expect} from "vitest";
|
|
6
|
+
|
|
7
|
+
import {gqlSchemaToReferences} from "../src";
|
|
8
|
+
import {GQLSchemaToReferencesOptions} from "../src/types";
|
|
9
|
+
|
|
10
|
+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
|
|
12
|
+
// Helper function to run a test with a specific fixture
|
|
13
|
+
export async function testGqlSchemaToReferences(fixtureName: string, options?: GQLSchemaToReferencesOptions) {
|
|
14
|
+
const schemaLocation = fullFixturePath(`${fixtureName}/input.graphql`)
|
|
15
|
+
const result = await gqlSchemaToReferences(schemaLocation, options);
|
|
16
|
+
// saveResultAsOutput(fixtureName, result)
|
|
17
|
+
const expectedOutput = readFixtureOutput(`${fixtureName}/output.json`);
|
|
18
|
+
|
|
19
|
+
try {
|
|
20
|
+
expect(result).toEqual(expectedOutput);
|
|
21
|
+
} catch (error) {
|
|
22
|
+
if (result?.length > 100) {
|
|
23
|
+
throw new Error(`FAILED: The diff result is too long (${result.length} items) to show.`);
|
|
24
|
+
}
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Helper function to read fixture output
|
|
30
|
+
function readFixtureOutput(name: string) {
|
|
31
|
+
const fixturePath = fullFixturePath(name);
|
|
32
|
+
return JSON.parse(fs.readFileSync(fixturePath, "utf8"));
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function fullFixturePath(name: string) {
|
|
36
|
+
return path.join(__dirname, "../__fixtures__", name);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
function saveResultAsOutput(fixtureName: string, result: any) {
|
|
40
|
+
fs.writeFileSync(fullFixturePath(fixtureName + "/output.json"), JSON.stringify(result, null, 2));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export function getFixturePath(name: string): string {
|
|
44
|
+
return path.join(__dirname, "../__fixtures__", name);
|
|
45
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
import { Reference } from '@xyd-js/uniform';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
interface SortItem {
|
|
4
|
+
node?: string;
|
|
5
|
+
group?: string[];
|
|
6
|
+
stack?: number;
|
|
7
|
+
}
|
|
8
|
+
interface OpenDocsSortConfig {
|
|
9
|
+
sortStack?: string[][];
|
|
10
|
+
sort?: SortItem[];
|
|
11
|
+
}
|
|
12
|
+
interface GQLSchemaToReferencesOptions {
|
|
13
|
+
regions?: string[];
|
|
14
|
+
flat?: boolean;
|
|
15
|
+
sort?: OpenDocsSortConfig;
|
|
16
|
+
route?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
declare function gqlSchemaToReferences(schemaLocation: string | string[], options?: GQLSchemaToReferencesOptions): Promise<Reference[]>;
|
|
4
20
|
|
|
5
21
|
export { gqlSchemaToReferences };
|