Skip to content

Commit 798ff31

Browse files
smyrickShane Myrickdariuszkuc
authored
[docs] Add server http req/res page (ExpediaGroup#773)
* Add server http req/res page * PR comments * Update README.md Co-authored-by: Dariusz Kuc <[email protected]> * Apply suggestions from code review Co-authored-by: Dariusz Kuc <[email protected]> * Update http-request-response.md Co-authored-by: Shane Myrick <[email protected]> Co-authored-by: Dariusz Kuc <[email protected]>
1 parent efaa3a9 commit 798ff31

File tree

11 files changed

+147
-56
lines changed

11 files changed

+147
-56
lines changed

README.md

Lines changed: 13 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
[![codecov](https://codecov.io/gh/ExpediaGroup/graphql-kotlin/branch/master/graph/badge.svg)](https://codecov.io/gh/ExpediaGroup/graphql-kotlin)
66
[![Slack](https://img.shields.io/badge/Slack-%23graphql--kotlin-ECB22E.svg?logo=data:image/svg+xml;base64,PHN2ZyB2aWV3Qm94PSIwIDAgNTQgNTQiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGcgZmlsbD0ibm9uZSIgZmlsbC1ydWxlPSJldmVub2RkIj48cGF0aCBkPSJNMTkuNzEyLjEzM2E1LjM4MSA1LjM4MSAwIDAgMC01LjM3NiA1LjM4NyA1LjM4MSA1LjM4MSAwIDAgMCA1LjM3NiA1LjM4Nmg1LjM3NlY1LjUyQTUuMzgxIDUuMzgxIDAgMCAwIDE5LjcxMi4xMzNtMCAxNC4zNjVINS4zNzZBNS4zODEgNS4zODEgMCAwIDAgMCAxOS44ODRhNS4zODEgNS4zODEgMCAwIDAgNS4zNzYgNS4zODdoMTQuMzM2YTUuMzgxIDUuMzgxIDAgMCAwIDUuMzc2LTUuMzg3IDUuMzgxIDUuMzgxIDAgMCAwLTUuMzc2LTUuMzg2IiBmaWxsPSIjMzZDNUYwIi8+PHBhdGggZD0iTTUzLjc2IDE5Ljg4NGE1LjM4MSA1LjM4MSAwIDAgMC01LjM3Ni01LjM4NiA1LjM4MSA1L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+&labelColor=611f69)](https://kotlinlang.slack.com/messages/graphql-kotlin/)
77

8-
GraphQL Kotlin is a collection of libraries, built on top of [graphql-java](https://www.graphql-java.com/), that aim to simplify running GraphQL in Kotlin
8+
GraphQL Kotlin is a collection of libraries, built on top of [graphql-java](https://www.graphql-java.com/), that aim to simplify running GraphQL clients and servers in Kotlin.
9+
10+
Visit our [documentation site](https://expediagroup.github.io/graphql-kotlin) for more details.
911

1012
## 📦 Modules
1113

@@ -15,48 +17,25 @@ GraphQL Kotlin is a collection of libraries, built on top of [graphql-java](http
1517
* [graphql-kotlin-schema-generator](/graphql-kotlin-schema-generator) - Code only GraphQL schema generation for Kotlin
1618
* [graphql-kotlin-spring-server](/graphql-kotlin-spring-server) - Spring Boot auto-configuration library to create a GraphQL server
1719
* [graphql-kotlin-types](/graphql-kotlin-types) - Core types used by both client and server
18-
* [plugins](/plugins) - GraphQL Kotlin Gradle and Maven plugins
20+
* [plugins](/plugins) - Gradle and Maven plugins
1921

2022
## ⌨️ Usage
2123

22-
Below is a basic example of how you can use [graphql-kotlin-spring-server](/graphql-kotlin-spring-server) to run a GraphQL server. For more details, see our documentation below or in the individual module READMEs
23-
24-
```kotlin
25-
// Simple data class that is parsed by the schema generator
26-
data class Widget(val id: Int, val value: String)
27-
28-
// Mark the class as a Spring GraphQL Query
29-
@Component
30-
class WidgetService : Query {
31-
fun widgetById(id: Int): Widget? = null
32-
}
33-
34-
@SpringBootApplication
35-
class Application
24+
While all the individual modules of `graphql-kotlin` are published as stand-alone libraries, the most common use cases are running a server, and genereating a type-safe client.
3625

37-
fun main(args: Array<String>) {
38-
runApplication<Application>(*args)
39-
}
40-
```
26+
### Server Example
4127

42-
will generate a server at `/graphql` and `/playground` with the following schema
28+
A basic example of how you can use [graphql-kotlin-spring-server](/graphql-kotlin-spring-server) to run a GraphQL server can be found on our [server documentation section](https://expediagroup.github.io/graphql-kotlin/docs/spring-server/spring-overview).
4329

44-
```graphql
45-
type Query {
46-
widgetById(id: Int!): Widget
47-
}
30+
### Client Example
4831

49-
type Widget {
50-
id: Int!
51-
value: String!
52-
}
53-
```
32+
A basic setup of [graphql-kotlin-client](/graphql-kotlin-client) can be found on our [client documentation section](https://expediagroup.github.io/graphql-kotlin/docs/client/client-overview).
5433

5534
## 📋 Documentation
5635

57-
Examples and documentation are available on our [documentation site](https://expediagroup.github.io/graphql-kotlin) hosted in GitHub Pages.
36+
More examples and documentation are available on our [documentation site](https://expediagroup.github.io/graphql-kotlin) hosted in GitHub Pages. We also have the [examples](https://github.com/ExpediaGroup/graphql-kotlin/tree/master/examples) module which can be run locally for testing and shows example code using the libraries.
5837

59-
If you have a question about something you can not find in our documentation, the indivdual module READMEs, or [javadocs](https://www.javadoc.io/doc/com.expediagroup/graphql-kotlin-schema-generator), feel free to [create an issue](https://github.com/ExpediaGroup/graphql-kotlin/issues) and tag it with the question label.
38+
If you have a question about something you can not find in our documentation, the indivdual module READMEs, or [javadocs](https://www.javadoc.io/doc/com.expediagroup/graphql-kotlin-schema-generator), feel free to contribute to the docs or [create an issue](https://github.com/ExpediaGroup/graphql-kotlin/issues) and tag it with the question label.
6039

6140
If you would like to contribute to our documentation see the [website](/website) directory for more information.
6241

@@ -80,12 +59,12 @@ To get started, please fork the repo and checkout a new branch. You can then bui
8059
./gradlew clean build
8160
```
8261

83-
8462
See more info in [CONTRIBUTING.md](CONTRIBUTING.md)
8563

8664
## 🛡️ Security
8765

88-
For more info on how to contact the team for security issues or the supported versions that recieve security updates, see [SECURITY.md](./.github/SECURITY.md).
66+
For more info on how to contact the team for security issues or the supported versions that recieve security updates, see [SECURITY.md](./.github/SECURITY.md)
8967

9068
## ⚖️ License
69+
9170
This library is licensed under the [Apache License, Version 2.0](LICENSE)

docs/federated/apollo-federation.md

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,80 @@ feasible making it much harder to manage and leading to unnecessary bottlenecks.
99
an API gateway and a number of smaller GraphQL services behind it alleviates some of those problems and allows teams to
1010
scale their graphs more easily.
1111

12-
[Apollo Federation](https://www.apollographql.com/docs/apollo-server/federation/introduction/) is an architecture for
13-
composing multiple GraphQL services into a single graph. Federated schemas rely on a number of custom directives to
14-
instrument the behavior of the underlying graph and convey the relationships between different schema types. Each individual
15-
GraphQL server generates a valid GraphQL schema and can be run independently. This is in contrast with traditional schema
16-
stitching approach where relationships between individual services, i.e. linking configuration, is configured at the GraphQL
12+
[Apollo Federation](https://www.apollographql.com/docs/apollo-server/federation/introduction/) is an architecture for
13+
composing multiple GraphQL services into a single graph. Federated schemas rely on a number of custom directives to
14+
instrument the behavior of the underlying graph and convey the relationships between different schema types. Each individual
15+
GraphQL server generates a valid GraphQL schema and can be run independently. This is in contrast with traditional schema
16+
stitching approach where relationships between individual services, i.e. linking configuration, is configured at the GraphQL
1717
Gateway level.
18+
19+
## Install
20+
Using a JVM dependency manager, simply link `graphql-kotlin-federation` to your project.
21+
22+
With Maven:
23+
24+
```xml
25+
<dependency>
26+
<groupId>com.expediagroup</groupId>
27+
<artifactId>graphql-kotlin-federation</artifactId>
28+
<version>${latestVersion}</version>
29+
</dependency>
30+
```
31+
32+
With Gradle:
33+
34+
```kotlin
35+
implementation("com.expediagroup", "graphql-kotlin-federation", latestVersion)
36+
```
37+
38+
39+
## Usage
40+
41+
`graphql-kotlin-federation` build on top of `graphql-kotlin-schema-generator` and adds a few extra methods and class to use to generate federation
42+
compliant schemas.
43+
44+
### `toFederatedSchema`
45+
46+
47+
Just like the basic [toSchema](../schema-generator/schema-generator-getting-started.md), `toFederatedSchema` accepts four parameters: `config`, `queries`, `mutations` and `subscriptions`.
48+
The difference is that the `config` class is of type [FederatedSchemaGeneratorConfig](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/graphql-kotlin-federation/src/main/kotlin/com/expediagroup/graphql/federation/FederatedSchemaGeneratorConfig.kt).
49+
This class extends the [base configuration class](../schema-generator/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.
50+
51+
You can see the definition for `toFederatedSchema` [in the
52+
source](https://github.com/ExpediaGroup/graphql-kotlin/blob/master/graphql-kotlin-federation/src/main/kotlin/com/expediagroup/graphql/federation/toFederatedSchema.kt)
53+
54+
## Example
55+
56+
```kotlin
57+
@KeyDirective(fields = FieldSet("id"))
58+
data class User(
59+
val id: ID,
60+
val name: String
61+
)
62+
63+
class Query {
64+
fun getUsers(): List<User> = getUsersFromDB()
65+
}
66+
67+
val config = FederatedSchemaGeneratorConfig(
68+
supportedPackages = "com.example"
69+
)
70+
71+
toFederatedSchema(
72+
config = config,
73+
queries = listOf(TopLevelObject(Query()))
74+
)
75+
```
76+
77+
will generate
78+
79+
```graphql
80+
type Query {
81+
getUsers: [User!]!
82+
}
83+
84+
type User @key(fields : "id") {
85+
id: ID!
86+
name: String!
87+
}
88+
```

docs/getting-started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,8 @@ Repository](https://search.maven.org/artifact/com.expediagroup/graphql-kotlin-sp
4848

4949
### Gradle
5050

51-
```groovy
52-
compile(group: 'com.expediagroup', name: 'graphql-kotlin-spring-server', version: "$latestVersion")
51+
```kotlin
52+
implementation("com.expediagroup", "graphql-kotlin-spring-server", latestVersion)
5353
```
5454

5555
## Generating a Schema

docs/schema-generator/execution/contextual-data.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,5 +52,8 @@ type Query {
5252

5353
Note that the argument that implements `GraphQLContext` is not reflected in the GraphQL schema.
5454

55+
## Spring Server
56+
For more details on how to create the context while using `graphql-kotlin-spring-server` see the [spring graphql context page](../../spring-server/spring-graphql-context.md).
57+
5558
### Customization
5659
The context is injected into the execution through the `FunctionDataFetcher` class. If you want to customize the logic on how the context is determined, that is possible to override. See more details on the [Fetching Data documentation](./fetching-data)

docs/schema-generator/schema-generator-getting-started.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,27 @@ id: schema-generator-getting-started
33
title: Getting Started with the Schema Generator
44
---
55

6+
## Install
7+
Using a JVM dependency manager, simply link `graphql-kotlin-schema-generator` to your project.
8+
9+
With Maven:
10+
11+
```xml
12+
<dependency>
13+
<groupId>com.expediagroup</groupId>
14+
<artifactId>graphql-kotlin-schema-generator</artifactId>
15+
<version>${latestVersion}</version>
16+
</dependency>
17+
```
18+
19+
With Gradle:
20+
21+
```kotlin
22+
implementation("com.expediagroup", "graphql-kotlin-schema-generator", latestVersion)
23+
```
24+
25+
## Usage
26+
627
`graphql-kotlin-schema-generator` provides a single function, `toSchema`, to generate a schema from Kotlin objects.
728

829
```kotlin
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
id: http-request-response
3+
title: Access the HTTP Request-Response
4+
---
5+
6+
GraphQL is strongly typed and any data that is not part of the schema is no longer automatically known by the clients. Relying on this information becomes an "undocumented" part of your API. As a result, by default, GraphQL query resolvers do not have access to the raw HTTP request and response objects.
7+
8+
That being said, there are some common use cases (like authorization) that require inspecting HTTP headers.
9+
10+
## GraphQL Context
11+
12+
The most common way to access the raw HTTP request and response objects is to process them when creating the GraphQLContext through the Spring bean [GraphQLContextFactory](./spring-graphql-context.md). Using the factory you can then extract the information from the incoming request and store it in the context so it can be accessed from any resolver.

docs/spring-server/spring-overview.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,11 @@ title: Spring Server Overview
77
is a Spring Boot auto-configuration library that automatically configures beans required to start up a reactive GraphQL
88
web server.
99

10-
This library is built on a [Spring WebFlux (reactive)](https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html) stack which is a non-blocking alternative to a traditional [Spring Web MVC (servlet)](https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html) based stack. Since both frameworks utilize different threading models they cannot and should not be intermixed. When building a GraphQL server using `graphql-kotlin-spring-server` all your queries and mutations should follow one of the supported [asynchronous execution models](https://expediagroup.github.io/graphql-kotlin/docs/execution/async-models).
10+
## WebFlux vs WebMVC
11+
12+
This library is built on a [Spring WebFlux (reactive)](https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html) stack which is a non-blocking alternative to a traditional [Spring Web MVC (servlet)](https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html) based stack.
13+
Since both frameworks utilize different threading models they cannot and should not be intermixed.
14+
When building a GraphQL server using `graphql-kotlin-spring-server` all your queries and mutations should follow one of the supported [asynchronous execution models](https://expediagroup.github.io/graphql-kotlin/docs/execution/async-models).
1115

1216
## Setup
1317

@@ -29,8 +33,8 @@ With Maven:
2933

3034
With Gradle:
3135

32-
```groovy
33-
compile(group: 'com.expediagroup', name: 'graphql-kotlin-spring-server', version: "$latestVersion")
36+
```kotlin
37+
implementation("com.expediagroup", "graphql-kotlin-spring-server", latestVersion)
3438
```
3539

3640
## Configuration
@@ -104,4 +108,4 @@ Your newly created GraphQL server starts up with following preconfigured default
104108
* **/graphql** - GraphQL server endpoint used for processing queries and mutations
105109
* **/subscriptions** - GraphQL server endpoint used for processing subscriptions
106110
* **/sdl** - Convenience endpoint that returns current schema in Schema Definition Language format
107-
* **/playground** - Prisma Labs GraphQL Playground IDE endpoint
111+
* **/playground** - Prisma Labs [GraphQL Playground IDE](https://github.com/prisma-labs/graphql-playground) endpoint

graphql-kotlin-federation/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ With Maven:
2929

3030
With Gradle:
3131

32-
```groovy
33-
compile(group: 'com.expediagroup', name: 'graphql-kotlin-federation', version: "$latestVersion")
32+
```kotlin
33+
implementation("com.expediagroup", "graphql-kotlin-federation", latestVersion)
3434
```
3535

3636
## Usage

graphql-kotlin-schema-generator/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ With Maven:
2424

2525
With Gradle:
2626

27-
```groovy
28-
compile(group: 'com.expediagroup', name: 'graphql-kotlin-schema-generator', version: "$latestVersion")
27+
```kotlin
28+
implementation("com.expediagroup", "graphql-kotlin-schema-generator", latestVersion)
2929
```
3030

3131
## Usage
@@ -40,7 +40,7 @@ class WidgetService {
4040
fun widgetById(id: Int): Widget? {
4141
// grabs widget from a data source, might return null
4242
}
43-
43+
4444
@Deprecated("Use widgetById")
4545
fun widgetByValue(value: String): Widget? {
4646
// grabs widget from a deprecated data source, might return null
@@ -72,7 +72,7 @@ schema {
7272

7373
type Query {
7474
widgetById(id: Int!): Widget
75-
75+
7676
widgetByValue(vale: String!): Widget @deprecated(reason: "Use widgetById")
7777
}
7878

graphql-kotlin-spring-server/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
[![Maven Central](https://img.shields.io/maven-central/v/com.expediagroup/graphql-kotlin-spring-server.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22com.expediagroup%22%20AND%20a:%22graphql-kotlin-spring-server%22)
33
[![Javadocs](https://img.shields.io/maven-central/v/com.expediagroup/graphql-kotlin-spring-server.svg?label=javadoc&colorB=brightgreen)](https://www.javadoc.io/doc/com.expediagroup/graphql-kotlin-spring-server)
44

5-
`graphql-kotlin-spring-server` is a Spring Boot autoconfiguration library that automatically configures beans required to start up reactive GraphQL web server.
5+
`graphql-kotlin-spring-server` is a Spring Boot autoconfiguration library that automatically configures beans required to start up reactive GraphQL web server.
66

77

88
## Installation
@@ -21,8 +21,8 @@ With Maven:
2121

2222
With Gradle:
2323

24-
```groovy
25-
compile(group: 'com.expediagroup', name: 'graphql-kotlin-spring-server', version: "$latestVersion")
24+
```kotlin
25+
implementation("com.expediagroup", "graphql-kotlin-spring-server", latestVersion)
2626
```
2727

2828
## Usage
@@ -31,15 +31,15 @@ At a minimum, in order for `graphql-kotlin-spring-server` to automatically confi
3131

3232
```yaml
3333
graphql:
34-
packages:
34+
packages:
3535
- "com.your.package"
3636
```
3737
3838
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.
3939

4040
```kotlin
4141
@Component
42-
class MyAwesomeQuery : Query {
42+
class MyAwesomeQuery : Query {
4343
fun myAwesomeQuery(): Widget { ... }
4444
}
4545

website/sidebars.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
"spring-server/spring-beans",
6161
"spring-server/spring-properties",
6262
"spring-server/spring-graphql-context",
63+
"spring-server/http-request-response",
6364
"spring-server/subscriptions"
6465
],
6566
"HTTP Client": [

0 commit comments

Comments
 (0)