-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Robert Wiesner
authored
Dec 4, 2022
1 parent
188b8fa
commit 04e29e4
Showing
14 changed files
with
91 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "Spring GraphQL Schema", | ||
"schemaPath": "src/main/resources/graphql/schema.graphqls", | ||
"extensions": {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
7 changes: 3 additions & 4 deletions
7
src/main/kotlin/de/rowi1de/reactive/graphql/model/HelloGraphql.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,17 @@ | ||
package de.rowi1de.reactive.graphql.model | ||
|
||
import com.expediagroup.graphql.generator.annotations.GraphQLDescription | ||
import org.springframework.graphql.data.method.annotation.SchemaMapping | ||
import java.time.ZonedDateTime | ||
|
||
@GraphQLDescription("Simple World") | ||
|
||
|
||
data class HelloGraphql( | ||
|
||
private val name: String | ||
) { | ||
@GraphQLDescription("Say Hello") | ||
val greeting: String | ||
get() = "Hello $name!" | ||
|
||
@GraphQLDescription("Time of greeting") | ||
val time: String | ||
get() = ZonedDateTime.now().toString() | ||
} |
9 changes: 5 additions & 4 deletions
9
src/main/kotlin/de/rowi1de/reactive/graphql/mutation/employees/EmployeesMutation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
package de.rowi1de.reactive.graphql.mutation.employees | ||
|
||
import com.expediagroup.graphql.server.operations.Mutation | ||
import de.rowi1de.reactive.graphql.model.employees.Employee | ||
import de.rowi1de.reactive.graphql.model.employees.NewEmployee | ||
import de.rowi1de.reactive.service.employees.EmployeeService | ||
import org.springframework.stereotype.Component | ||
import org.springframework.graphql.data.method.annotation.MutationMapping | ||
import org.springframework.stereotype.Controller | ||
|
||
@Component | ||
class EmployeesMutation(private val service: EmployeeService) : Mutation { | ||
@Controller | ||
class EmployeesMutation(private val service: EmployeeService) { | ||
|
||
@MutationMapping | ||
suspend fun newEmployee(newEmployee: NewEmployee): Employee = service.addEmployee(newEmployee) | ||
} |
10 changes: 6 additions & 4 deletions
10
src/main/kotlin/de/rowi1de/reactive/graphql/query/BrokenQuery.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 7 additions & 7 deletions
14
src/main/kotlin/de/rowi1de/reactive/graphql/query/HelloQuery.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
package de.rowi1de.reactive.graphql.query | ||
|
||
import com.expediagroup.graphql.generator.annotations.GraphQLDescription | ||
import com.expediagroup.graphql.server.operations.Query | ||
import de.rowi1de.reactive.graphql.model.HelloGraphql | ||
import org.springframework.stereotype.Component | ||
import org.springframework.graphql.data.method.annotation.Argument | ||
import org.springframework.graphql.data.method.annotation.QueryMapping | ||
import org.springframework.stereotype.Controller | ||
|
||
@Component | ||
class HelloQuery : Query { | ||
@Controller | ||
class HelloQuery { | ||
|
||
@GraphQLDescription("Simple Hello World Query") | ||
@QueryMapping | ||
suspend fun hello( | ||
@GraphQLDescription("Who should we greet?") name: String? = null | ||
@Argument name: String? = null | ||
): HelloGraphql = HelloGraphql(name ?: "World") | ||
} |
10 changes: 6 additions & 4 deletions
10
src/main/kotlin/de/rowi1de/reactive/graphql/query/employees/EmployeesQuery.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,17 @@ | ||
package de.rowi1de.reactive.graphql.query.employees | ||
|
||
import com.expediagroup.graphql.server.operations.Query | ||
import de.rowi1de.reactive.graphql.model.employees.Employees | ||
import de.rowi1de.reactive.graphql.model.employees.Teams | ||
import de.rowi1de.reactive.service.employees.EmployeeService | ||
import org.springframework.stereotype.Component | ||
import org.springframework.graphql.data.method.annotation.QueryMapping | ||
import org.springframework.stereotype.Controller | ||
|
||
@Component | ||
class EmployeesQuery(private val service: EmployeeService) : Query { | ||
@Controller | ||
class EmployeesQuery(private val service: EmployeeService) { | ||
|
||
@QueryMapping | ||
suspend fun employees(): Employees = Employees(service.getEmployees()) | ||
|
||
@QueryMapping | ||
suspend fun teams(): Teams = Teams(service.getTeams()) | ||
} |
11 changes: 5 additions & 6 deletions
11
src/main/kotlin/de/rowi1de/reactive/graphql/subscription/HelloSubscription.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
package de.rowi1de.reactive.graphql.subscription | ||
|
||
import com.expediagroup.graphql.generator.annotations.GraphQLDescription | ||
import com.expediagroup.graphql.server.operations.Subscription | ||
import de.rowi1de.reactive.graphql.model.HelloGraphql | ||
import org.springframework.stereotype.Component | ||
import org.springframework.graphql.data.method.annotation.SubscriptionMapping | ||
import org.springframework.stereotype.Controller | ||
import reactor.core.publisher.Flux | ||
import java.time.Duration | ||
|
||
@Component | ||
class HelloSubscription : Subscription { | ||
@GraphQLDescription("Greet every second") | ||
@Controller | ||
class HelloSubscription { | ||
@SubscriptionMapping | ||
suspend fun hello(name: String): Flux<HelloGraphql> = Flux.interval(Duration.ofSeconds(1)) | ||
.map { HelloGraphql("$name $it") } | ||
} |
9 changes: 5 additions & 4 deletions
9
src/main/kotlin/de/rowi1de/reactive/graphql/subscription/employee/EmployeeSubscription.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
package de.rowi1de.reactive.graphql.subscription.employee | ||
|
||
import com.expediagroup.graphql.server.operations.Subscription | ||
import de.rowi1de.reactive.graphql.model.employees.Employee | ||
import de.rowi1de.reactive.service.employees.EmployeeService | ||
import kotlinx.coroutines.reactor.asFlux | ||
import org.springframework.stereotype.Component | ||
import org.springframework.graphql.data.method.annotation.SubscriptionMapping | ||
import org.springframework.stereotype.Controller | ||
import reactor.core.publisher.Flux | ||
|
||
@Component | ||
class EmployeeSubscription(private val service: EmployeeService) : Subscription { | ||
@Controller | ||
class EmployeeSubscription(private val service: EmployeeService) { | ||
@SubscriptionMapping | ||
suspend fun employees(): Flux<Employee> = service.employees().asFlux() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
type Query { | ||
hello(name: String): HelloGraphql! | ||
} | ||
|
||
type HelloGraphql{ | ||
greeting: String! | ||
time: String! | ||
} |