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
fix: GraphiQL may render broken and cannot be fully disabled #1183
fix: GraphiQL may render broken and cannot be fully disabled #1183
Conversation
7407753
to
cee2503
Compare
@srinivasankavitha any way to get 👀 on this? |
@@ -48,6 +48,7 @@ class DgsWebfluxConfigurationProperties( | |||
* Configuration properties for the GraphiQL endpoint. | |||
*/ | |||
data class DgsGraphiQLConfigurationProperties( | |||
@DefaultValue("true") var enabled: Boolean = true, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this used?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's used by Spring's metadata generator. The property isn't used directly by DGS b/c it's referred to in full dot notation as a @Conditional
. This is mainly useful for IDE autocompletion.
Lines 144 to 147 in 8fa2368
@ConditionalOnProperty(name = ["dgs.graphql.graphiql.enabled"], havingValue = "true", matchIfMissing = true) | |
open fun graphiQlConfigurer(configProps: DgsWebfluxConfigurationProperties): GraphiQlConfigurer { | |
return GraphiQlConfigurer(configProps) | |
} |
@@ -35,7 +35,7 @@ class GraphiQlConfigurer(private val configProps: DgsWebfluxConfigurationPropert | |||
val graphiQLTitle = configProps.graphiql.title | |||
registry | |||
.addResourceHandler(configProps.graphiql.path + "/**") | |||
.addResourceLocations("classpath:/static/graphiql/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For my understanding, could you explain why moving the location out of the static directory addresses the race condition?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DGS_GRAPHQL_PATH is sometimes unset because there's a race condition between Spring's built in static resource handler and DGS' GraphiQL handlers in both Spring MVC and WebFlux. The alternative option to changing the path for graphiql would be to force applications to configure spring.web.resources.add-mappings to false; it defaults to true.
So, Spring attempts to serve all assets under resources/static
as static files. This means the resources are served as-is from disk / JAR, and not processed by the DGS handler. Depending on bean registration order, the DGS handler may be registered after Spring's static resource handler.
From my understanding about Spring, it's best NOT to store templates that require server side rendering in /resources/[static|public]
.
cee2503
to
2208027
Compare
Hi @srinivasankavitha , I answered your questions and rebased this on |
2208027
to
90c41b2
Compare
90c41b2
to
f338788
Compare
f338788
to
6741dc3
Compare
Pull request checklist
first
Pull Request type
Changes in this PR
Fix a few issues with GraphiQL:
dgs.graphql.graphiql.enabled
is not recognized as a valid configuration option with WebFluxspring.web.resources.add-mappings
it set totrue
(the default)Alternatives considered
DGS_GRAPHQL_PATH
is sometimes unset because there's a race condition between Spring's built in static resource handler and DGS' GraphiQL handlers in both Spring MVC and WebFlux. The alternative option to changing the path forgraphiql
would be to force applications to configurespring.web.resources.add-mappings
tofalse
; it defaults totrue
.PR #1167 from another contributor, also says it fixes #1135. However, it looks like a different potential issue related non-ASCII data in queries, rather than a fix for this bug.