Skip to content

Commit 7763014

Browse files
smyrickShane Myrick
andauthored
Clean up docs (#759)
* Clean up docs * Update extended scalars docs * Update exception docs Co-authored-by: Shane Myrick <[email protected]>
1 parent 6842a06 commit 7763014

File tree

17 files changed

+213
-250
lines changed

17 files changed

+213
-250
lines changed

docs/blogs-and-videos.md

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,22 @@ title: Blogs & Videos
55

66
Here are some links to other blog posts and videos which may provide further examples and reading.
77

8-
### From the Expedia Group team
9-
10-
#### graphql-kotlin
8+
## graphql-kotlin
119
Articles and videos specifically about `graphql-kotlin`
1210

13-
* 📝 [graphql-kotlin: Generate a GraphQL schema from Kotlin code](https://medium.com/expedia-group-tech/graphql-kotlin-generate-a-graphql-schema-from-kotlin-code-21d1dc2f6e27)
14-
* 📝 [Release of graphql-kotlin 1.0.0!](https://medium.com/expedia-group-tech/release-of-graphql-kotlin-1-0-0-791ad85d3116)
15-
* 📝 [Creating GraphQL Schemas in Kotlin](https://medium.com/expedia-group-tech/creating-graphql-schemas-in-kotlin-aaaac0ab0672)
16-
* 📝 [Apollo Federation in a GraphQL Kotlin Server](https://medium.com/expedia-group-tech/apollo-federation-in-a-graphql-kotlin-server-115cea51607a)
17-
* 📝 [Creating a Reactive GraphQL Server with Spring Boot and Kotlin](https://medium.com/expedia-group-tech/creating-a-reactive-graphql-server-with-spring-boot-and-kotlin-54aca7316470)
18-
* 📺 [Bootiful GraphQL with Kotlin (Dariusz Kuc, Guillaume Scheibel)](https://www.youtube.com/watch?v=7YJyPXjLdug&amp;index=25) (en)
19-
* 📝 [🎉 Announcing graphql-kotlin 2.0!](https://medium.com/expedia-group-tech/graphql-kotlin-2-0-4006ea41f774)
20-
* 📝 [Introducing GraphQL Kotlin Client](https://medium.com/expedia-group-tech/introducing-graphql-kotlin-client-b32dc3061a6f)
11+
* 📝&nbsp;&nbsp;[graphql-kotlin: Generate a GraphQL schema from Kotlin code](https://medium.com/expedia-group-tech/graphql-kotlin-generate-a-graphql-schema-from-kotlin-code-21d1dc2f6e27)
12+
* 📝&nbsp;&nbsp;[Release of graphql-kotlin 1.0.0!](https://medium.com/expedia-group-tech/release-of-graphql-kotlin-1-0-0-791ad85d3116)
13+
* 📝&nbsp;&nbsp;[Creating GraphQL Schemas in Kotlin](https://medium.com/expedia-group-tech/creating-graphql-schemas-in-kotlin-aaaac0ab0672)
14+
* 📝&nbsp;&nbsp;[Apollo Federation in a GraphQL Kotlin Server](https://medium.com/expedia-group-tech/apollo-federation-in-a-graphql-kotlin-server-115cea51607a)
15+
* 📝&nbsp;&nbsp;[Creating a Reactive GraphQL Server with Spring Boot and Kotlin](https://medium.com/expedia-group-tech/creating-a-reactive-graphql-server-with-spring-boot-and-kotlin-54aca7316470)
16+
* 📺&nbsp;&nbsp;[Bootiful GraphQL with Kotlin (Dariusz Kuc, Guillaume Scheibel)](https://www.youtube.com/watch?v=7YJyPXjLdug&amp;index=25) (en)
17+
* 📝&nbsp;&nbsp;[Announcing graphql-kotlin 2.0!](https://medium.com/expedia-group-tech/graphql-kotlin-2-0-4006ea41f774)
18+
* 📝&nbsp;&nbsp;[Introducing GraphQL Kotlin Client](https://medium.com/expedia-group-tech/introducing-graphql-kotlin-client-b32dc3061a6f)
2119

22-
#### GraphQL
20+
## GraphQL
2321
Articles and videos about how Expedia Group is using GraphQL
2422

25-
* 📺 [Creating a federated schema for a global company (Shane Myrick)](https://youtu.be/MuD3TAP0D9Y) (en)
26-
* 📺 [Migrer ses APIs vers GraphQL: pourquoi? comment! (Guillaume Scheibel)](https://youtu.be/IRIkpvJo95s) (fr)
27-
* 📺 [Migrate your APIs to GraphQL: how? and why! (Guillaume Scheibel)](https://youtu.be/IkPMpzQ-TRI) (en)
28-
* 📺 [Transforming customer experiences and your organization with GraphQL (Jim Gust, Dan Boerner)](https://youtu.be/Jt-ZD4zj4Ow) (en)
23+
* 📺&nbsp;&nbsp;[Creating a federated schema for a global company (Shane Myrick)](https://youtu.be/MuD3TAP0D9Y) (en)
24+
* 📺&nbsp;&nbsp;[Migrer ses APIs vers GraphQL: pourquoi? comment! (Guillaume Scheibel)](https://youtu.be/IRIkpvJo95s) (fr)
25+
* 📺&nbsp;&nbsp;[Migrate your APIs to GraphQL: how? and why! (Guillaume Scheibel)](https://youtu.be/IkPMpzQ-TRI) (en)
26+
* 📺&nbsp;&nbsp;[Transforming customer experiences and your organization with GraphQL (Jim Gust, Dan Boerner)](https://youtu.be/Jt-ZD4zj4Ow) (en)

docs/getting-started.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ compile(group: 'com.expediagroup', name: 'graphql-kotlin-spring-server', version
5454

5555
## Generating a Schema
5656

57-
While we have included a server implementation, you can use `graphql-kotlin-schema-generator` to generate a schema from Kotlin code and expose it with any server library.
57+
You can use `graphql-kotlin-schema-generator` to generate a schema from Kotlin code and expose it with any server library.
5858

5959
See the docs in [Schema Generator Getting Started](./schema-generator/schema-generator-getting-started.md).
6060

61-
### Federation
61+
### Apollo Federation
6262

6363
Using `graphql-kotlin-federation`, you can generate an [Apollo Federation](https://www.apollographql.com/docs/apollo-server/federation/federation-spec/) complaint schema.
6464

@@ -73,3 +73,13 @@ See the docs in [Spring Server Overview](./spring-server/spring-overview.md).
7373
`graphql-kotlin-plugins` can be used to generate a `graphql-kotlin-client` from an existing schema that is easy to use and type-safe.
7474

7575
See the docs in [Client Overview](./client/client-overview.md).
76+
77+
## Examples
78+
79+
The `examples` module is a collection of working code and examples on how to use all of the `graphql-kotlin` modules.
80+
81+
See the [example docs](./examples.md) for more info.
82+
83+
## Blogs and Videos
84+
85+
You can find more posts and recorded conference talks on GraphQL and `graphql-kotlin` on our [Blogs and Videos](./blogs-and-videos.md) page.

docs/schema-generator/customizing-schemas/deprecating-schema.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,31 @@ id: deprecating-schema
33
title: Deprecating Schema
44
---
55

6-
### Deprecating Fields
7-
86
GraphQL schemas can have fields marked as deprecated. Instead of creating a custom annotation,
97
`graphql-kotlin-schema-generator` just looks for the `kotlin.Deprecated` annotation and will use that annotation message
108
for the deprecated reason.
119

1210
```kotlin
1311
class SimpleQuery {
1412
@Deprecated(message = "this query is deprecated", replaceWith = ReplaceWith("shinyNewQuery"))
15-
@GraphQLDescription("old query that should not be used always returns false")
1613
fun simpleDeprecatedQuery(): Boolean = false
1714

18-
@GraphQLDescription("new query that always returns true")
1915
fun shinyNewQuery(): Boolean = true
2016
}
2117
```
2218

2319
The above query would produce the following GraphQL schema:
2420

2521
```graphql
26-
schema {
27-
query: Query
28-
}
29-
3022
type Query {
31-
32-
"""old query that should not be used always returns false"""
3323
simpleDeprecatedQuery: Boolean! @deprecated(reason: "this query is deprecated, replace with shinyNewQuery")
3424

35-
"""new query that always returns true"""
3625
shinyNewQuery: Boolean!
3726
}
3827
```
3928

4029
While you can deprecate any fields/functions/classes in your Kotlin code, GraphQL only supports deprecation directive on
4130
the fields (which correspond to Kotlin fields and functions) and enum values.
4231

32+
Deprecation of input types is not yet supported [in the GraphQL spec](https://github.com/graphql/graphql-spec/pull/525).
33+

docs/schema-generator/customizing-schemas/documenting-fields.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: Documenting Schema
44
---
55

66
Since Javadocs are not available at runtime for introspection, `graphql-kotlin-schema-generator` includes an annotation
7-
class `@GraphQLDescription` that can be used to add schema descriptions to *any* GraphQL schema element. The string value can be in the Markdown format, however due to an [issue in graphql-java](https://github.com/graphql-java/graphql-java/issues/1677) the `#` character is not supported to mark header levels.
7+
class `@GraphQLDescription` that can be used to add schema descriptions to *any* GraphQL schema element. The string value can be in the Markdown format.
88

99
```kotlin
1010
@GraphQLDescription("A useful widget")
@@ -13,9 +13,8 @@ data class Widget(
1313
val value: Int?
1414
)
1515

16-
class WidgetQuery: Query {
17-
18-
@GraphQLDescription("creates new widget for given ID")
16+
class WidgetQuery {
17+
@GraphQLDescription("Creates new widget for given ID")
1918
fun widgetById(@GraphQLDescription("The special ingredient") id: Int): Widget? = Widget(id)
2019
}
2120
```
@@ -28,7 +27,7 @@ schema {
2827
}
2928

3029
type Query {
31-
"""creates new widget for given ID"""
30+
"""Creates new widget for given ID"""
3231
widgetById(
3332
"""The special ingredient"""
3433
id: Int!

docs/schema-generator/customizing-schemas/excluding-fields.md

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,6 @@ class SimpleQuery {
2222
The above query would produce the following GraphQL schema:
2323

2424
```graphql
25-
schema {
26-
query: Query
27-
}
28-
2925
type Query {
3026
doSomething(value: Int!): Boolean!
3127
}

docs/schema-generator/customizing-schemas/renaming-fields.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ type MyCustomName {
2121
}
2222
```
2323

24-
### Known Issues
24+
## Known Issues
2525
> NOTE: Due to how we deserialize input classes, if you rename a field of an input class you must also annotate the field with the Jackson annotation @JsonProperty. See [issue 493](https://github.com/ExpediaGroup/graphql-kotlin/issues/493) for more info.
2626

2727
```kotlin

docs/schema-generator/execution/async-models.md

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,6 @@ class Query {
2929
will produce the following schema
3030

3131
```graphql
32-
33-
schema {
34-
query: Query
35-
}
36-
3732
type Query {
3833
getUser(id: String!): User
3934
}

docs/schema-generator/execution/exceptions.md

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,34 @@ id: exceptions
33
title: Exceptions and Partial Data
44
---
55

6-
Exceptions thrown during execution of a query will result in a GraphQLError that is added to a list of errors of the result. See
7-
[graphql-java documentation](https://www.graphql-java.com/documentation/v14/execution/) for more details on how to customize your exception handling.
6+
## Returning GraphQL Errors
87

9-
### Partial Data
8+
Exceptions thrown during execution of an operation will result in an empty data response and a GraphQLError that is added to a list of errors of the result.
9+
See [graphql-java documentation](https://www.graphql-java.com/documentation/v14/execution/) for more details on how to customize your exception handling.
1010

11-
GraphQL allows you to return both data and errors in a single response. Depending on the criticality of the encountered error you may want to return
12-
partial data together with the corresponding errors. In Kotlin, functions return only a single value, which means that in order to return both data
11+
12+
```kotlin
13+
fun getRandomNumberOrError(): Int {
14+
val num = Random().nextInt(100)
15+
return if (num <= 50) num else throw Exception("number is greater than 50")
16+
}
17+
```
18+
19+
## Returning Data and Errors
20+
21+
GraphQL allows you to return both data and errors in a single response, as long as the data returned still matches the schema. Depending on the criticality of the encountered error, instead of throwing an exception, you may want to return
22+
default data or use a nullable field, but still include more information in the `errors` block. In Kotlin, functions return only a single value, which means that in order to return both data
1323
and errors you have to explicitly return them wrapped in a `DataFetcherResult` object.
1424

1525
```kotlin
1626
class DataAndErrorsQuery {
17-
fun returnDataAndErrors(): DataFetcherResult<String> {
18-
// some logic here to populate data and capture error
19-
return DataFetcherResult.newResult<String>()
20-
.data(myData)
21-
.error(myError)
27+
fun returnDataAndErrors(): DataFetcherResult<String?> {
28+
val data: String? = getData()
29+
val error = if (data == null) MyError() else null
30+
31+
return DataFetcherResult.newResult<String?>()
32+
.data(data)
33+
.error(error)
2234
.build()
2335
}
2436
}

docs/schema-generator/writing-schemas/arguments.md

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,15 @@ Method arguments are automatically exposed as part of the arguments to the corre
77

88
```kotlin
99
class SimpleQuery{
10-
11-
@GraphQLDescription("performs some operation")
12-
fun doSomething(@GraphQLDescription("super important value") value: Int): Boolean = true
10+
fun doSomething(value: Int): Boolean = true
1311
}
1412
```
1513

1614
The above Kotlin code will generate following GraphQL schema:
1715

1816
```graphql
1917
type Query {
20-
"""performs some operation"""
21-
doSomething(
22-
"""super important value"""
23-
value: Int!
24-
): Boolean!
18+
doSomething(value: Int!): Boolean!
2519
}
2620
```
2721

@@ -38,22 +32,15 @@ For example, the following code:
3832

3933
```kotlin
4034
class WidgetMutation {
41-
42-
@GraphQLDescription("modifies passed in widget so it doesn't have null value")
43-
fun processWidget(@GraphQLDescription("widget to be modified") widget: Widget): Widget {
35+
fun processWidget(widget: Widget): Widget {
4436
if (null == widget.value) {
4537
widget.value = 42
4638
}
4739
return widget
4840
}
4941
}
5042

51-
@GraphQLDescription("A useful widget")
52-
data class Widget(
53-
@GraphQLDescription("The widget's value that can be null")
54-
var value: Int? = nul
55-
) {
56-
@GraphQLDescription("returns original value multiplied by target OR null if original value was null")
43+
data class Widget(var value: Int? = nul) {
5744
fun multiplyValueBy(multiplier: Int) = value?.times(multiplier)
5845
}
5946
```
@@ -62,32 +49,17 @@ Will generate the following schema:
6249

6350
```graphql
6451
type Mutation {
65-
"""modifies passed in widget so it doesn't have null value"""
66-
processWidget(
67-
"""widget to be modified"""
68-
widget: WidgetInput!
69-
): Widget!
52+
processWidget(widget: WidgetInput!): Widget!
7053
}
7154

72-
"""A useful widget"""
7355
type Widget {
74-
75-
"""The widget's value that can be null"""
7656
value: Int
77-
78-
"""
79-
returns original value multiplied by target OR null if original value was null
80-
"""
8157
multiplyValueBy(multiplier: Int!): Int
8258
}
8359

84-
"""A useful widget"""
8560
input WidgetInput {
86-
87-
"""The widget's value that can be null"""
8861
value: Int
8962
}
90-
9163
```
9264

9365
Please note that only fields are exposed in the input objects. Functions will only be available on the GraphQL output
@@ -104,11 +76,7 @@ defaults (even if they are marked as nullable). Therefore in order for a GraphQL
10476
nullable and also specify a default Kotlin value.
10577

10678
```kotlin
107-
@GraphQLDescription("query with optional input")
108-
fun doSomethingWithOptionalInput(
109-
@GraphQLDescription("this field is required") requiredValue: Int,
110-
@GraphQLDescription("this field is optional") optionalValue: Int?)
111-
= "required value=$requiredValue, optional value=$optionalValue"
79+
fun doSomethingWithOptionalInput(requiredValue: Int, optionalValue: Int?) = "required value=$requiredValue, optional value=$optionalValue"
11280
```
11381

11482
NOTE: Non nullable input fields will always require users to specify the value regardless of whether a default Kotlin value

0 commit comments

Comments
 (0)