spring-projects / spring-boot

Spring Boot helps you to create Spring-powered, production-grade applications and services with absolute minimum fuss.
https://spring.io/projects/spring-boot
Apache License 2.0
75.34k stars 40.72k forks source link

Configure specific GraphQL schema files #42792

Open bjoernmayer opened 1 month ago

bjoernmayer commented 1 month ago

Heyho,

it seems like there is currently no way to specify schema files by their filename. Instead it is only possible to configure directories.

From GraphqlProperties.java:

private String[] appendSlashIfNecessary(String[] locations) {
            return Arrays.stream(locations)
                .map((location) -> location.endsWith("/") ? location : location + "/")
                .toArray(String[]::new);
        }

Hence this is impossible:

spring.graphql.schema:
    locations:
        # Subgraph's schema
        - classpath:schema/schema.graphqls
        # Federation-specific directives (shared across subgraphs)
        - classpath:schema/federation.graphqls
        # Common types (shared across subgraphs)
        - classpath:schema/Accommodation.graphqls
        - classpath:schema/AccommodationDeal.graphqls

I encountered this obstacle when trying to migrate from DGS to Spring GQL

bclozel commented 1 month ago

Hello @bjoernmayer

Yes that's correct, those are meant to be locations, not fully resolved resources. I'm not sure I understand the use case though. Why point directly to resources and not locations? Are there schema resources in the same location that are not meant to be used? Why?

bjoernmayer commented 1 month ago

Hi @bclozel, thank you for looking into this.

The main reason is Federation.

We are working with subgraphs in a Mono Repository. We have all of our shared types in a shared library. Each subgraph then picks only the types, that it needs and should expose in its schema.

bclozel commented 1 month ago

Spring for GraphQL provides a org.springframework.graphql.execution.GraphQlSource.SchemaResourceBuilder#schemaResources that lets you configure specific schema files.

You can already declare specific resources in your application by contributing a GraphQlSourceBuilderCustomizer bean to your application and add resources manually.

I'll move this issue to Spring Boot to consider a separate configuration property that would let you set additional schema resources on top of scanned ones.

jack5505 commented 4 weeks ago

Hello could you please give me this task for me

bclozel commented 3 weeks ago

@jack5505 thanks for the proposal but this is targeted for the next minor version and we haven't started working on this yet.