Skip to content

Commit 37f6bae

Browse files
authored
Create docs site (#401)
📝 Description Create a new docs site with docusaurus. This is the first pass at copying the content over from the README. We will probably have to modify content but since this does not impact the library I think we can merge to get the setup running then edit pages as we see issues. You can see the running example here: https://experdelfavero.github.io/graphql-kotlin/
1 parent 41df336 commit 37f6bae

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+12015
-11
lines changed

.github/CODE_OF_CONDUCT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ behaviour and are expected to take appropriate and fair corrective action in
3838
response to any instances of unacceptable behaviour.
3939

4040
Project maintainers have the right and responsibility to remove, edit, or
41-
reject comments, commits, code, wiki edits, issues, and other contributions
41+
reject comments, commits, code, wiki or documentation edits, issues, and other contributions
4242
that are not aligned to this Code of Conduct, or to ban temporarily or
4343
permanently any contributor for other behaviours that they deem inappropriate,
4444
threatening, offensive, or harmful.

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@
33
.DS_Store
44
target
55
pom.xml.versionsBackup
6+
7+
website/translated_docs
8+
website/build/
9+
website/yarn.lock
10+
website/node_modules
11+
website/i18n/*

CONTRIBUTING.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ mvn antrun:run@detekt
5353

5454
## Add documentation for new or updated functionality
5555

56-
Please add appropriate javadocs in the source code and ask the maintainers to update the wiki with any relevant information.
56+
Please add appropriate javadocs in the source code and ask the maintainers to update the documentation with any relevant
57+
information.
58+
Further instructions on how to add documentation content are in `webserver/README.md`.
5759

5860
## Add license information
5961
All source files must contain the following license header. If you are using an IDE please add this as a copyright template for this project so that it will be added automatically.

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ type Widget {
5151

5252
## 📋 Documentation
5353

54-
Examples and documentation are available on our [Uncyclo](https://github.com/ExpediaGroup/graphql-kotlin/wiki) or in each module README file.
54+
Examples and documentation are available on our
55+
[documentation](https://ExpediaGroup.github.io/graphql-kotlin/docs/doc-main),
56+
or in each module README file.
5557

56-
If you have a question about something you can not find in our wiki, the indivdual modules, or javadocs, feel free to [create an issue](https://github.com/ExpediaGroup/graphql-kotlin/issues) and tag it with the question label.
58+
If you have a question about something you can not find in our documentation, the indivdual modules, or javadocs, feel free to [create an issue](https://github.com/ExpediaGroup/graphql-kotlin/issues) and tag it with the question label.
5759

5860
## 👥 Contact
5961

docs/contributors/release-proc.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
---
2+
id: release-proc
3+
title: Releasing a new version
4+
---
5+
1. The `pom.xml` should already be `${currentVersion}-SNAPSHOT`
6+
7+
2. Draft a new release and tag the commit (usually just `master`) you want to release as `${currentVersion}` or
8+
increment to a new major/minor version https://github.com/ExpediaDotCom/graphql-kotlin/releases
9+
- When drafting a new release, look at the commit history and comment any new features that were made
10+
- Travis will automatically build on a new tag, change the pom to remove `-SNAPSHOT`, and push the library to Maven
11+
Central
12+
- Travis will create a new branch that bumps the version in both the library and example to
13+
`${nextVersion}-SNAPSHOT`
14+
15+
3. Create a new PR for the Travis branch for the snapshot updates

docs/doc-main.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
id: doc-main
3+
title: GraphQL-Kotlin User Guide
4+
---
5+
6+
GraphQL Kotlin consists of number of libraries that aim to simplify GraphQL integration for Kotlin applications.
7+
8+
## 📦 Modules
9+
10+
* [graphql-kotlin-federation](https://github.com/ExpediaGroup/graphql-kotlin/tree/master/graphql-kotlin-federation)
11+
— Schema generator extension to build federated GraphQL schemas
12+
* [graphql-kotlin-schema-generator](https://github.com/ExpediaGroup/graphql-kotlin/tree/master/graphql-kotlin-schema-generator)
13+
— Code only GraphQL schema generation for Kotlin
14+
* [graphql-kotlin-spring-server](https://github.com/ExpediaGroup/graphql-kotlin/tree/master/graphql-kotlin-spring-server)
15+
— Spring Boot auto-configuration library to create GraphQL web app
16+
* [examples](https://github.com/ExpediaGroup/graphql-kotlin/tree/master/examples)
17+
— Example apps that use graphql-kotlin libraries to test and demonstrate usages
18+
19+
If you encounter any problems using this library please open up a new
20+
[Issue](https://github.com/ExpediaGroup/graphql-kotlin/issues)
21+
22+
Additional resources
23+
24+
* [GraphQL](https://graphql.org/)
25+
* [graphql-java](https://www.graphql-java.com/documentation/)

docs/examples/examples.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
id: examples
3+
title: Examples of how to use the libraries
4+
---
5+
6+
## Spring Example
7+
8+
One way to run a GraphQL server is with [Spring Boot](https://github.com/spring-projects/spring-boot). A sample Spring
9+
Boot app that uses [Spring
10+
Webflux](https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html) together with
11+
`graphql-kotlin-schema-generator` and [graphql-playground](https://github.com/prisma/graphql-playground) is provided as
12+
a [examples/spring](https://github.com/ExpediaGroup/graphql-kotlin/tree/master/examples/spring). All the examples used
13+
in this documentation should be available in the sample app.
14+
15+
In order to run it you can run
16+
[Application.kt](https://github.com/ExpediaDotCom/graphql-kotlin/blob/master/graphql-kotlin-spring-example/src/main/kotlin/com/expedia/graphql/sample/Application.kt)
17+
directly from your IDE. Alternatively you can also use the Spring Boot maven plugin by running `mvn spring-boot:run`
18+
from the command line. Once the app has started you can explore the example schema by opening Playground endpoint at
19+
[http://localhost:8080/playground](http://localhost:8080/playground).
20+
21+
## Federation Example
22+
23+
Example Spring Boot apps generating Federated GraphQL schema and Apollo Gateway that exposes single federated schema are
24+
provided in [examples/federation](https://github.com/ExpediaGroup/graphql-kotlin/tree/master/examples/federation)
25+
project. Please refer to their README files for details on how to run the target applications.

docs/execution/async-models.md

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
id: async-models
3+
title: Async Models
4+
---
5+
By default, `graphql-kotlin-schema-generator` will resolve all functions synchronously, i.e. it will block the
6+
underlying thread while executing the target function. While you could configure your GraphQL server with execution
7+
strategies that execute each query in parallel on some thread pools, instead we highly recommend to utilize asynchronous
8+
programming models.
9+
10+
## Coroutines
11+
12+
`graphql-kotlin-schema-generator` has built-in support for Kotlin coroutines. Provided default
13+
[FunctionDataFetcher](https://github.com/ExpediaDotCom/graphql-kotlin/blob/master/graphql-kotlin-schema-generator/src/main/kotlin/com/expedia/graphql/execution/FunctionDataFetcher.kt)
14+
will automatically asynchronously execute suspendable functions and convert the result to `CompletableFuture` expected
15+
by `graphql-java`.
16+
17+
Example
18+
19+
```kotlin
20+
data class User(val id: String, val name: String)
21+
22+
class Query {
23+
suspend fun getUser(id: String): User {
24+
// Your coroutine logic to get user data
25+
}
26+
}
27+
```
28+
29+
will produce the following schema
30+
31+
```graphql
32+
33+
schema {
34+
query: Query
35+
}
36+
37+
type Query {
38+
getUser(id: String!): User
39+
}
40+
41+
type User {
42+
id: String!
43+
name: String!
44+
}
45+
```
46+
47+
## CompletableFuture
48+
49+
`graphql-java` relies on Java `CompletableFuture` for asynchronously processing the requests. In order to simplify the
50+
interop with `graphql-java`, `graphql-kotlin-schema-generator` has a built-in hook which will automatically unwrap a
51+
`CompletableFuture` and use the inner class as the return type in the schema.
52+
53+
```kotlin
54+
data class User(val id: String, val name: String)
55+
56+
class Query {
57+
fun getUser(id: String): CompletableFuture<User> {
58+
// Your logic to get data asynchronously
59+
}
60+
}
61+
```
62+
63+
will result in the exactly the same schema as in the coroutine example above.
64+
65+
## RxJava/Reactor
66+
67+
If you use a different monad type, like `Single` from [RxJava](https://github.com/ReactiveX/RxJava) or `Mono` from
68+
[Project Reactor](https://projectreactor.io/), you just have to provide the logic in
69+
`SchemaGeneratorHooks.willResolveMonad` to unwrap it and return the inner class.
70+
71+
```kotlin
72+
class RxJava2Query {
73+
fun asynchronouslyDo(): Observable<Int> = Observable.just(1)
74+
75+
fun asynchronouslyDoSingle(): Single<Int> = Single.just(1)
76+
77+
fun maybe(): Maybe<Int> = Maybe.empty()
78+
}
79+
80+
private class MonadHooks : SchemaGeneratorHooks {
81+
override fun willResolveMonad(type: KType): KType = when (type.classifier) {
82+
Observable::class, Single::class, Maybe::class -> type.arguments.firstOrNull()?.type
83+
else -> type
84+
} ?: type
85+
}
86+
87+
val configWithRxJavaMonads = getConfig(hooks = MonadHooks())
88+
89+
toSchema(queries = listOf(TopLevelObject(RxJava2Query())), config = configWithRxJavaMonads)
90+
```
91+
92+
This will produce
93+
94+
```graphql
95+
type Query {
96+
asynchronouslyDo(): Int
97+
asynchronouslyDoSingle(): Int
98+
maybe: Int
99+
}
100+
```
101+
102+
You can find additional example on how to configure the hooks in our [unit
103+
tests](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/graphql-kotlin-schema-generator/src/test/kotlin/com/expediagroup/graphql/generator/SchemaGeneratorAsyncTests.kt).
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
id: data-fetching-environment
3+
title: Data Fetching Environment
4+
---
5+
Each resolver has a `DataFetchingEnvironment` that can be accessed from graphql-java:
6+
https://www.graphql-java.com/documentation/v13/data-fetching/
7+
8+
You can access this info by including the `DataFetchingEnvironment` as one of the arguments to a Kotlin function. This
9+
argument will not be included in the schema.
10+
11+
```kotlin
12+
class Query {
13+
fun printEnvironmentInfo(environment: DataFetchingEnvironment, value: Int): String {
14+
// Access env data
15+
}
16+
}
17+
```
18+
19+
This will produce the following schema
20+
21+
```graphql
22+
type Query {
23+
printEnvironmentInfo(value: Int!): String!
24+
}
25+
```
26+
27+
You can also use this to retrieve arguments and query information from higher up the query chain. You can see a working
28+
example in the `graphql-kotlin-spring-example` module
29+
[[link](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/examples/spring/src/main/kotlin/com/expediagroup/graphql/sample/query/EnvironmentQuery.kt#L32)].

docs/execution/subscriptions.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
id: subscriptions
3+
title: Subscriptions
4+
---
5+
Subscriptions are supported with `graphql-java`. See their documentation first:
6+
https://www.graphql-java.com/documentation/v11/subscriptions/
7+
8+
To make a function a subscription function you just have to have the return type wrapped in an implementation of a
9+
reactive-streams `Publisher`. As an example here is a function that uses Spring WebFlux to return a random number every
10+
second. Since `Flux` is an implementation of `Publisher` this is a valid method.
11+
12+
```kotlin
13+
@GraphQLDescription("Returns a random number every second")
14+
fun counter(): Flux<Int> = Flux.interval(Duration.ofSeconds(1)).map { Random.nextInt() }
15+
```
16+
17+
Then in the `toSchema` method you just have to provide a `List<TopLevelObject>` the same way as queries and mutations
18+
are provided with the `subscriptions` argument.
19+
20+
```kotlin
21+
toSchema(
22+
config = schemaConfig,
23+
queries = queries.toTopLevelObjects(),
24+
mutations = mutations.toTopLevelObjects(),
25+
subscriptions = subscriptions.toTopLevelObjects()
26+
)
27+
```
28+
29+
### Subscription Hooks
30+
31+
Through the hooks a new method was added `didGenerateSubscriptionType` which is called after a new subscription type is
32+
generated but before it is added to the schema. The other hook are still called so you can add logic for the types and
33+
validation of subscriptions the same as queries and mutations.
34+
35+
### Server Implementation
36+
37+
The server that runs your GraphQL schema will have to support some method for subscriptions, like WebSockets.
38+
`graphql-kotlin-spring-server` provides default WebSocket based implementation and you can see an example implementation
39+
of a `Subscription` in the [example
40+
app](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/examples/spring/src/main/kotlin/com/expediagroup/graphql/sample/subscriptions/SimpleSubscription.kt).
41+
42+
> NOTE: make sure that your implementation supports the `graphql-ws` sub-protocol which requires you handle some
43+
> specific websocket events.

0 commit comments

Comments
 (0)