@whipper slapper's answer worked for me along with some configs in the Application.properties,
@Configuration
@Profile("local")
public class LocalCorsConfiguration {
@Bean
public CorsFilter corsFilter() {
final UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
final CorsConfiguration config = new CorsConfiguration();
config.setAllowCredentials(true);
config.addAllowedOrigin("http://localhost:3000");
config.addAllowedHeader("*");
config.addAllowedMethod("*");
source.registerCorsConfiguration("/graphql/**", config);
return new CorsFilter(source);
}
}
I added the above code to @SpringBootApplication
file underneath the definition function, and to run it in the local
profile I added spring.profiles.active=local
to the application.properties file,
Altogether my application.properties file looked like this
spring.application.name=tut
spring.graphql.graphiql.enabled=true
spring.graphql.cors.allowed-origins='http://localhost:3000'
spring.graphql.cors.allow-credentials=true
graphql.servlet.corsEnabled: true
spring.profiles.active=local