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

How to replace the whole engine #1124

Closed
andimarek opened this issue Feb 16, 2025 · 3 comments
Closed

How to replace the whole engine #1124

andimarek opened this issue Feb 16, 2025 · 3 comments
Labels
for: external-project Needs a change in external project status: superseded Issue is superseded by another type: enhancement A general enhancement

Comments

@andimarek
Copy link
Contributor

Hi,

how would I replace the whole GraphQL Java engine with a custom implementation in Spring GraphQL?

What I mean is:

I would like to implement a custom ExecutionGraphQlService and therefore use all the transport level support, but everything else is custom.

I will also not have any Schema file (therefore the GraphQlAutoConfiguration will not run) or any Controller with mappings.

How would that look like in Spring GraphQL?

If I register just a custom ExecutionGraphQlService and a custom GraphQlProperties that causes the following error:

Parameter 2 of method graphQlRouterFunction in org.springframework.boot.autoconfigure.graphql.reactive.GraphQlWebFluxAutoConfiguration required a bean of type 'org.springframework.graphql.execution.GraphQlSource' that could not be found.

But I don't want any GraphQlSource instance.

Btw: I understand that this is not a common use case and it maybe very well out of scope, but nevertheless it would be great to be able to reuse all the awesome HTTP/Transport logic in Spring GraphQL.

Thanks team!

@rstoyanchev
Copy link
Contributor

Some initial thoughts below, but not knowing the exact situation, it may take a bit of back and forth.

I'm wondering if you really need to replace DefaultExecutionGraphQlService? At that level we don't care about controllers and mappings. It's just about calling the GraphQL Java engine.

graphQlRouterFunction needs GraphQlSource for the handler that prints the schema. GraphQLSource is a trivial interface that you could just implement without involving on any of the supporting infrastructure. Or you could also extend AbstractGraphQlSourceBuilder, which does not make assumptions about how GraphQLSchema is prepared.

@bclozel
Copy link
Member

bclozel commented Feb 17, 2025

I had a look at the current state of the Spring Boot auto-configuration and in fact we should probably untangle the main auto-configuration from the transports one.

Currently GraphQlProperties binds:

  • spring.graphql.schema.* for schema setup, inspection, printer and introspection
  • spring.graphql.path is for the HTTP transport only
  • spring.graphql.graphiql.* for GraphiQL
  • and then spring.graphql.websocket.*, spring.graphql.rsocket.*, spring.graphql.sse.* for other transports

Maybe we should ensure that transport properties are still bound even if the main auto-configuration is not considered. This would solve the GraphQlProperties bean issue. In the process, we should rename spring.graphql.path to spring.graphql.http.path.

The main auto-configuration is processed (and so the properties are bound) only if one of the following is true:

  • schema files are found in the GraphQlProperties configured locations
  • one or more GraphQlSourceBuilderCustomizer beans are present
  • a GraphQlSource bean is present

This sounds reasonable. I think the second problem comes from the fact that the HTTP transport expects both an ExecutionGraphQlService and a GraphQlSource bean. I think we should make the GraphQlSource bean optional in the HTTP transport auto-configuration.

Those changes sound quite sensible, independently of this use case being considered.

@bclozel
Copy link
Member

bclozel commented Feb 28, 2025

I took care of the Spring Boot side of things in spring-projects/spring-boot#44495.
I don't think there is anything else to cover here, so I'm closing this issue for now.
We can reopen if we miss something here.

@bclozel bclozel closed this as not planned Won't fix, can't repro, duplicate, stale Feb 28, 2025
@bclozel bclozel added type: enhancement A general enhancement status: superseded Issue is superseded by another for: external-project Needs a change in external project labels Feb 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project Needs a change in external project status: superseded Issue is superseded by another type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants