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

Commit 0923ca1

Browse files
authored
Merge pull request #160 from graphql-java-kickstart/bugfix/157-graphql-tools-props
Added ConfigurationProperties for graphql-tools props (fix #157)
2 parents 46e9c32 + 2743abe commit 0923ca1

File tree

17 files changed

+75
-77
lines changed

17 files changed

+75
-77
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 {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.oembedler.moon.graphql.boot.resolvers;
1+
package com.graphql.sample.boot;
22

33
class Comment {
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.oembedler.moon.graphql.boot;
1+
package com.graphql.sample.boot;
22

33
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
44
import graphql.servlet.ObjectMapperConfigurer;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.oembedler.moon.graphql.boot.resolvers;
1+
package com.graphql.sample.boot;
22

33
import com.coxautodev.graphql.tools.GraphQLMutationResolver;
44
import java.util.Random;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.oembedler.moon.graphql.boot.resolvers;
1+
package com.graphql.sample.boot;
22

33
public class Post {
44

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.oembedler.moon.graphql.boot.resolvers;
1+
package com.graphql.sample.boot;
22

33
import com.coxautodev.graphql.tools.GraphQLResolver;
44
import org.springframework.stereotype.Component;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.oembedler.moon.graphql.boot.resolvers;
1+
package com.graphql.sample.boot;
22

33
import com.coxautodev.graphql.tools.GraphQLQueryResolver;
44
import org.springframework.stereotype.Component;

example-graphql-tools/src/test/java/com/oembedler/moon/graphql/boot/GraphQLServletTest.kt renamed to example-graphql-tools/src/test/java/com/graphql/sample/boot/GraphQLServletTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.oembedler.moon.graphql.boot
1+
package com.graphql.sample.boot
22

33

44
import com.graphql.spring.boot.test.GraphQLTestTemplate
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.oembedler.moon.graphql.boot;
1+
package com.graphql.sample.boot;
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import com.fasterxml.jackson.databind.node.ObjectNode;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.oembedler.moon.graphql.boot;
1+
package com.graphql.sample.boot;
22

33
import org.junit.Ignore;
44
import org.junit.Test;

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: 29 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,37 @@
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+
private String schemaLocationPattern;
21+
22+
public ClasspathResourceSchemaStringProvider(String schemaLocationPattern) {
23+
this.schemaLocationPattern = schemaLocationPattern;
24+
}
25+
26+
@Override
27+
public List<String> schemaStrings() throws IOException {
28+
Resource[] resources = applicationContext.getResources("classpath*:" + schemaLocationPattern);
29+
if (resources.length <= 0) {
30+
throw new IllegalStateException(
31+
"No graphql schema files found on classpath with location pattern '"
32+
+ schemaLocationPattern
33+
+ "'. Please add a graphql schema to the classpath or add a SchemaParser bean to your application context.");
34+
}
35+
36+
return Arrays.stream(resources)
37+
.map(this::readSchema)
38+
.collect(Collectors.toList());
3239
}
3340

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);
41+
private String readSchema(Resource resource) {
42+
StringWriter writer = new StringWriter();
43+
try (InputStream inputStream = resource.getInputStream()) {
44+
IOUtils.copy(inputStream, writer, StandardCharsets.UTF_8);
45+
} catch (IOException e) {
46+
throw new IllegalStateException("Cannot read graphql schema from resource " + resource, e);
47+
}
48+
return writer.toString();
4549
}
46-
return writer.toString();
47-
}
4850

4951
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
import graphql.schema.GraphQLSchema;
99
import graphql.servlet.GraphQLSchemaProvider;
1010
import org.springframework.beans.factory.annotation.Autowired;
11-
import org.springframework.beans.factory.annotation.Value;
1211
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
1312
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
1413
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
1514
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
1615
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
1716
import org.springframework.boot.autoconfigure.jackson.JacksonAutoConfiguration;
17+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
1818
import org.springframework.context.annotation.Bean;
1919
import org.springframework.context.annotation.Configuration;
2020

@@ -29,6 +29,7 @@
2929
@Configuration
3030
@ConditionalOnClass(SchemaParser.class)
3131
@AutoConfigureAfter({JacksonAutoConfiguration.class})
32+
@EnableConfigurationProperties(GraphQLToolsProperties.class)
3233
public class GraphQLJavaToolsAutoConfiguration {
3334

3435
@Autowired(required = false)
@@ -40,13 +41,13 @@ public class GraphQLJavaToolsAutoConfiguration {
4041
@Autowired(required = false)
4142
private SchemaParserOptions options;
4243

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

4647
@Bean
4748
@ConditionalOnMissingBean
4849
public SchemaStringProvider schemaStringProvider() {
49-
return new ClasspathResourceSchemaStringProvider();
50+
return new ClasspathResourceSchemaStringProvider(props.getSchemaLocationPattern());
5051
}
5152

5253
@Bean
@@ -71,7 +72,7 @@ public SchemaParser schemaParser(
7172
} else if (perFieldObjectMapperProvider != null) {
7273
final SchemaParserOptions.Builder optionsBuilder =
7374
newOptions().objectMapperProvider(perFieldObjectMapperProvider);
74-
optionsBuilder.introspectionEnabled(introspectionEnabled);
75+
optionsBuilder.introspectionEnabled(props.isIntrospectionEnabled());
7576
builder.options(optionsBuilder.build());
7677
}
7778

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)