Search code examples
spring-bootgraphqlspring-graphql

Spring-GraphQL: Refer to schema.graphqls definition located in separate JAR


The Spring-GraphQL service I am working on requires a schema.graphqls file to be present at runtime. The spring-graphql documentation describes a default location where the schema can be resolved:

By default, GraphQL schema files are expected to be in src/main/resources/graphql and have the extension ".graphqls", ".graphql", ".gql", or ".gqls".

The schema I would like to use is located in a different jar on the classpath. The Spring documentation indicates that the property spring.graphql.schema.locations can be used to alter the location of the file:

You can customize the schema locations to check as follows: spring.graphql.schema.locations=classpath:graphql/

I have tried several values (such as classpath:**) but I cannot seem to give the correct location. Would anyone know what value to use when the schema is located in a separate JAR?

I have verified the presence of the schema resource using SomeClass.class.getResource("/schema.graphqls").toURI();, which returned the schema URI:

jar:file:/home/{myname}/.m2/repository/com/organisation/some-external-lib/1.2.3/some-external-lib-1.2.3.jar!/schema.graphqls

Solution

  • I found a thread on github where a similar issue is discussed. I fixed my problem by using the following configuration:

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