Skip to content

Commit 305cfa4

Browse files
author
Shane Myrick
authored
example: add another nested example (#239)
1 parent 8136a43 commit 305cfa4

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

example/src/main/kotlin/com/expedia/graphql/sample/query/NestedQueries.kt

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.expedia.graphql.sample.query
22

3+
import com.expedia.graphql.annotations.GraphQLDescription
34
import com.fasterxml.jackson.annotation.JsonIgnore
45
import graphql.schema.DataFetcher
56
import graphql.schema.DataFetchingEnvironment
@@ -11,8 +12,11 @@ import org.springframework.context.annotation.Scope
1112
import org.springframework.stereotype.Component
1213

1314
@Component
14-
class NestedQueries : Query {
15+
class NestedQueries(private val coffeeBean: CoffeeBean) : Query {
1516
fun findAnimal(): NestedAnimal = NestedAnimal(1, "cat")
17+
18+
@GraphQLDescription("An exmaple of using data fetcher with out a bean factory")
19+
fun getCoffeeBean(beanName: String) = coffeeBean
1620
}
1721

1822
data class NestedAnimal(
@@ -49,3 +53,17 @@ class AnimalDetailsDataFetcher : DataFetcher<NestedAnimalDetails>, BeanFactoryAw
4953
}
5054
}
5155
}
56+
57+
@Component
58+
class CoffeeBean {
59+
60+
fun icedCofee(environment: DataFetchingEnvironment, size: String): String {
61+
val beanChoice = environment.executionStepInfo.parent.arguments["beanName"]
62+
return "Iced Coffee, Bean choice: $beanChoice, size: $size"
63+
}
64+
65+
fun hotCofee(environment: DataFetchingEnvironment, size: String): String {
66+
val beanChoice = environment.executionStepInfo.parent.arguments["beanName"]
67+
return "Hot Coffee, Bean choice: $beanChoice, size: $size"
68+
}
69+
}

0 commit comments

Comments
 (0)