Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit 4599e20

Browse files
committed
Added ConfigurationProperties for graphql-tools props (fix #157)
1 parent 46e9c32 commit 4599e20

File tree

8 files changed

+61
-70
lines changed

8 files changed

+61
-70
lines changed

README.md

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -166,34 +166,15 @@ Available Spring Boot configuration parameters (either `application.yml` or `app
166166
```yaml
167167
graphql:
168168
tools:
169-
schemaLocationPattern: "**/*.graphqls"
169+
schema-location-pattern: "**/*.graphqls"
170170
# Enable or disable the introspection query. Disabling it puts your server in contravention of the GraphQL
171171
# specification and expectations of most clients, so use this option with caution
172-
introspectionEnabled: true
172+
introspection-enabled: true
173173
```
174174
By default GraphQL tools uses the location pattern `**/*.graphqls` to scan for GraphQL schemas on the classpath.
175175
Use the `schemaLocationPattern` property to customize this pattern.
176176

177177

178-
## GraphQL Spring Common [LATEST SUPPORTED VERSION: 3.1.1]
179-
**https://github.com/oembedler/spring-graphql-common**
180-
181-
See the [Readme](https://github.com/oembedler/spring-graphql-common#usage) and the [example](https://github.com/graphql-java-kickstart/graphql-spring-boot/tree/master/example-spring-common) for usage instructions.
182-
183-
#### Application Properties
184-
```yaml
185-
graphql:
186-
spring-graphql-common:
187-
clientMutationIdName: clientMutationId
188-
injectClientMutationId: true
189-
allowEmptyClientMutationId: false
190-
mutationInputArgumentName: input
191-
outputObjectNamePrefix: Payload
192-
inputObjectNamePrefix: Input
193-
schemaMutationObjectName: Mutation
194-
```
195-
196-
197178
# Contributions
198179

199180
Contributions are welcome. Please respect the [Code of Conduct](http://contributor-covenant.org/version/1/3/0/).
@@ -203,8 +184,6 @@ Contributions are welcome. Please respect the [Code of Conduct](http://contribu
203184

204185
`graphql-spring-boot-starter` and `graphiql-spring-boot-starter` are licensed under the MIT License. See [LICENSE](LICENSE.md) for details.
205186

206-
[spring-graphql-common License](https://github.com/oembedler/spring-graphql-common/blob/master/LICENSE.md)
207-
208187
[graphql-java License](https://github.com/andimarek/graphql-java/blob/master/LICENSE.md)
209188

210189
[graphiql License](https://github.com/graphql/graphiql/blob/master/LICENSE)

build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ buildscript {
3434

3535
plugins {
3636
id 'net.researchgate.release' version '2.7.0'
37+
id 'io.franzbecker.gradle-lombok' version '1.14' apply false
3738
}
3839

3940
subprojects {
@@ -42,6 +43,7 @@ subprojects {
4243
apply plugin: 'maven'
4344
apply plugin: 'maven-publish'
4445
apply plugin: "com.jfrog.bintray"
46+
apply plugin: 'io.franzbecker.gradle-lombok'
4547

4648
group = PROJECT_GROUP
4749

@@ -65,6 +67,14 @@ subprojects {
6567
targetCompatibility = TARGET_COMPATIBILITY
6668
}
6769

70+
compileJava.dependsOn(processResources)
71+
72+
lombok {
73+
version = "1.18.4"
74+
sha256 = ""
75+
}
76+
77+
6878
if (!it.name.startsWith('example')) {
6979

7080
jar {

gradle.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ LIB_JUNIT_VER = 4.12
4141
LIB_SPRING_CORE_VER = 5.0.4.RELEASE
4242
LIB_SPRING_BOOT_VER = 2.0.5.RELEASE
4343
LIB_GRAPHQL_SERVLET_VER = 7.0.0
44-
LIB_GRAPHQL_JAVA_TOOLS_VER = 5.3.5
44+
LIB_GRAPHQL_JAVA_TOOLS_VER = 5.4.0
4545
LIB_COMMONS_IO_VER = 2.6
4646

47-
GRADLE_WRAPPER_VER = 4.7
47+
GRADLE_WRAPPER_VER = 4.10.2
4848

4949
###
5050

graphql-spring-boot-autoconfigure/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
dependencies {
21-
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor:$LIB_SPRING_BOOT_VER"
21+
compileOnly "org.springframework.boot:spring-boot-configuration-processor:$LIB_SPRING_BOOT_VER"
2222

2323
compile "org.springframework.boot:spring-boot-autoconfigure:$LIB_SPRING_BOOT_VER"
2424
compile "org.springframework.boot:spring-boot-starter-websocket:$LIB_SPRING_BOOT_VER"

graphql-spring-boot-autoconfigure/src/main/java/com/oembedler/moon/graphql/boot/ClasspathResourceSchemaStringProvider.java

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import org.apache.commons.io.IOUtils;
44
import org.springframework.beans.factory.annotation.Autowired;
5-
import org.springframework.beans.factory.annotation.Value;
65
import org.springframework.context.ApplicationContext;
76
import org.springframework.core.io.Resource;
87

@@ -16,34 +15,34 @@
1615

1716
public class ClasspathResourceSchemaStringProvider implements SchemaStringProvider {
1817

19-
@Autowired
20-
private ApplicationContext applicationContext;
21-
@Value("${graphql.tools.schemaLocationPattern:**/*.graphqls}")
22-
private String schemaLocationPattern;
23-
24-
@Override
25-
public List<String> schemaStrings() throws IOException {
26-
Resource[] resources = applicationContext.getResources("classpath*:" + schemaLocationPattern);
27-
if (resources.length <= 0) {
28-
throw new IllegalStateException(
29-
"No graphql schema files found on classpath with location pattern '"
30-
+ schemaLocationPattern
31-
+ "'. Please add a graphql schema to the classpath or add a SchemaParser bean to your application context.");
18+
@Autowired
19+
private ApplicationContext applicationContext;
20+
@Autowired
21+
private GraphQLToolsProperties props;
22+
23+
@Override
24+
public List<String> schemaStrings() throws IOException {
25+
Resource[] resources = applicationContext.getResources("classpath*:" + props.getSchemaLocationPattern());
26+
if (resources.length <= 0) {
27+
throw new IllegalStateException(
28+
"No graphql schema files found on classpath with location pattern '"
29+
+ props.getSchemaLocationPattern()
30+
+ "'. Please add a graphql schema to the classpath or add a SchemaParser bean to your application context.");
31+
}
32+
33+
return Arrays.stream(resources)
34+
.map(this::readSchema)
35+
.collect(Collectors.toList());
3236
}
3337

34-
return Arrays.stream(resources)
35-
.map(this::readSchema)
36-
.collect(Collectors.toList());
37-
}
38-
39-
private String readSchema(Resource resource) {
40-
StringWriter writer = new StringWriter();
41-
try (InputStream inputStream = resource.getInputStream()) {
42-
IOUtils.copy(inputStream, writer, StandardCharsets.UTF_8);
43-
} catch (IOException e) {
44-
throw new IllegalStateException("Cannot read graphql schema from resource " + resource, e);
38+
private String readSchema(Resource resource) {
39+
StringWriter writer = new StringWriter();
40+
try (InputStream inputStream = resource.getInputStream()) {
41+
IOUtils.copy(inputStream, writer, StandardCharsets.UTF_8);
42+
} catch (IOException e) {
43+
throw new IllegalStateException("Cannot read graphql schema from resource " + resource, e);
44+
}
45+
return writer.toString();
4546
}
46-
return writer.toString();
47-
}
4847

4948
}

graphql-spring-boot-autoconfigure/src/main/java/com/oembedler/moon/graphql/boot/GraphQLJavaToolsAutoConfiguration.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@
1010
import org.springframework.beans.factory.annotation.Autowired;
1111
import org.springframework.beans.factory.annotation.Value;
1212
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
13-
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
14-
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
15-
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
16-
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
13+
import org.springframework.boot.autoconfigure.condition.*;
1714
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
1815
import org.springframework.context.annotation.Bean;
1916
import org.springframework.context.annotation.Configuration;
@@ -40,8 +37,8 @@ public class GraphQLJavaToolsAutoConfiguration {
4037
@Autowired(required = false)
4138
private SchemaParserOptions options;
4239

43-
@Value("${graphql.tools.introspectionEnabled:true}")
44-
private boolean introspectionEnabled;
40+
@Autowired
41+
private GraphQLToolsProperties props;
4542

4643
@Bean
4744
@ConditionalOnMissingBean
@@ -71,7 +68,7 @@ public SchemaParser schemaParser(
7168
} else if (perFieldObjectMapperProvider != null) {
7269
final SchemaParserOptions.Builder optionsBuilder =
7370
newOptions().objectMapperProvider(perFieldObjectMapperProvider);
74-
optionsBuilder.introspectionEnabled(introspectionEnabled);
71+
optionsBuilder.introspectionEnabled(props.isIntrospectionEnabled());
7572
builder.options(optionsBuilder.build());
7673
}
7774

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.oembedler.moon.graphql.boot;
2+
3+
import lombok.Data;
4+
import org.springframework.boot.context.properties.ConfigurationProperties;
5+
import org.springframework.context.annotation.Configuration;
6+
7+
@Data
8+
@Configuration
9+
@ConfigurationProperties(prefix = "graphql.tools")
10+
class GraphQLToolsProperties {
11+
12+
private String schemaLocationPattern = "**/*.graphqls";
13+
private boolean introspectionEnabled = true;
14+
private boolean useDefaultObjectmapper = true;
15+
16+
}

graphql-spring-boot-autoconfigure/src/main/resources/META-INF/additional-spring-configuration-metadata.json

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,6 @@
4444
"name": "graphql.servlet.maxQueryDepth",
4545
"defaultValue": null,
4646
"type": "java.lang.Integer"
47-
},
48-
{
49-
"name": "graphql.tools.schemaLocationPattern",
50-
"defaultValue": "**/*.graphqls",
51-
"type": "java.lang.String"
52-
},
53-
{
54-
"name": "graphql.tools.introspectionEnabled",
55-
"defaultValue": true,
56-
"type": "java.lang.Boolean"
5747
}
5848
]
5949
}

0 commit comments

Comments
 (0)