Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix : graphiql/index.html does not replace fetch path #737

Merged
merged 5 commits into from
Nov 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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")) }
}
}