@xyd-js/gql 0.0.0-build

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 (76) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/LICENSE +21 -0
  3. package/README.md +3 -0
  4. package/TODO.md +8 -0
  5. package/__fixtures__/-1.opendocs.docs-nested/input.graphql +66 -0
  6. package/__fixtures__/-1.opendocs.docs-nested/output.json +554 -0
  7. package/__fixtures__/-1.opendocs.flat/input.graphql +19 -0
  8. package/__fixtures__/-1.opendocs.flat/output.json +243 -0
  9. package/__fixtures__/-1.opendocs.scopes/input.graphql +33 -0
  10. package/__fixtures__/-1.opendocs.scopes/output.json +378 -0
  11. package/__fixtures__/-1.opendocs.sidebar/input.graphql +44 -0
  12. package/__fixtures__/-1.opendocs.sort/input.graphql +92 -0
  13. package/__fixtures__/-1.opendocs.sort/output.json +1078 -0
  14. package/__fixtures__/-1.opendocs.sort+group/input.graphql +111 -0
  15. package/__fixtures__/-1.opendocs.sort+group/output.json +1114 -0
  16. package/__fixtures__/-1.opendocs.sort+group+path/input.graphql +118 -0
  17. package/__fixtures__/-1.opendocs.sort+group+path/output.json +1114 -0
  18. package/__fixtures__/-2.complex.github/input.graphql +69424 -0
  19. package/__fixtures__/-2.complex.github/output.json +269874 -0
  20. package/__fixtures__/-2.complex.livesession/input.graphql +23 -0
  21. package/__fixtures__/-2.complex.livesession/output.json +302 -0
  22. package/__fixtures__/-2.complex.monday/input.graphql +6089 -0
  23. package/__fixtures__/-2.complex.monday/output.json +1 -0
  24. package/__fixtures__/-3.array-non-null-return/input.graphql +9 -0
  25. package/__fixtures__/-3.array-non-null-return/output.json +151 -0
  26. package/__fixtures__/1.basic/input.graphql +118 -0
  27. package/__fixtures__/1.basic/output.json +630 -0
  28. package/__fixtures__/2.circular/input.graphql +17 -0
  29. package/__fixtures__/2.circular/output.json +248 -0
  30. package/__fixtures__/3.opendocs/input.graphql +27 -0
  31. package/__fixtures__/3.opendocs/output.json +338 -0
  32. package/__fixtures__/4.union/input.graphql +19 -0
  33. package/__fixtures__/4.union/output.json +344 -0
  34. package/__fixtures__/5.flat/input.graphql +27 -0
  35. package/__fixtures__/5.flat/output.json +383 -0
  36. package/__fixtures__/6.default-values/input.graphql +47 -0
  37. package/__fixtures__/6.default-values/output.json +655 -0
  38. package/__fixtures__/7.type-args/input.graphql +19 -0
  39. package/__fixtures__/7.type-args/output.json +301 -0
  40. package/__fixtures__/8.default-sort/input.graphql +60 -0
  41. package/__fixtures__/8.default-sort/output.json +1078 -0
  42. package/__tests__/gqlSchemaToReferences.test.ts +109 -0
  43. package/__tests__/utils.ts +45 -0
  44. package/declarations.d.ts +4 -0
  45. package/dist/index.d.ts +21 -0
  46. package/dist/index.js +1503 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/opendocs.graphql +56 -0
  49. package/index.ts +3 -0
  50. package/package.json +29 -0
  51. package/src/context.ts +17 -0
  52. package/src/converters/gql-arg.ts +51 -0
  53. package/src/converters/gql-enum.ts +27 -0
  54. package/src/converters/gql-field.ts +164 -0
  55. package/src/converters/gql-input.ts +34 -0
  56. package/src/converters/gql-interface.ts +35 -0
  57. package/src/converters/gql-mutation.ts +36 -0
  58. package/src/converters/gql-object.ts +83 -0
  59. package/src/converters/gql-operation.ts +128 -0
  60. package/src/converters/gql-query.ts +36 -0
  61. package/src/converters/gql-sample.ts +159 -0
  62. package/src/converters/gql-scalar.ts +16 -0
  63. package/src/converters/gql-subscription.ts +36 -0
  64. package/src/converters/gql-types.ts +195 -0
  65. package/src/converters/gql-union.ts +40 -0
  66. package/src/gql-core.ts +362 -0
  67. package/src/index.ts +3 -0
  68. package/src/opendocs.graphql +56 -0
  69. package/src/opendocs.ts +253 -0
  70. package/src/schema.ts +293 -0
  71. package/src/types.ts +103 -0
  72. package/src/utils.ts +25 -0
  73. package/tsconfig.json +18 -0
  74. package/tsup.config.ts +33 -0
  75. package/tsup.examples-config.ts +30 -0
  76. package/vitest.config.ts +21 -0
@@ -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
+ }
@@ -0,0 +1,4 @@
1
+ declare module '*.graphql' {
2
+ const content: string;
3
+ export default content;
4
+ }
@@ -0,0 +1,21 @@
1
+ import { Reference } from '@xyd-js/uniform';
2
+
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[]>;
20
+
21
+ export { gqlSchemaToReferences };