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

Commit da47918

Browse files
committed
Extract graphql-java-tools into its own starter
1 parent b820f4c commit da47918

File tree

6 files changed

+51
-49
lines changed

6 files changed

+51
-49
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1818
#
1919

20-
version = 5.11.1
20+
version = 5.12.0-SNAPSHOT
2121

2222
PROJECT_GROUP = com.graphql-java-kickstart
2323
PROJECT_NAME = graphql-spring-boot

graphql-java-tools-spring-boot-autoconfigure/build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ dependencies {
44

55
compile "com.graphql-java-kickstart:graphql-java-tools:$LIB_GRAPHQL_JAVA_TOOLS_VER"
66
compile "org.springframework.boot:spring-boot-autoconfigure:$LIB_SPRING_BOOT_VER"
7-
compile "commons-io:commons-io:$LIB_COMMONS_IO_VER"
87

9-
compile "com.graphql-java-kickstart:graphql-java-servlet:$LIB_GRAPHQL_SERVLET_VER"
8+
compileOnly "com.graphql-java-kickstart:graphql-java-servlet:$LIB_GRAPHQL_SERVLET_VER"
109

11-
// testCompile "com.graphql-java-kickstart:graphql-java-servlet:$LIB_GRAPHQL_SERVLET_VER"
10+
testCompile "com.graphql-java-kickstart:graphql-java-servlet:$LIB_GRAPHQL_SERVLET_VER"
1211
testCompile "com.graphql-java:graphql-java:$LIB_GRAPHQL_JAVA_VER"
1312
testCompile "org.springframework.boot:spring-boot-starter-web:$LIB_SPRING_BOOT_VER"
1413
testCompile "org.springframework.boot:spring-boot-starter-test:$LIB_SPRING_BOOT_VER"
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,54 @@
11
package graphql.kickstart.tools.boot;
22

3-
import org.apache.commons.io.IOUtils;
4-
import org.springframework.beans.factory.annotation.Autowired;
5-
import org.springframework.context.ApplicationContext;
6-
import org.springframework.core.io.Resource;
3+
import static java.util.stream.Collectors.joining;
74

5+
import java.io.BufferedReader;
86
import java.io.IOException;
97
import java.io.InputStream;
10-
import java.io.StringWriter;
8+
import java.io.InputStreamReader;
119
import java.nio.charset.StandardCharsets;
1210
import java.util.Arrays;
1311
import java.util.List;
1412
import java.util.stream.Collectors;
13+
import org.springframework.beans.factory.annotation.Autowired;
14+
import org.springframework.context.ApplicationContext;
15+
import org.springframework.core.io.Resource;
1516

1617
public class ClasspathResourceSchemaStringProvider implements SchemaStringProvider {
1718

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());
19+
@Autowired
20+
private ApplicationContext applicationContext;
21+
private String schemaLocationPattern;
22+
23+
public ClasspathResourceSchemaStringProvider(String schemaLocationPattern) {
24+
this.schemaLocationPattern = schemaLocationPattern;
25+
}
26+
27+
@Override
28+
public List<String> schemaStrings() throws IOException {
29+
Resource[] resources = applicationContext.getResources("classpath*:" + schemaLocationPattern);
30+
if (resources.length <= 0) {
31+
throw new IllegalStateException(
32+
"No graphql schema files found on classpath with location pattern '"
33+
+ schemaLocationPattern
34+
+ "'. Please add a graphql schema to the classpath or add a SchemaParser bean to your application context.");
3935
}
4036

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();
37+
return Arrays.stream(resources)
38+
.map(this::readSchema)
39+
.collect(Collectors.toList());
40+
}
41+
42+
private String readSchema(Resource resource) {
43+
try (
44+
InputStream inputStream = resource.getInputStream();
45+
InputStreamReader bufferedInputStream = new InputStreamReader(inputStream, StandardCharsets.UTF_8.name());
46+
BufferedReader reader = new BufferedReader(bufferedInputStream)
47+
) {
48+
return reader.lines().collect(joining());
49+
} catch (IOException e) {
50+
throw new IllegalStateException("Cannot read graphql schema from resource " + resource, e);
4951
}
52+
}
5053

5154
}

graphql-spring-boot-autoconfigure/build.gradle

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,17 @@
1818
*/
1919

2020
dependencies {
21-
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor:$LIB_SPRING_BOOT_VER"
22-
compileOnly "org.springframework.boot:spring-boot-configuration-processor:$LIB_SPRING_BOOT_VER"
23-
21+
compile(project(":graphql-java-tools-spring-boot-starter"))
2422
compile "org.springframework.boot:spring-boot-autoconfigure:$LIB_SPRING_BOOT_VER"
25-
compile "org.springframework.boot:spring-boot-starter-websocket:$LIB_SPRING_BOOT_VER"
26-
compile "org.springframework.boot:spring-boot-starter-actuator:$LIB_SPRING_BOOT_VER"
2723
compile "com.graphql-java-kickstart:graphql-java-servlet:$LIB_GRAPHQL_SERVLET_VER"
28-
// compile "com.graphql-java-kickstart:graphql-java-tools:$LIB_GRAPHQL_JAVA_TOOLS_VER"
29-
// compile "commons-io:commons-io:$LIB_COMMONS_IO_VER"
30-
31-
compile(project(":graphql-java-tools-spring-boot-starter"))
3224

25+
compileOnly "org.springframework.boot:spring-boot-starter-websocket:$LIB_SPRING_BOOT_VER"
26+
compileOnly "org.springframework.boot:spring-boot-starter-actuator:$LIB_SPRING_BOOT_VER"
3327
compileOnly "org.springframework.boot:spring-boot-starter-web:$LIB_SPRING_BOOT_VER"
3428

29+
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor:$LIB_SPRING_BOOT_VER"
30+
compileOnly "org.springframework.boot:spring-boot-configuration-processor:$LIB_SPRING_BOOT_VER"
31+
3532
testCompile "com.graphql-java:graphql-java:$LIB_GRAPHQL_JAVA_VER"
3633
testCompile "org.springframework.boot:spring-boot-starter-web:$LIB_SPRING_BOOT_VER"
3734
testCompile "org.springframework.boot:spring-boot-starter-test:$LIB_SPRING_BOOT_VER"

graphql-spring-boot-test-autoconfigure/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ dependencies {
2222
compile("org.springframework.boot:spring-boot-starter-test:$LIB_SPRING_BOOT_VER")
2323
compile(project(":graphql-spring-boot-test"))
2424
compile(project(":graphql-spring-boot-starter"))
25+
compile(project(":graphql-java-tools-spring-boot-starter"))
26+
compile("org.springframework.boot:spring-boot-starter-actuator:$LIB_SPRING_BOOT_VER")
27+
compile("org.springframework.boot:spring-boot-starter-websocket:$LIB_SPRING_BOOT_VER")
2528
compile("com.graphql-java-kickstart:graphql-java-tools:$LIB_GRAPHQL_JAVA_TOOLS_VER")
2629
}
2730

graphql-spring-boot-test-autoconfigure/src/main/java/com/graphql/spring/boot/test/GraphQLTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
import com.coxautodev.graphql.tools.SchemaParserDictionary;
55
import com.coxautodev.graphql.tools.SchemaParserOptions;
66
import com.oembedler.moon.graphql.boot.GraphQLInstrumentationAutoConfiguration;
7-
import com.oembedler.moon.graphql.boot.GraphQLJavaToolsAutoConfiguration;
87
import com.oembedler.moon.graphql.boot.GraphQLWebAutoConfiguration;
98
import graphql.execution.ExecutionStrategy;
109
import graphql.execution.instrumentation.Instrumentation;
1110
import graphql.execution.preparsed.PreparsedDocumentProvider;
11+
import graphql.kickstart.tools.boot.GraphQLJavaToolsAutoConfiguration;
1212
import graphql.schema.GraphQLScalarType;
1313
import graphql.schema.GraphQLSchema;
1414
import graphql.schema.idl.SchemaParser;
@@ -36,13 +36,13 @@
3636
import org.springframework.core.annotation.AliasFor;
3737
import org.springframework.test.context.ActiveProfiles;
3838
import org.springframework.web.filter.CorsFilter;
39-
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
4039

4140
import javax.servlet.MultipartConfigElement;
4241
import java.lang.annotation.ElementType;
4342
import java.lang.annotation.Retention;
4443
import java.lang.annotation.RetentionPolicy;
4544
import java.lang.annotation.Target;
45+
import org.springframework.web.socket.server.standard.ServerEndpointExporter;
4646

4747
import static org.springframework.context.annotation.FilterType.ASSIGNABLE_TYPE;
4848

0 commit comments

Comments
 (0)