Skip to content

Configure specific GraphQL schema files #42792

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

Closed
bjoernmayer opened this issue Oct 1, 2024 · 5 comments
Closed

Configure specific GraphQL schema files #42792

bjoernmayer opened this issue Oct 1, 2024 · 5 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@bjoernmayer
Copy link

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

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 1, 2024
@bclozel
Copy link
Member

bclozel commented Oct 9, 2024

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?

@bclozel bclozel added the status: waiting-for-feedback We need additional information before we can continue label Oct 9, 2024
@bjoernmayer
Copy link
Author

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.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Oct 9, 2024
@rstoyanchev rstoyanchev changed the title Specify Schema locations using filename Specify schema files by referring to specific files Oct 18, 2024
@rstoyanchev rstoyanchev changed the title Specify schema files by referring to specific files Specify schema by referring to specific files Oct 18, 2024
@bclozel bclozel changed the title Specify schema by referring to specific files Configure specific GraphQL schema files Oct 18, 2024
@bclozel bclozel removed the status: feedback-provided Feedback has been provided label Oct 18, 2024
@bclozel
Copy link
Member

bclozel commented Oct 18, 2024

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.

@bclozel bclozel transferred this issue from spring-projects/spring-graphql Oct 18, 2024
@bclozel bclozel self-assigned this Oct 18, 2024
@bclozel bclozel added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 18, 2024
@bclozel bclozel added this to the 3.5.x milestone Oct 18, 2024
@jack5505
Copy link

Hello could you please give me this task for me

@bclozel
Copy link
Member

bclozel commented Oct 28, 2024

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

@bclozel bclozel modified the milestones: 3.5.x, 3.5.0-M1 Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants