Skip to content

Update the docs with general changes #1113

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

Merged
merged 1 commit into from
Apr 7, 2021
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 RELEASING.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
In order to [release a new version](https://github.com/ExpediaDotCom/graphql-kotlin/releases) we simply need to draft a new release
In order to [release a new version](https://github.com/ExpediaDotCom/graphql-kotlin/releases) we need to draft a new release
and tag the commit. Releases are following [semantic versioning](https://semver.org/) and specify major, minor and patch version.

Once release is published it will trigger corresponding [Github Action](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/.github/workflows/release.yml)
Expand Down
2 changes: 1 addition & 1 deletion generator/graphql-kotlin-federation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ See more

## Installation

Using a JVM dependency manager, simply link `graphql-kotlin-federation` to your project.
Using a JVM dependency manager, link `graphql-kotlin-federation` to your project.

With Maven:

Expand Down
2 changes: 1 addition & 1 deletion generator/graphql-kotlin-schema-generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ For information on `graphql-java`, please visit [GraphQL Java](https://www.graph

## Installation

Using a JVM dependency manager, simply link `graphql-kotlin-schema-generator` to your project.
Using a JVM dependency manager, link `graphql-kotlin-schema-generator` to your project.

With Maven:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import graphql.schema.DataFetchingEnvironment
import java.util.concurrent.CompletableFuture

/**
* Helper method to simply get a value from a registered DataLoader.
* Helper method to get a value from a registered DataLoader.
* The provided key should be the cache key object used to save the value for that particular data loader.
*/
fun <K, V> DataFetchingEnvironment.getValueFromDataLoader(dataLoaderName: String, key: K): CompletableFuture<V> {
Expand Down
4 changes: 2 additions & 2 deletions servers/graphql-kotlin-spring-server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

## Installation

Using a JVM dependency manager, simply link `graphql-kotlin-spring-server` to your project.
Using a JVM dependency manager, link `graphql-kotlin-spring-server` to your project.

With Maven:

Expand Down Expand Up @@ -35,7 +35,7 @@ graphql:
- "com.your.package"
```

In order to expose your queries, mutations and subscriptions in the GraphQL schema you simply need to implement corresponding marker interfaces and they will be automatically picked up by `graphql-kotlin-spring-server` autoconfiguration library.
In order to expose your queries, mutations and subscriptions in the GraphQL schema you need to implement corresponding marker interfaces and they will be automatically picked up by `graphql-kotlin-spring-server` autoconfiguration library.

```kotlin
@Component
Expand Down
Binary file modified website/docs/assets/spring-initializer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions website/docs/getting-started.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ GraphQL Kotlin is a collection of libraries, built on top of [graphql-java](http

## Installation

Using a JVM dependency manager, simply link any `graphql-kotlin-*` library to your project.
Using a JVM dependency manager, link any `graphql-kotlin-*` library to your project.

<Tabs
defaultValue="gradle"
Expand Down Expand Up @@ -45,13 +45,13 @@ implementation("com.expediagroup", "graphql-kotlin-spring-server", latestVersion

You can use `graphql-kotlin-schema-generator` to generate a schema from Kotlin code and expose it with any server library.

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

### Apollo Federation

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

See the docs in [Apollo Federation](./schema-generator/federation/apollo-federation.md).
See the docs in [Apollo Federation](./schema-generator/federation/apollo-federation.mdx).

## Running a Server

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: Advanced Features
## Adding Custom Additional Types

There are a couple ways you can add more types to the schema without having them be directly consumed by a type in your schema.
This may be required for [Apollo Federation](../federation/apollo-federation.md), or maybe adding other interface implementations that are not picked up.
This may be required for [Apollo Federation](../federation/apollo-federation.mdx), or maybe adding other interface implementations that are not picked up.

### `SchemaGenerator::generateSchema`

Expand Down
2 changes: 1 addition & 1 deletion website/docs/schema-generator/execution/contextual-data.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ it is just used to inform the schema generator that this is the class that shoul
class MyGraphQLContext(val customValue: String) : GraphQLContext
```

Then you can just use the class as an argument and it will be automatically injected during execution time.
Then, you can use the class as an argument and it will be automatically injected during execution time.

```kotlin
class ContextualQuery : Query {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
id: apollo-federation
title: Apollo Federation
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

In many cases, exposing single GraphQL API that exposes unified view of all the available data provides tremendous value
to their clients. As the underlying graph scales, managing single monolithic GraphQL server might become less and less
feasible making it much harder to manage and leading to unnecessary bottlenecks. Migrating towards federated model with
Expand All @@ -17,27 +21,35 @@ gateway level.

## Install

Using a JVM dependency manager, simply link `graphql-kotlin-federation` to your project.
Using a JVM dependency manager, link `graphql-kotlin-federation` to your project.

With Maven:
<Tabs
defaultValue="gradle"
values={[
{ label: 'Gradle Kotlin', value: 'gradle' },
{ label: 'Maven', value: 'maven' }
]
}>

```xml
<TabItem value="gradle">

<dependency>
<groupId>com.expediagroup</groupId>
<artifactId>graphql-kotlin-federation</artifactId>
<version>${latestVersion}</version>
</dependency>
```kotlin
implementation("com.expediagroup", "graphql-kotlin-federation", latestVersion)
```

```
</TabItem>
<TabItem value="maven">

With Gradle:
```xml
<dependency>
<groupId>com.expediagroup</groupId>
<artifactId>graphql-kotlin-federation</artifactId>
<version>${latestVersion}</version>
</dependency>
```

```kotlin

implementation("com.expediagroup", "graphql-kotlin-federation", latestVersion)

```
</TabItem>
</Tabs>

## Usage

Expand All @@ -46,7 +58,7 @@ compliant schemas.

### `toFederatedSchema`

Just like the basic [toSchema](../schema-generator-getting-started.md), `toFederatedSchema` accepts four parameters: `config`, `queries`, `mutations` and `subscriptions`.
Just like the basic [toSchema](../schema-generator-getting-started.mdx), `toFederatedSchema` accepts four parameters: `config`, `queries`, `mutations` and `subscriptions`.
The difference is that the `config` class is of type [FederatedSchemaGeneratorConfig](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/generator/graphql-kotlin-federation/src/main/kotlin/com/expediagroup/graphql/generator/federation/FederatedSchemaGeneratorConfig.kt).
This class extends the [base configuration class](../customizing-schemas/generator-config.md) and adds some default logic. You can override the logic if needed, but do so with caution as you may no longer generate a spec compliant schema.

Expand Down
Original file line number Diff line number Diff line change
@@ -1,37 +1,48 @@
---
id: schema-generator-getting-started
title: Getting Started with the Schema Generator
title: Getting Started
---
## Install

Using a JVM dependency manager, simply link `graphql-kotlin-schema-generator` to your project.

With Maven:
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

```xml
## Install

<dependency>
<groupId>com.expediagroup</groupId>
<artifactId>graphql-kotlin-schema-generator</artifactId>
<version>${latestVersion}</version>
</dependency>
Using a JVM dependency manager, link `graphql-kotlin-schema-generator` to your project.

```
<Tabs
defaultValue="gradle"
values={[
{ label: 'Gradle Kotlin', value: 'gradle' },
{ label: 'Maven', value: 'maven' }
]
}>

With Gradle:
<TabItem value="gradle">

```kotlin

implementation("com.expediagroup", "graphql-kotlin-schema-generator", latestVersion)
```

</TabItem>
<TabItem value="maven">

```xml
<dependency>
<groupId>com.expediagroup</groupId>
<artifactId>graphql-kotlin-schema-generator</artifactId>
<version>${latestVersion}</version>
</dependency>
```

</TabItem>
</Tabs>

## Usage

`graphql-kotlin-schema-generator` provides a single function, `toSchema`, to generate a schema from Kotlin objects.

```kotlin

data class Widget(val id: Int, val value: String)

class WidgetQuery {
Expand All @@ -53,13 +64,11 @@ val schema = toSchema(
queries = listOf(TopLevelObject(widgetQuery)),
mutations = listOf(TopLevelObject(widgetMutation))
)

```

will generate:

```graphql

schema {
query: Query
mutation: Mutation
Expand All @@ -77,7 +86,6 @@ type Widget {
id: Int!
value: String!
}

```

Any `public` functions defined on a query, mutation, or subscription Kotlin class will be translated into GraphQL fields on the object
Expand All @@ -96,42 +104,39 @@ custom hooks, supported packages, and name overrides. See the [Generator Configu
You can see the definition for `toSchema` [in the
source](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/generator/graphql-kotlin-schema-generator/src/main/kotlin/com/expediagroup/graphql/generator/toSchema.kt)

## Class `TopLevelObject`
## `TopLevelObject`

`toSchema` uses Kotlin reflection to build a GraphQL schema from given classes using `graphql-java`'s schema builder. We
don't just pass a `KClass` though, we have to actually pass an object, because the functions on the object are
transformed into the data fetchers. In most cases, a `TopLevelObject` can be constructed with just an object:

```kotlin

class Query {
fun getNumber() = 1
}

val topLevelObject = TopLevelObject(Query())

toSchema(config = config, queries = listOf(topLevelObject))

```

In the above case, `toSchema` will use `topLevelObject::class` as the reflection target, and `Query` as the data fetcher
target.


### Dynamic `TopLevelObject`
In a lot of cases, such as with Spring AOP, the object (or bean) being used to generate a schema is a dynamic proxy. In
this case, `topLevelObject::class` is not `Query`, but rather a generated class that will confuse the schema generator.
To specify the `KClass` to use for reflection on a proxy, pass the class to `TopLevelObject`:

```kotlin

@Component
class Query {
@Timed
fun getNumber() = 1
}

val query = getObjectFromBean()
val customDef = TopLevelObject(query, Query::class)

toSchema(config, listOf(customDef))

```
16 changes: 14 additions & 2 deletions website/docs/server/spring-server/spring-beans.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ Many of the beans are conditionally created and the default behavior can be cust

## Non-Federated Schema

_Created only if federation is disabled_
:::note

_Created only if federation is **disabled**_

:::

| Bean | Description |
| :-------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
Expand All @@ -25,7 +29,11 @@ _Created only if federation is disabled_

## Federated Schema

_Created only if federation is enabled_
:::note

_Created only if federation is **enabled**_

:::

| Bean | Description |
| :------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
Expand All @@ -50,8 +58,12 @@ _Created only if federation is enabled_

## Subscriptions

:::note

_Created only if the `Subscription` marker interface is used_

:::

| Bean | Description |
| :-------------------------------------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| SpringGraphQLSubscriptionHandler | Spring reactor code for executing GraphQL subscriptions requests |
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
id: spring-http-request-response
title: HTTP Request and Response
---

To access the HTTP request and response methods, use [Spring WebFilter](https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/server/WebFilter.html).
From these filters you can modify the request and response, both before and after the GraphQL execution.
Loading