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

Support for multiple graphql schema files #56

Closed
tobiolalusi opened this issue Jun 11, 2021 · 10 comments
Closed

Support for multiple graphql schema files #56

tobiolalusi opened this issue Jun 11, 2021 · 10 comments
Assignees
Labels
type: enhancement A general enhancement
Milestone

Comments

@tobiolalusi
Copy link

The TypeDefinitionRegistry provides a .merge(TypedefinitionRegistry) to be able to merge multiple schema resources. This comes in mostly handy when the developer tries to create multiple graphql schema files to improve readability and simplicity. All these will be merged into one GraphQL schema/TypeDefinitionRegistry.

@bclozel bclozel self-assigned this Jun 29, 2021
@bclozel bclozel added the type: enhancement A general enhancement label Jun 29, 2021
@bclozel bclozel added this to the 1.0 M1 milestone Jun 29, 2021
@bclozel
Copy link
Member

bclozel commented Jun 29, 2021

Thanks @tobiolalusi - this is now fixed and will be available in our first milestone.

For now the configuration property must contain actual locations, e.g. classpath:/graphql/, under which we scan for *.graphqls files. We could have gone for full patterns instead, e.g. classpath:/graphql/*.graphqls, but I thought the former would align better with the existing Spring Boot properties.

Let me know if you had something else in mind!

@hantsy
Copy link
Contributor

hantsy commented Jun 30, 2021

My previous location is classpath: schema/schema.graphql.

there is no way to make it work in the configuration of the new spring.graphql.schema.locations, I have to rename my schema folder.

@bclozel
Copy link
Member

bclozel commented Jun 30, 2021

You mean you need to rename your schema file from schema.graphql to schema.graphqls?

Once done, the following should work:

spring.graphql.schema.locations=classpath:/schema/

@tobiolalusi
Copy link
Author

There are several possible ways to name a GraphQL file. Could be with one of the following extensions: .graphqls, .graphql, .gql, .gqls. There are however no official standards for naming the files, but most commonly used ones is one of .graphql and .graphqls.

I could create a PR based on the current update that supports the above mentioned extensions, if need be.

@hantsy
Copy link
Contributor

hantsy commented Jun 30, 2021

@bclozel I removed the config in my sample now and renamed my folders and schema file to follow the convention.

@bclozel
Copy link
Member

bclozel commented Jun 30, 2021

@tobiolalusi @hantsy
Would something like the following address the use case in a more flexible way?

# default value
spring.graphql.schema.location-patterns=classpath:/schema/*.graphqls

# sample configuration
spring.graphql.schema.location-patterns=classpath:/schema/*.graphql, classpath:/graphql/other/*.gql

@rstoyanchev
Copy link
Contributor

I think the way it works currently, based on root location is good and simple. We could expand that slightly to check for the additional suffixes and adapt to what's present. Given the combination of dedicated locations for such GraphQL schema files, as well as the rather specific suffixes, it shouldn't cause any surprises I think.

I can't see a good reason for other kinds of files to use such prefixes, and if they do they simply won't parse and it can't go unnoticed.

@tobiolalusi
Copy link
Author

Unless, spring-graphql wants to create a standard, which in my opinion isn't a bad idea, the .graphqls extension is a good one. Apart from that, for a little more flexibility, I agree with @rstoyanchev, we could instead to adapt to the different standard graphql extensions.
As long as any file is in the spring.graphql.schema.locations and they have any of these extensions, they are valid graphql schema files.

@bclozel
Copy link
Member

bclozel commented Jun 30, 2021

Reopening to look for well-known file extensions in the configured locations.

@bclozel bclozel reopened this Jun 30, 2021
@hantsy
Copy link
Contributor

hantsy commented Jul 1, 2021

I think spring.graphql.schema.locations is ok, accept a custom classpath, or patterns if you like.

spring.graphql.schema.locations=classpath:schema/schema.graphql,a_relative_path/a.graphql, file:/home/hantsy/graphql.gql, classpath:/**/antpatterns/*.graphqls

Maybe can read from a URI in the future to support GraphQL Gateway/Federation.

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