-
Notifications
You must be signed in to change notification settings - Fork 68
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
SpqrWebSocketAutoConfiguration is too specific #79
Comments
As a workaround, I have to reimplement and disable like so /**
* Reimplemented the io.leangen.graphql.spqr.spring.autoconfigure.SpqrWebSocketAutoConfiguration
* make sure to set the property "graphql.spqr.ws.enabled" to false
*/
@Configuration
@EnableWebSocket
@Slf4j
public class WebSocketSecurityConfigurer implements WebSocketConfigurer {
private final GraphQL graphQL;
private final SpqrProperties config;
private final DataLoaderRegistryFactory dataLoaderRegistryFactory;
@Autowired
@SuppressWarnings("OptionalUsedAsFieldOrParameterType")
public WebSocketSecurityConfigurer(GraphQL graphQL, SpqrProperties config,
Optional<DataLoaderRegistryFactory> dataLoaderRegistryFactory) {
this.graphQL = graphQL;
this.config = config;
this.dataLoaderRegistryFactory = dataLoaderRegistryFactory.orElse(null);
}
@Override
public void registerWebSocketHandlers(WebSocketHandlerRegistry webSocketHandlerRegistry) {
String webSocketEndpoint = config.getWs().getEndpoint();
String graphQLEndpoint = config.getHttp().getEndpoint();
String endpointUrl = webSocketEndpoint == null ? graphQLEndpoint : webSocketEndpoint;
boolean keepAliveEnabled = config.getWs().getKeepAlive().isEnabled();
int keepAliveInterval = config.getWs().getKeepAlive().getIntervalMillis();
SecuredWebSocketContextFactory connectionFactory = new SecuredWebSocketContextFactory();
AuthorizedGraphQLWebSocketExecutor executor = new AuthorizedGraphQLWebSocketExecutor(connectionFactory, dataLoaderRegistryFactory);
WebSocketHandler apolloHandler = new PerConnectionApolloHandler(graphQL, executor, keepAliveEnabled ? defaultTaskScheduler() : null, keepAliveInterval);
WebSocketHandler securityHandler = new BearerTokenWebSocketHandler(apolloHandler);
webSocketHandlerRegistry
.addHandler(securityHandler, endpointUrl)
.setAllowedOrigins(config.getWs().getAllowedOrigins());
}
private TaskScheduler defaultTaskScheduler() {
ThreadPoolTaskScheduler threadPoolScheduler = new ThreadPoolTaskScheduler();
threadPoolScheduler.setThreadNamePrefix("GraphQLWSKeepAlive-");
threadPoolScheduler.setPoolSize(Runtime.getRuntime().availableProcessors());
threadPoolScheduler.setRemoveOnCancelPolicy(true);
threadPoolScheduler.setRejectedExecutionHandler(new ThreadPoolExecutor.DiscardPolicy());
threadPoolScheduler.initialize();
return threadPoolScheduler;
}
} |
kaqqao
added a commit
that referenced
this issue
Aug 10, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Firstly, great work so far on this package.
The
SpqrWebSocketAutoConfiguration
defines a number of beans used to set up WebSocket handlers. I need to decorate the defaultWebSocketHandler
to add extra functionality, without reimplementing it.My attempt at a configuration class to override the
SpqrWebSocketAutoConfiguration
:I think customization of this could be simplified by providing better access to the
webSocketHandlerRegistry
to configure the handlers and interceptors, and separating theGraphQL
andSpqrProperties
logic out from theConditionalOnMissingBean
definitions so it can be reused if you only want to extend the existing configuration.If I find time I'll make a PR with some of the above for your consideration.
The text was updated successfully, but these errors were encountered: