Skip to content

Commit

Permalink
Merge pull request #737 from heoYH/master
Browse files Browse the repository at this point in the history
bugfix : graphiql/index.html does not replace fetch path
  • Loading branch information
berngp committed Nov 23, 2021
2 parents 719a0a3 + 42cd0fe commit 13add6b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
Expand Up @@ -31,20 +31,22 @@ import com.netflix.graphql.dgs.webflux.handlers.DgsWebfluxHttpHandler
import com.netflix.graphql.dgs.webflux.handlers.WebFluxCookieValueResolver
import graphql.ExecutionInput
import graphql.GraphQL
import graphql.execution.*
import graphql.execution.AsyncExecutionStrategy
import graphql.execution.AsyncSerialExecutionStrategy
import graphql.execution.DataFetcherExceptionHandler
import graphql.execution.ExecutionIdProvider
import graphql.execution.ExecutionStrategy
import graphql.execution.instrumentation.ChainedInstrumentation
import graphql.introspection.IntrospectionQuery
import graphql.schema.GraphQLSchema
import org.springframework.beans.factory.annotation.Qualifier
import org.springframework.beans.factory.annotation.Value
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
import org.springframework.boot.context.properties.EnableConfigurationProperties
import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.core.env.Environment
import org.springframework.core.io.Resource
import org.springframework.http.MediaType
import org.springframework.web.reactive.function.server.RequestPredicates.accept
import org.springframework.web.reactive.function.server.RouterFunction
Expand Down Expand Up @@ -113,14 +115,11 @@ open class DgsWebFluxAutoConfiguration(private val configProps: DgsWebfluxConfig

@Bean
@ConditionalOnProperty(name = ["dgs.graphql.graphiql.enabled"], havingValue = "true", matchIfMissing = true)
open fun graphiQlIndexRedirect(@Value("classpath:/static/graphiql/index.html") indexHtml: Resource): RouterFunction<ServerResponse> {
open fun graphiQlIndexRedirect(): RouterFunction<ServerResponse> {
return RouterFunctions.route()
.GET(configProps.graphiql.path) {
permanentRedirect(URI.create(configProps.graphiql.path + "/index.html")).build()
}
.GET(configProps.graphiql.path + "/index.html") {
ok().bodyValue(indexHtml)
}
.build()
}

Expand Down
Expand Up @@ -33,7 +33,7 @@ class GraphiQlConfigurer(private val configProps: DgsWebfluxConfigurationPropert
override fun addResourceHandlers(registry: ResourceHandlerRegistry) {
val graphqlPath = configProps.path
registry
.addResourceHandler("/graphiql/**")
.addResourceHandler(configProps.graphiql.path + "/**")
.addResourceLocations("classpath:/static/graphiql/")
.resourceChain(true)
.addResolver(PathResourceResolver())
Expand All @@ -53,7 +53,7 @@ class GraphiQlConfigurer(private val configProps: DgsWebfluxConfigurationPropert
resource: Resource,
transformerChain: ResourceTransformerChain
): Mono<Resource> {
if (exchange.request.uri.toASCIIString().endsWith("graphiql/index.html")) {
if (exchange.request.uri.toASCIIString().endsWith(configProps.graphiql.path + "/index.html")) {
val content = resource.inputStream.bufferedReader().use(BufferedReader::readText)
return Mono.just(
TransformedResource(
Expand Down
Expand Up @@ -17,11 +17,13 @@
package com.netflix.graphql.dgs.webflux.autoconfiguration

import com.netflix.graphql.dgs.autoconfig.DgsAutoConfiguration
import graphql.Assert
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.web.reactive.server.WebTestClient
import org.springframework.test.web.reactive.server.expectBody
import org.springframework.web.reactive.config.EnableWebFlux

@AutoConfigureWebTestClient
Expand All @@ -48,5 +50,7 @@ class GraphiQlCustomEndpoint {
.exchange()
.expectStatus()
.is2xxSuccessful
.expectBody<String>()
.consumeWith { it -> Assert.assertTrue(it.responseBody!!.contains("fetch('/graphql")) }
}
}

0 comments on commit 13add6b

Please sign in to comment.