Skip to content

Commit

Permalink
Update to graphql-java 19.0 (ExpediaGroup#1491)
Browse files Browse the repository at this point in the history
FlowSubscriptionExecutionStrategy needs to be updated to
pass instrumentationState to instrumentations per
graphql-java/graphql-java#2769

ValidationError string changed slightly so adjust assertions.
  • Loading branch information
josephlbarnett committed Jul 28, 2022
1 parent 2667c5b commit 9ca68d1
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 17 deletions.
Expand Up @@ -16,6 +16,7 @@

package com.expediagroup.graphql.examples.server.spring

import org.hamcrest.core.StringContains
import org.springframework.test.web.reactive.server.WebTestClient

fun WebTestClient.ResponseSpec.verifyOnlyDataExists(expectedQuery: String): WebTestClient.BodyContentSpec {
Expand All @@ -34,10 +35,14 @@ fun WebTestClient.ResponseSpec.verifyData(
.jsonPath("$DATA_JSON_PATH.$expectedQuery").isEqualTo(expectedData)
}

fun WebTestClient.ResponseSpec.verifyError(expectedError: String): WebTestClient.BodyContentSpec {
fun WebTestClient.ResponseSpec.verifyError(expectedErrorSubString: String): WebTestClient.BodyContentSpec {
return this.expectStatus().isOk
.expectBody()
.jsonPath(DATA_JSON_PATH).doesNotExist()
.jsonPath("$ERRORS_JSON_PATH.[0].message").isEqualTo(expectedError)
.verifyError(expectedErrorSubString)
}

fun WebTestClient.BodyContentSpec.verifyError(expectedErrorSubString: String): WebTestClient.BodyContentSpec {
return this.jsonPath(DATA_JSON_PATH).doesNotExist()
.jsonPath("$ERRORS_JSON_PATH.[0].message").value(StringContains.containsString(expectedErrorSubString))
.jsonPath(EXTENSIONS_JSON_PATH).doesNotExist()
}
Expand Up @@ -81,10 +81,11 @@ class PolymorphicQueryIT(@Autowired private val testClient: WebTestClient) {
.bodyValue("query { $query(type: $unknownType) { type, sound } }")
.exchange()
.expectStatus().isOk
.verifyError("Validation error")
.verifyError("WrongType")
.verifyError(
"Validation error of type WrongType: " +
"argument 'type' with value 'EnumValue{name='$unknownType'}' is not a valid 'AnimalType' - " +
"Expected enum literal value not in allowable values - 'EnumValue{name='HELLO'}'. @ 'animal'"
"argument 'type' with value 'EnumValue{name='$unknownType'}' is not a valid 'AnimalType' - " +
"Expected enum literal value not in allowable values - 'EnumValue{name='HELLO'}'"
)
}

Expand Down
Expand Up @@ -73,31 +73,37 @@ class SimpleQueryIT(@Autowired private val testClient: WebTestClient) {
@Test
fun `verify notPartOfSchema query`() {
val query = "notPartOfSchema"
val expectedError = "Validation error of type FieldUndefined: " +
"Field 'notPartOfSchema' in type 'Query' is undefined @ 'notPartOfSchema'"
val expectedErrorOne = "Validation error"
val expectedErrorTwo = "FieldUndefined"
val expectedErrorThree = "Field 'notPartOfSchema' in type 'Query' is undefined"

testClient.post()
.uri(GRAPHQL_ENDPOINT)
.accept(APPLICATION_JSON)
.contentType(GRAPHQL_MEDIA_TYPE)
.bodyValue("query { $query }")
.exchange()
.verifyError(expectedError)
.verifyError(expectedErrorOne)
.verifyError(expectedErrorTwo)
.verifyError(expectedErrorThree)
}

@Test
fun `verify privateFunctionsAreNotVisible query`() {
val query = "privateFunctionsAreNotVisible"
val expectedError = "Validation error of type FieldUndefined: " +
"Field 'privateFunctionsAreNotVisible' in type 'Query' is undefined @ 'privateFunctionsAreNotVisible'"
val expectedErrorOne = "Validation error"
val expectedErrorTwo = "FieldUndefined"
val expectedErrorThree = "Field 'privateFunctionsAreNotVisible' in type 'Query' is undefined"

testClient.post()
.uri(GRAPHQL_ENDPOINT)
.accept(APPLICATION_JSON)
.contentType(GRAPHQL_MEDIA_TYPE)
.bodyValue("query { $query }")
.exchange()
.verifyError(expectedError)
.verifyError(expectedErrorOne)
.verifyError(expectedErrorTwo)
.verifyError(expectedErrorThree)
}

@Test
Expand Down
Expand Up @@ -25,6 +25,8 @@ import graphql.execution.ExecutionStrategy
import graphql.execution.ExecutionStrategyParameters
import graphql.execution.SimpleDataFetcherExceptionHandler
import graphql.execution.SubscriptionExecutionStrategy
import graphql.execution.instrumentation.ExecutionStrategyInstrumentationContext
import graphql.execution.instrumentation.SimpleInstrumentationContext
import graphql.execution.instrumentation.parameters.InstrumentationExecutionParameters
import graphql.execution.instrumentation.parameters.InstrumentationExecutionStrategyParameters
import graphql.execution.instrumentation.parameters.InstrumentationFieldParameters
Expand Down Expand Up @@ -55,7 +57,9 @@ class FlowSubscriptionExecutionStrategy(dfe: DataFetcherExceptionHandler) : Exec

val instrumentation = executionContext.instrumentation
val instrumentationParameters = InstrumentationExecutionStrategyParameters(executionContext, parameters)
val executionStrategyCtx = instrumentation.beginExecutionStrategy(instrumentationParameters)
val executionStrategyCtx = ExecutionStrategyInstrumentationContext.nonNullCtx(
instrumentation.beginExecutionStrategy(instrumentationParameters, executionContext.instrumentationState)
)

val sourceEventStream = createSourceEventStream(executionContext, parameters)

Expand Down Expand Up @@ -142,7 +146,9 @@ class FlowSubscriptionExecutionStrategy(dfe: DataFetcherExceptionHandler) : Exec
val subscribedFieldStepInfo = createSubscribedFieldStepInfo(executionContext, newParameters)

val i13nFieldParameters = InstrumentationFieldParameters(executionContext) { subscribedFieldStepInfo }
val subscribedFieldCtx = instrumentation.beginSubscribedFieldEvent(i13nFieldParameters)
val subscribedFieldCtx = SimpleInstrumentationContext.nonNullCtx(
instrumentation.beginSubscribedFieldEvent(i13nFieldParameters, executionContext.instrumentationState)
)

val fetchedValue = unboxPossibleDataFetcherResult(newExecutionContext, parameters, eventPayload)

Expand All @@ -161,7 +167,7 @@ class FlowSubscriptionExecutionStrategy(dfe: DataFetcherExceptionHandler) : Exec
)

return overallResult.thenCompose { executionResult ->
instrumentation.instrumentExecutionResult(executionResult, i13ExecutionParameters)
instrumentation.instrumentExecutionResult(executionResult, i13ExecutionParameters, executionContext.instrumentationState)
}
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Expand Up @@ -22,7 +22,7 @@ kotlinxSerializationVersion = 1.3.2
androidPluginVersion = 7.1.2
classGraphVersion = 4.8.143
federationGraphQLVersion = 0.9.0
graphQLJavaVersion = 18.0
graphQLJavaVersion = 19.0
graphQLJavaDataLoaderVersion = 3.1.3
jacksonVersion = 2.13.2
kotlinPoetVersion = 1.11.0
Expand Down
Expand Up @@ -18,6 +18,7 @@ package com.expediagroup.graphql.server.spring.execution
import com.expediagroup.graphql.server.operations.Query
import com.expediagroup.graphql.server.types.GraphQLRequest
import graphql.introspection.IntrospectionQuery
import org.hamcrest.core.StringContains
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.autoconfigure.EnableAutoConfiguration
Expand Down Expand Up @@ -50,7 +51,8 @@ class IntrospectionIT(@Autowired private val testClient: WebTestClient) {
.expectBody()
.jsonPath("$.data").doesNotExist()
.jsonPath("$.errors").isArray
.jsonPath("$.errors[0].message").isEqualTo("Validation error of type FieldUndefined: Field 'queryType' in type '__Schema' is undefined @ '__schema/queryType'")
.jsonPath("$.errors[0].message").value(StringContains.containsString("Validation error"))
.jsonPath("$.errors[0].message").value(StringContains.containsString("Field 'queryType' in type '__Schema' is undefined"))
}

@Configuration
Expand Down

0 comments on commit 9ca68d1

Please sign in to comment.