Skip to content

Commit 7348343

Browse files
authored
Refactor to remove build warnings (ExpediaGroup#611)
* Refactor to clean up some build warnings Non-functional change that just adds some internal documentation and cleans up some build and IDE warnings * Suppress unused wanrings in tests * Undo RouteConfiguration changes * Move strings to const * Move constants to internal file reference * Remove unessacary function calls
1 parent 49b7dc5 commit 7348343

File tree

9 files changed

+36
-19
lines changed

9 files changed

+36
-19
lines changed

examples/gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ version = 1.0-SNAPSHOT
44
# build config
55
org.gradle.caching=true
66
org.gradle.parallel=true
7+
kapt.incremental.apt=true

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ version = 2.0.0-SNAPSHOT
44
# build config
55
org.gradle.caching=true
66
org.gradle.parallel=true
7+
kapt.incremental.apt=true
78

89
# See https://github.com/gradle/gradle/issues/11308
910
systemProp.org.gradle.internal.publish.checksums.insecure=true

graphql-kotlin-schema-generator/src/test/kotlin/com/expediagroup/graphql/generator/ToSchemaTest.kt

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@ import kotlin.test.assertNotNull
4444
import kotlin.test.assertNull
4545
import kotlin.test.assertTrue
4646

47-
@Suppress("Detekt.UnusedPrivateMember",
47+
@Suppress(
48+
"Detekt.UnusedPrivateMember",
4849
"Detekt.FunctionOnlyReturningConstant",
4950
"Detekt.LargeClass",
50-
"Detekt.MethodOverloading")
51+
"Detekt.MethodOverloading",
52+
"UNUSED_PARAMETER",
53+
"unused"
54+
)
5155
class ToSchemaTest {
5256

5357
@Test
@@ -452,11 +456,11 @@ class ToSchemaTest {
452456
}
453457

454458
class QueryWithJavaClass {
455-
fun query(): java.net.CookieManager? = CookieManager()
459+
fun query(): CookieManager? = CookieManager()
456460
}
457461

458462
class QueryWithListOfJavaClass {
459-
fun listQuery(): List<java.net.CookieManager> = listOf(CookieManager())
463+
fun listQuery(): List<CookieManager> = listOf(CookieManager())
460464
}
461465

462466
class QueryWithConflictingTypes {

graphql-kotlin-spring-server/src/main/kotlin/com/expediagroup/graphql/spring/RoutesConfiguration.kt

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ import org.springframework.web.reactive.function.server.buildAndAwait
3535
import org.springframework.web.reactive.function.server.coRouter
3636
import org.springframework.web.reactive.function.server.json
3737

38+
internal const val REQUEST_PARAM_QUERY = "query"
39+
internal const val REQUEST_PARAM_OPERATION_NAME = "operationName"
40+
internal const val REQUEST_PARAM_VARIABLES = "variables"
41+
internal val graphQLMediaType = MediaType("application", "graphql")
42+
3843
/**
3944
* Default route configuration for GraphQL service and SDL service endpoints.
4045
*/
@@ -45,7 +50,6 @@ class RoutesConfiguration(
4550
private val queryHandler: QueryHandler,
4651
private val objectMapper: ObjectMapper
4752
) {
48-
private val graphQLMediaType: MediaType = MediaType("application", "graphql")
4953
private val mapTypeReference: MapType = TypeFactory.defaultInstance().constructMapType(HashMap::class.java, String::class.java, Any::class.java)
5054

5155
@Bean
@@ -84,10 +88,10 @@ class RoutesConfiguration(
8488
// https://github.com/FasterXML/jackson-module-kotlin/issues/221
8589
@Suppress("BlockingMethodInNonBlockingContext")
8690
private suspend fun createGraphQLRequest(serverRequest: ServerRequest): GraphQLRequest? = when {
87-
serverRequest.queryParam("query").isPresent -> {
88-
val query = serverRequest.queryParam("query").get()
89-
val operationName: String? = serverRequest.queryParam("operationName").orElseGet { null }
90-
val variables: String? = serverRequest.queryParam("variables").orElseGet { null }
91+
serverRequest.queryParam(REQUEST_PARAM_QUERY).isPresent -> {
92+
val query = serverRequest.queryParam(REQUEST_PARAM_QUERY).get()
93+
val operationName: String? = serverRequest.queryParam(REQUEST_PARAM_OPERATION_NAME).orElseGet { null }
94+
val variables: String? = serverRequest.queryParam(REQUEST_PARAM_VARIABLES).orElseGet { null }
9195
val graphQLVariables: Map<String, Any>? = variables?.let {
9296
objectMapper.readValue(it, mapTypeReference)
9397
}

graphql-kotlin-spring-server/src/test/kotlin/com/expediagroup/graphql/spring/FederationConfigurationTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class FederationConfigurationTest {
132132
)
133133
}
134134

135+
@Suppress("unused")
135136
class FederatedQuery : Query {
136137
fun widget(): Widget = Widget(1, "hello")
137138
}

graphql-kotlin-spring-server/src/test/kotlin/com/expediagroup/graphql/spring/SubscriptionConfigurationTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class SubscriptionConfigurationTest {
139139
fun query(): String = "hello!"
140140
}
141141

142+
@Suppress("unused")
142143
class SimpleSubscription : Subscription {
143144
fun ticker(): Flux<Int> = Flux.range(1, 5)
144145
.delayElements(Duration.ofMillis(100))

graphql-kotlin-spring-server/src/test/kotlin/com/expediagroup/graphql/spring/instrumentation/InstrumentationIT.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ class InstrumentationIT(@Autowired private val testClient: WebTestClient) {
3838
fun secondInstrumentation(): Instrumentation = OrderedInstrumentation(DEFAULT_INSTRUMENTATION_ORDER + 1, atomicCounter)
3939
}
4040

41+
@Suppress("unused")
4142
class BasicQuery : Query {
4243
fun helloWorld(name: String) = "Hello $name!"
4344
}

graphql-kotlin-spring-server/src/test/kotlin/com/expediagroup/graphql/spring/routes/RouteConfigurationIT.kt

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@
1717
package com.expediagroup.graphql.spring.routes
1818

1919
import com.expediagroup.graphql.annotations.GraphQLContext
20+
import com.expediagroup.graphql.spring.REQUEST_PARAM_OPERATION_NAME
21+
import com.expediagroup.graphql.spring.REQUEST_PARAM_QUERY
22+
import com.expediagroup.graphql.spring.REQUEST_PARAM_VARIABLES
2023
import com.expediagroup.graphql.spring.execution.GraphQLContextFactory
24+
import com.expediagroup.graphql.spring.graphQLMediaType
2125
import com.expediagroup.graphql.spring.model.GraphQLRequest
2226
import com.expediagroup.graphql.spring.operations.Query
2327
import com.fasterxml.jackson.module.kotlin.jacksonObjectMapper
@@ -124,7 +128,7 @@ class RouteConfigurationIT(@Autowired private val testClient: WebTestClient) {
124128
testClient.get()
125129
.uri { builder ->
126130
builder.path("/graphql")
127-
.queryParam("query", "{query}")
131+
.queryParam(REQUEST_PARAM_QUERY, "{query}")
128132
.build(query)
129133
}
130134
.exchange()
@@ -139,9 +143,9 @@ class RouteConfigurationIT(@Autowired private val testClient: WebTestClient) {
139143
testClient.get()
140144
.uri { builder ->
141145
builder.path("/graphql")
142-
.queryParam("query", "{query}")
143-
.queryParam("variables", "{variables}")
144-
.queryParam("operationName", "{operationName}")
146+
.queryParam(REQUEST_PARAM_QUERY, "{query}")
147+
.queryParam(REQUEST_PARAM_VARIABLES, "{variables}")
148+
.queryParam(REQUEST_PARAM_OPERATION_NAME, "{operationName}")
145149
.build(query, jacksonObjectMapper().writeValueAsString(variables), operationName)
146150
}
147151
.exchange()
@@ -159,7 +163,7 @@ class RouteConfigurationIT(@Autowired private val testClient: WebTestClient) {
159163
testClient.post()
160164
.uri { builder ->
161165
builder.path("/graphql")
162-
.queryParam("query", "{query}")
166+
.queryParam(REQUEST_PARAM_QUERY, "{query}")
163167
.build("{ hello(name: \"POST query param\") }")
164168
}
165169
.accept(MediaType.APPLICATION_JSON)
@@ -174,7 +178,7 @@ class RouteConfigurationIT(@Autowired private val testClient: WebTestClient) {
174178
testClient.post()
175179
.uri("/graphql")
176180
.accept(MediaType.APPLICATION_JSON)
177-
.contentType(MediaType("application", "graphql"))
181+
.contentType(graphQLMediaType)
178182
.bodyValue("query { hello(name: \"POST application/graphql\") }")
179183
.exchange()
180184
.verifyGraphQLRoute("Hello POST application/graphql!")

graphql-kotlin-spring-server/src/test/kotlin/com/expediagroup/graphql/spring/routes/SubscriptionRoutesConfigurationIT.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
package com.expediagroup.graphql.spring.routes
1818

19+
import com.expediagroup.graphql.spring.REQUEST_PARAM_QUERY
1920
import com.expediagroup.graphql.spring.model.GraphQLRequest
2021
import com.expediagroup.graphql.spring.model.SubscriptionOperationMessage
2122
import com.expediagroup.graphql.spring.operations.Query
@@ -32,7 +33,6 @@ import org.springframework.context.annotation.Bean
3233
import org.springframework.context.annotation.Configuration
3334
import org.springframework.http.MediaType
3435
import org.springframework.test.web.reactive.server.WebTestClient
35-
import org.springframework.web.reactive.socket.WebSocketMessage
3636
import org.springframework.web.reactive.socket.client.ReactorNettyWebSocketClient
3737
import reactor.core.publisher.Flux
3838
import reactor.core.publisher.Mono
@@ -69,6 +69,7 @@ class SubscriptionRoutesConfigurationIT(
6969
fun hello(name: String) = "Hello $name!"
7070
}
7171

72+
@Suppress("unused")
7273
class SimpleSubscription : Subscription {
7374
fun getNumber(): Flux<Int> = Flux.just(42)
7475
}
@@ -96,7 +97,7 @@ class SubscriptionRoutesConfigurationIT(
9697
testClient.get()
9798
.uri { builder ->
9899
builder.path("/foo")
99-
.queryParam("query", "{query}")
100+
.queryParam(REQUEST_PARAM_QUERY, "{query}")
100101
.build(query)
101102
}
102103
.exchange()
@@ -115,8 +116,7 @@ class SubscriptionRoutesConfigurationIT(
115116
val sessionMono = client.execute(uri) { session ->
116117
session.send(Mono.just(session.textMessage(objectMapper.writeValueAsString(message))))
117118
.thenMany(session.receive()
118-
.map(WebSocketMessage::getPayloadAsText)
119-
.map { objectMapper.readValue<SubscriptionOperationMessage>(it) }
119+
.map { objectMapper.readValue<SubscriptionOperationMessage>(it.payloadAsText) }
120120
.map { objectMapper.writeValueAsString(it.payload) }
121121
)
122122
.subscribeWith(output)

0 commit comments

Comments
 (0)