Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Cleanup documentation #14

Merged
merged 1 commit into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/content/Examples/index.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Here you can find some example projects using this library:

1. Basic example using the ktor
plugin: [Official Example](https://github.com/aPureBase/KGraphQL/tree/main/kgraphql-example)
plugin: [Official Example](https://github.com/stuebingerb/KGraphQL/tree/main/kgraphql-example)
1. Todo app that allows for nested todos and different scopes: [Todo Tree](https://github.com/MattLangsenkamp/TodoTree)
1. An article about pairing Kotlin and GraphQL together using
http4k [Medium Article](https://medium.com/@pagakrivos/graphql-and-kotlin-e5d17162d169) | [GitHub repo](https://github.com/pagidas/kgraphql-http4k-demo)
Expand Down
8 changes: 4 additions & 4 deletions docs/content/Installation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ title: Getting Started
weight: 1
---

[![Maven Central](https://img.shields.io/maven-central/v/com.apurebase/kgraphql.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.apurebase%22%20AND%20a:%22kgraphql%22)
[![Maven Central](https://img.shields.io/maven-central/v/de.stuebingerb/kgraphql.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22de.stuebingerb%22%20AND%20a:%22kgraphql%22)

KGraphQL is pushed to MavenCentral repository. It requires kotlin compiler version 1.4.x and require kotlin runtime of
the same version as a dependency.
Expand All @@ -20,7 +20,7 @@ Add Maven Central repository:
Add dependencies:

```kotlin
implementation("com.apurebase:kgraphql:$KGraphQLVersion")
implementation("de.stuebingerb:kgraphql:$KGraphQLVersion")
```

=== "Gradle"
Expand All @@ -35,7 +35,7 @@ Add Maven Central repository:
Add dependencies (you can also add other modules that you need):

```groovy
implementation 'com.apurebase:kgraphql:${KGraphQLVersion}'
implementation 'de.stuebingerb:kgraphql:${KGraphQLVersion}'
```

=== "Maven"
Expand All @@ -54,7 +54,7 @@ Add Maven Central repository to section:

```xml
<dependency>
<groupId>com.apurebase</groupId>
<groupId>de.stuebingerb</groupId>
<artifactId>kgraphql</artifactId>
<version>${KGraphQLVersion}</version>
</dependency>
Expand Down
2 changes: 1 addition & 1 deletion docs/content/Plugins/ktor.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Ktor

If you are running a ktor server. There is a separate package that makes it easy to set up a fully functional GraphQL
If you are running a ktor server, there is a separate package that makes it easy to set up a fully functional GraphQL
server.

You first need to add the KGraphQL-ktor package to your dependency
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ configure {
}
```

*example*
*Example*

```kotlin
data class Person(val id: Int, val name: String)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ of [deprecation](/docs/reference/deprecation).
data class Person(val name: String, val age: Int)

KGraphQL.schema {
type<Person>{
property<Boolean>("isChild"){
resolver { person -> (person.age <= 18) }
type<Person> {
property<Boolean>("isChild") {
resolver { person -> person.age <= 18 }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ weight: 1
---

Kotlin properties are automatically inspected during schema creation. Schema DSL allows ignoring
and [deprecation](/docs/reference/deprecation) of kotlin properties
and [deprecation](/docs/reference/deprecation) of kotlin properties.

*Example*

```kotlin
data class Person(val name: String, val age: Int)

KGraphQL.schema {
type<Person>{
property(Person::age){
type<Person> {
property(Person::age) {
ignore = true
}
property(Person::name){
deprecate("Person need no name")
property(Person::name) {
deprecate("Person needs no name")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ See [Extension Properties](/docs/reference/type-system/objects-and-interfaces/ex
data class Person(val name: String, val age: Int)

KGraphQL.schema {
type<Person>{
type<Person> {
description = "Human"
}
}
Expand All @@ -29,7 +29,7 @@ extension function `ignore()` makes KGraphQL ignore its receiver property.
data class Person(val name: String, val age: Int)

KGraphQL.schema {
type<Person>{
type<Person> {
Person::age.ignore()
}
}
Expand All @@ -46,11 +46,11 @@ operations, `transformation` has property `resolver` which is used to declare da
data class Person(val name: String, val age: Int)

KGraphQL.schema {
type<Person>{
type<Person> {
transformation(Person::age) {
//inMonths is nullable, so client can fetch age property without passing any value to this argument
//if(null == true) evaluates to false, if(null) is invalid kotlin code
age: Int , inMonths : Boolean? -> if(inMonths == true) age * 12 else age
// inMonths is nullable, so client can fetch age property without passing any value to this argument
// if(null == true) evaluates to false, if(null) is invalid kotlin code
age: Int, inMonths: Boolean? -> if (inMonths == true) { age * 12 } else { age }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,27 @@ members of union type will fail in runtime.
*Example*

```kotlin
data class UnionMember1(val one : String)
data class UnionMember1(val one: String)

data class UnionMember2(val two : String)
data class UnionMember2(val two: String)

data class Person(val name: String, val age: Int)

KGraphQL.schema {
type<Person>{
unionProperty("union"){
type<Person> {
unionProperty("union") {
nullable = true // Defaults to false
returnType = unionType("UnionExample"){
returnType = unionType("UnionExample") {
type<UnionMember1>()
type<UnionMember2>()
}
resolver { person -> if (person.age <= 18) UnionMember1("one") else UnionMember2("two") }
resolver { person ->
if (person.age <= 18) {
UnionMember1("one")
} else {
UnionMember2("two")
}
}
}
}
}
Expand Down
26 changes: 20 additions & 6 deletions docs/content/Reference/Type System/enums.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Enums

GraphQL Enums are a variant on the Scalar type, which represents one of a finite set of possible values. They directly
map to Kotlin enums
map to Kotlin enums.

*Example*

Expand All @@ -11,17 +11,31 @@ enum class Coolness {
}

val schema = KGraphQL.schema {
enum<Coolness>{
enum<Coolness> {
description = "State of coolness"
value(Coolness.COOL){
value(Coolness.COOL) {
description = "really cool"
}
}

query("cool"){
resolver{ cool: Coolness -> cool.toString() }
query("cool") {
resolver { cool: Coolness -> cool.toString() }
}
}
```

Enum values can be [deprecated](/Reference/deprecation).
Enum values can be [deprecated](/Reference/deprecation):

*Example*

```kotlin
enum class SampleEnum { ONE, TWO, THREE }

val schema = defaultSchema {
enum<SampleEnum> {
value(SampleEnum.ONE) {
deprecate("deprecated enum value")
}
}
}
```
7 changes: 4 additions & 3 deletions docs/content/Reference/Type System/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ either Object or Interface. Rules are following:
* if Interface in schema is implemented by any Class in schema, it is interpreted as GraphQL Interface type.
* if Interface in schema is NOT implemented by any Class in schema, it is interpreted as GraphQL Object type.

## Built in types
## Built-in Types

By default, every schema has following built in types:
By default, every schema has following built-in types:

### Scalars

Expand All @@ -36,4 +36,5 @@ By default, every schema has following built in types:

## Introspection types

Introspection interface aligns to [GraphQL specification](http://facebook.github.io/graphql/#sec-Schema-Introspection).
Introspection interface aligns to [GraphQL specification](https://spec.graphql.org/October2021/#sec-Introspection) with
additions from the current working draft (deprecated input fields and repeatable directives).
6 changes: 3 additions & 3 deletions docs/content/Reference/Type System/scalars.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ weight: 1
As defined by specification, scalar represents a primitive value in GraphQL. In KGraphQL, besides built-in scalar types,
client code can declare custom scalar type, which can coerce to String, Boolean, Int, Long or Float (Kotlin Double).

KGraphQL provides group of DSL methods: `stringScalar { }`, `booleanScalar { }`, `intScalar{ }`, `longScalar{ }`,
`floatScalar{ }`. They differ only by Kotlin primitive type they coerce to.
KGraphQL provides a group of DSL methods: `stringScalar { }`, `booleanScalar { }`, `intScalar{ }`, `longScalar{ }`,
`floatScalar{ }`. They differ only by the Kotlin primitive type they coerce to.

Scalar has to define its coercion functions `deserialize` and `serialize` or coercion object which implements correct
subtype of `com.apurebase.kgraphql.schema.scalar.ScalarCoercion`.
Expand All @@ -16,7 +16,7 @@ subtype of `com.apurebase.kgraphql.schema.scalar.ScalarCoercion`.

```kotlin
stringScalar<UUID> {
deserialize = { uuid : String -> UUID.fromString(uuid) }
deserialize = { uuid: String -> UUID.fromString(uuid) }
serialize = UUID::toString
}
```
Expand Down
7 changes: 5 additions & 2 deletions docs/content/Reference/Type System/unions.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ KgraphQL.schema {
unionProperty("unionExample") {
returnType = unionExample
resolver { _, isOne: Boolean ->
if (isOne) UnionMember1(one = "Hello")
else UnionMember2(two = "World")
if (isOne) {
UnionMember1(one = "Hello")
} else {
UnionMember2(two = "World")
}
}
}
}
Expand Down
11 changes: 8 additions & 3 deletions docs/content/Reference/accessRule.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Access Rule

It's possible to add restriction unto your resolvers by using the `accessRule`. Example shown below.
It's possible to add restriction unto your resolvers by using the `accessRule`.

*Example*

```kotlin
type<MyType> {
Expand All @@ -10,8 +12,11 @@ type<MyType> {

// Return an exception or null
accessRule { item: MyType, ctx: Content ->
if (item.ownerId != ctx.userId) IncorrectOwnerException()
else null
if (item.ownerId != ctx.userId) {
IncorrectOwnerException()
} else {
null
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions docs/content/Reference/configuration.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
KGraphQL schema allows configuration of following properties:
KGraphQL schema allows configuration of the following properties:

| Property | Description | Default value |
|--------------------------------|----------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| useDefaultPrettyPrinter | Schema pretty prints JSON reponses | `false` |
| useDefaultPrettyPrinter | Schema pretty prints JSON reponses | `false` |
| useCachingDocumentParser | Schema caches parsed query documents | `true` |
| documentParserCacheMaximumSize | Schema document cache maximum size | `1000` |
| objectMapper | Schema is using Jackson ObjectMapper from this property | result of `jacksonObjectMapper()` from [jackson-kotlin-module](https://github.com/FasterXML/jackson-module-kotlin) |
| acceptSingleValueAsArray | Schema accepts single argument values as singleton list | `true`
| acceptSingleValueAsArray | Schema accepts single argument values as singleton list | `true` |
| coroutineDispatcher | Schema is using CoroutineDispatcher from this property | [CommonPool](https://github.com/Kotlin/kotlinx.coroutines/blob/master/kotlinx-coroutines-core/src/main/kotlin/kotlinx/coroutines/experimental/CommonPool.kt) |
| executor | | [Executor.Parallel](https://github.com/aPureBase/KGraphQL/blob/master/kgraphql/src/main/kotlin/com/apurebase/kgraphql/schema/execution/Executor.kt) |
| genericTypeResolver | Schema is using generic type resolver from this property | [GenericTypeResolver.DEFAULT](https://github.com/aPureBase/KGraphQL/blob/master/kgraphql/src/main/kotlin/com/apurebase/kgraphql/schema/execution/GenericTypeResolver.kt) |
Expand Down
20 changes: 17 additions & 3 deletions docs/content/Reference/deprecation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,20 @@
title: Deprecation
---

Schema creator is able to deprecate fields, operations and enum values. DSL builders for those schema elements expose
method `deprecate(reason: String)`. Deprecation is visible in schema introspection system with fields
`isDeprecated : Boolean` and `deprecationReason: String`.
Schema creator is able to deprecate fields, operations, enum values, and input values. DSL builders for those schema
elements expose method `deprecate(reason: String)`. Deprecation is visible in schema introspection system with fields
`isDeprecated: Boolean` and `deprecationReason: String`.

Input values may only be deprecated if they are not required, cf. [3.13.3@deprecated](https://spec.graphql.org/draft/#sec--deprecated).

*Example*

```kotlin
data class Sample(val content: String)

type<Sample> {
Sample::content.configure {
deprecate("deprecated property")
}
}
```
8 changes: 4 additions & 4 deletions docs/content/Reference/operations.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ Subscription is not supported yet.
*Example*

```kotlin
data class Hero(val name : String, val age : Int)
data class Hero(val name: String, val age: Int)

query("hero"){
query("hero") {
description = "returns formatted name of R2-D2"
resolver { -> Hero("R2-D2", 40) }
}
Expand All @@ -48,9 +48,9 @@ for name or age, example query: `{hero{name, age}}`
*Example*

```kotlin
mutation("createHero"){
mutation("createHero") {
description = "Creates hero with specified name"
resolver { name : String -> name }
resolver { name: String -> name }
}
```

Expand Down
4 changes: 2 additions & 2 deletions docs/content/Reference/resolver.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ provide any. it is matched by argument name.

```kotlin
KGraphQL.schema {
query("data"){
query("data") {
resolver { int: Int, string: String? -> int }.withArgs {
arg <Int> { name = "int"; defaultValue = 33 }
arg<Int> { name = "int"; defaultValue = 33 }
}
}
}
Expand Down