Skip to content

Commit 135a5e2

Browse files
committed
docs: improve docs and auto generate config docs (#56)
* docs: document class consolidation * auto generate configuration docs
1 parent 843e2ee commit 135a5e2

File tree

13 files changed

+176
-84
lines changed

13 files changed

+176
-84
lines changed

.github/workflows/docs.yml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ concurrency:
1818
group: pages
1919
cancel-in-progress: false
2020

21-
defaults:
22-
run:
23-
working-directory: docs
24-
2521
jobs:
2622
build:
2723
runs-on: ubuntu-latest
@@ -35,8 +31,16 @@ jobs:
3531
- name: Install Dependencies
3632
run: bun install
3733

34+
- name: Build Plugin
35+
run: bun run build
36+
37+
- name: Install Docs Dependencies
38+
run: bun install
39+
working-directory: docs
40+
3841
- name: Build Docs
3942
run: bun docs:build
43+
working-directory: docs
4044

4145
- name: Setup Pages
4246
uses: actions/configure-pages@v5

.prettierignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.hbs

docs/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# Generated files
88
.docusaurus
99
.cache-loader
10+
docs/configuration.md
1011

1112
# Misc
1213
.DS_Store

docs/bun.lockb

22.5 KB
Binary file not shown.

docs/docs/class-consolidation.md

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
---
2+
sidebar_position: 5
3+
---
4+
5+
# Class Consolidation
6+
7+
In GraphQL, it's common to have input types that mirror output types. For example, you might have a `UserInput` type for creating a user and a `User` type for querying a user. These types might have the same fields but are treated as separate types in GraphQL.
8+
9+
With the class consolidation feature, GraphQL Kotlin Codegen can detect when these types are equivalent and consolidate them into a single Kotlin class.
10+
If this class functions in your resolver code as both an input and an output type, GraphQL Kotlin will subsequently
11+
transform it into the separate input and output types we started with.
12+
13+
## How It Works
14+
15+
The class consolidation feature works by comparing the fields of input and output types. If the fields and their types
16+
are exactly the same, the types are considered equivalent.
17+
18+
Here's an example:
19+
20+
```graphql
21+
input UserInput {
22+
name: String!
23+
email: String!
24+
}
25+
26+
type User {
27+
name: String!
28+
email: String!
29+
}
30+
```
31+
32+
In this case, `UserInput` and `User` have the same fields, so they would be consolidated into a single Kotlin class:
33+
34+
```kotlin
35+
data class User(
36+
val name: String,
37+
val email: String
38+
)
39+
```
40+
41+
This also works recursively. If the fields of a type are themselves input or output types, they will be consolidated as well.
42+
43+
```graphql
44+
input UserInput {
45+
name: NameInput!
46+
email: String!
47+
}
48+
49+
input NameInput {
50+
first: String!
51+
last: String!
52+
}
53+
54+
type User {
55+
name: Name!
56+
email: String!
57+
}
58+
59+
type Name {
60+
first: String!
61+
last: String!
62+
}
63+
```
64+
65+
```kotlin
66+
data class User(
67+
val name: Name,
68+
val email: String
69+
)
70+
71+
data class Name(
72+
val first: String,
73+
val last: String
74+
)
75+
```
76+
77+
## Limitations
78+
79+
The class consolidation feature only works with types that have the same fields with the same types.
80+
If the fields are different, the types will not be consolidated. Instead, individual classes will be generated with the
81+
`@GraphQLValidObjectLocations` annotation, enforcing that the class can only be used as either an input or output type.
82+
Check out the [GraphQL Kotlin docs](https://opensource.expediagroup.com/graphql-kotlin/docs/schema-generator/customizing-schemas/restricting-input-output)
83+
to learn more about this annotation.

docs/docs/configuration.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

docs/docs/recommended-usage.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class MyQuery : Query, QueryInterface() {
6060

6161
```
6262

63-
The resulting source code is at risk of being extremely unperformant. The `MyType` class is a data class, which means
63+
The resulting source code is extremely unperformant. The `MyType` class is a data class, which means
6464
that the `field1` and `field2` properties are both initialized when the `MyType` object is created, and
6565
`myExpensiveCall1()` and `myExpensiveCall2()` will both be called in sequence! Even if I only query for `field1`, not
6666
only will `myExpensiveCall2()` still run, but it will also wait until `myExpensiveCall1()` is totally finished.

docs/docusaurus.config.ts

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import { themes as prismThemes } from "prism-react-renderer";
22
import type { Config } from "@docusaurus/types";
33
import type * as Preset from "@docusaurus/preset-classic";
4-
import * as path from "path";
54

6-
const config: Config = {
5+
export default {
76
title: "GraphQL Kotlin Codegen",
87
favicon: "img/favicon.ico",
98

@@ -30,15 +29,6 @@ const config: Config = {
3029
} satisfies Preset.Options,
3130
],
3231
],
33-
themes: [
34-
path.resolve(
35-
__dirname,
36-
"node_modules",
37-
"docusaurus-theme-github-codeblock",
38-
"build",
39-
"index.js",
40-
),
41-
],
4232
themeConfig: {
4333
navbar: {
4434
title: "GraphQL Kotlin Codegen",
@@ -76,6 +66,4 @@ const config: Config = {
7666
darkTheme: prismThemes.dracula,
7767
},
7868
} satisfies Preset.ThemeConfig,
79-
};
80-
81-
export default config;
69+
} satisfies Config;

docs/jsdoc.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"source": {
3+
"includePattern": ".+\\.(js|cjs|mjs)$"
4+
}
5+
}

docs/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"private": true,
44
"scripts": {
55
"docs:start": "docusaurus start",
6-
"docs:build": "tsc && docusaurus build"
6+
"docs:build": "tsc && bun generate && docusaurus build",
7+
"generate": "jsdoc2md --files ../dist/plugin.cjs --partial partials/main.hbs --partial partials/scope.hbs -c jsdoc.conf > docs/configuration.md"
78
},
89
"devDependencies": {
910
"@docusaurus/core": "3.2.1",
@@ -13,7 +14,7 @@
1314
"@docusaurus/types": "3.2.1",
1415
"@mdx-js/react": "3.0.1",
1516
"clsx": "2.1.1",
16-
"docusaurus-theme-github-codeblock": "2.0.2",
17+
"jsdoc-to-markdown": "8.0.1",
1718
"prism-react-renderer": "2.3.1",
1819
"react": "18.3.1",
1920
"react-dom": "18.3.1",

0 commit comments

Comments
 (0)