-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: improve docs and auto generate config docs (#56)
* docs: document class consolidation * auto generate configuration docs
- Loading branch information
1 parent
843e2ee
commit 135a5e2
Showing
13 changed files
with
176 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.hbs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
# Generated files | ||
.docusaurus | ||
.cache-loader | ||
docs/configuration.md | ||
|
||
# Misc | ||
.DS_Store | ||
|
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
--- | ||
sidebar_position: 5 | ||
--- | ||
|
||
# Class Consolidation | ||
|
||
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. | ||
|
||
With the class consolidation feature, GraphQL Kotlin Codegen can detect when these types are equivalent and consolidate them into a single Kotlin class. | ||
If this class functions in your resolver code as both an input and an output type, GraphQL Kotlin will subsequently | ||
transform it into the separate input and output types we started with. | ||
|
||
## How It Works | ||
|
||
The class consolidation feature works by comparing the fields of input and output types. If the fields and their types | ||
are exactly the same, the types are considered equivalent. | ||
|
||
Here's an example: | ||
|
||
```graphql | ||
input UserInput { | ||
name: String! | ||
email: String! | ||
} | ||
|
||
type User { | ||
name: String! | ||
email: String! | ||
} | ||
``` | ||
|
||
In this case, `UserInput` and `User` have the same fields, so they would be consolidated into a single Kotlin class: | ||
|
||
```kotlin | ||
data class User( | ||
val name: String, | ||
val email: String | ||
) | ||
``` | ||
|
||
This also works recursively. If the fields of a type are themselves input or output types, they will be consolidated as well. | ||
|
||
```graphql | ||
input UserInput { | ||
name: NameInput! | ||
email: String! | ||
} | ||
|
||
input NameInput { | ||
first: String! | ||
last: String! | ||
} | ||
|
||
type User { | ||
name: Name! | ||
email: String! | ||
} | ||
|
||
type Name { | ||
first: String! | ||
last: String! | ||
} | ||
``` | ||
|
||
```kotlin | ||
data class User( | ||
val name: Name, | ||
val email: String | ||
) | ||
|
||
data class Name( | ||
val first: String, | ||
val last: String | ||
) | ||
``` | ||
|
||
## Limitations | ||
|
||
The class consolidation feature only works with types that have the same fields with the same types. | ||
If the fields are different, the types will not be consolidated. Instead, individual classes will be generated with the | ||
`@GraphQLValidObjectLocations` annotation, enforcing that the class can only be used as either an input or output type. | ||
Check out the [GraphQL Kotlin docs](https://opensource.expediagroup.com/graphql-kotlin/docs/schema-generator/customizing-schemas/restricting-input-output) | ||
to learn more about this annotation. |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"source": { | ||
"includePattern": ".+\\.(js|cjs|mjs)$" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
sidebar_position: 3 | ||
--- | ||
|
||
# Configuration | ||
|
||
{{>all-docs~}} |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters