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

Commit 720dcc0

Browse files
committed
Clean up code
1 parent 7977f8e commit 720dcc0

File tree

17 files changed

+44
-163
lines changed

17 files changed

+44
-163
lines changed

altair-spring-boot-autoconfigure/build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1818
*/
1919
dependencies{
20+
implementation(project(':graphql-kickstart-starter-utils'))
2021
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
21-
22+
2223
implementation "org.springframework.boot:spring-boot-autoconfigure"
2324
implementation "org.apache.commons:commons-text:$LIB_APACHE_COMMONS_TEXT"
2425
compileOnly "org.springframework.boot:spring-boot-starter-web"

altair-spring-boot-autoconfigure/src/main/java/graphql/kickstart/altair/boot/AltairController.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.fasterxml.jackson.core.JsonProcessingException;
44
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import graphql.kickstart.util.PropertyGroupReader;
6+
import graphql.kickstart.util.PropsLoader;
57
import java.io.IOException;
68
import java.io.InputStream;
79
import java.nio.charset.Charset;
@@ -55,11 +57,11 @@ private void loadTemplate() throws IOException {
5557
}
5658

5759
private void loadProps() throws IOException {
58-
props = new PropsLoader(environment).load();
60+
props = new PropsLoader(environment, "altair.props.resources.", "altair.props.values.").load();
5961
}
6062

6163
private void loadHeaders() throws JsonProcessingException {
62-
PropertyGroupReader propertyReader = new PropertyGroupReader(environment, "graphiql.headers.");
64+
PropertyGroupReader propertyReader = new PropertyGroupReader(environment, "altair.headers.");
6365
Properties headerProperties = propertyReader.load();
6466
this.headers = new ObjectMapper().writeValueAsString(headerProperties);
6567
}
@@ -86,7 +88,7 @@ private Map<String, String> getReplacements(String graphqlEndpoint,
8688
replacements.put("pageTitle", altairProperties.getPageTitle());
8789
replacements.put("pageFavicon", getResourceUrl("favicon.ico", "favicon.ico"));
8890
replacements.put("altairBaseUrl", getResourceUrl(
89-
StringUtils.join(altairProperties.getSTATIC().getBasePath(), "/vendor/altair/"),
91+
StringUtils.join(altairProperties.getBasePath(), "/vendor/altair/"),
9092
joinJsUnpkgPath(ALTAIR, altairProperties.getCdn().getVersion(), "build/dist/")));
9193
replacements
9294
.put("altairLogoUrl", getResourceUrl("assets/img/logo_350.svg", "assets/img/logo_350.svg"));

altair-spring-boot-autoconfigure/src/main/java/graphql/kickstart/altair/boot/AltairProperties.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ public class AltairProperties {
99

1010
private boolean enabled = true;
1111
private Endpoint endpoint = new Endpoint();
12-
private Static STATIC = new Static();
1312
private Cdn cdn = new Cdn();
1413
private String pageTitle = "Altair";
1514
private String mapping = "/altair";
15+
private String basePath = "";
1616

1717
@Data
1818
static class Endpoint {
@@ -21,12 +21,6 @@ static class Endpoint {
2121
private String subscriptions = "/subscriptions";
2222
}
2323

24-
@Data
25-
static class Static {
26-
27-
private String basePath = "";
28-
}
29-
3024
@Data
3125
static class Cdn {
3226

example-graphql-subscription/src/main/java/graphql/kickstart/spring/web/boot/resolvers/Query.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@
66
@Component
77
class Query implements GraphQLQueryResolver {
88

9-
public String hello() {
10-
return "Hello world!";
9+
private static final String HELLO = "Hello world";
10+
11+
String hello() {
12+
return HELLO;
1113
}
1214

1315
}

graphiql-spring-boot-autoconfigure/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1818
*/
1919
dependencies{
20+
implementation(project(':graphql-kickstart-starter-utils'))
2021
annotationProcessor "org.springframework.boot:spring-boot-configuration-processor"
2122

2223
implementation "org.springframework.boot:spring-boot-autoconfigure"

graphiql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/graphiql/boot/GraphiQLController.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
import com.fasterxml.jackson.core.JsonProcessingException;
44
import com.fasterxml.jackson.databind.ObjectMapper;
5+
import graphql.kickstart.util.PropertyGroupReader;
6+
import graphql.kickstart.util.PropsLoader;
57
import java.io.IOException;
68
import java.io.InputStream;
79
import java.nio.charset.Charset;
@@ -53,7 +55,8 @@ private void loadTemplate() throws IOException {
5355
}
5456

5557
private void loadProps() throws IOException {
56-
props = new PropsLoader(environment).load();
58+
props = new PropsLoader(environment, "graphiql.props.resources.", "graphiql.props.variables.")
59+
.load();
5760
}
5861

5962
private void loadHeaders() {
@@ -71,7 +74,7 @@ public byte[] graphiql(String contextPath, @PathVariable Map<String, String> par
7174
Map<String, String> replacements = getReplacements(
7275
constructGraphQlEndpoint(contextPath, params),
7376
contextPath + graphiQLProperties.getEndpoint().getSubscriptions(),
74-
contextPath + graphiQLProperties.getSTATIC().getBasePath()
77+
contextPath + graphiQLProperties.getBasePath()
7578
);
7679

7780
String populatedTemplate = StringSubstitutor.replace(template, replacements);

graphiql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/graphiql/boot/GraphiQLProperties.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
class GraphiQLProperties {
99

1010
private Endpoint endpoint = new Endpoint();
11-
private Static STATIC = new Static();
1211
private CodeMirror codeMirror = new CodeMirror();
1312
private Props props = new Props();
1413
private String pageTitle = "GraphiQL";
1514
private String mapping = "/graphiql";
1615
private Subscriptions subscriptions = new Subscriptions();
1716
private Cdn cdn = new Cdn();
17+
private String basePath = "/";
1818

1919
@Data
2020
static class Endpoint {
@@ -23,12 +23,6 @@ static class Endpoint {
2323
private String subscriptions = "/subscriptions";
2424
}
2525

26-
@Data
27-
static class Static {
28-
29-
private String basePath = "/";
30-
}
31-
3226
@Data
3327
static class CodeMirror {
3428

graphiql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/graphiql/boot/PropertyGroupReader.java

Lines changed: 0 additions & 66 deletions
This file was deleted.

graphiql-spring-boot-autoconfigure/src/main/java/graphql/kickstart/graphiql/boot/PropsLoader.java

Lines changed: 0 additions & 54 deletions
This file was deleted.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
import org.springframework.context.ApplicationContextException;
1010

1111
@DisplayName("Test exception if multiple query resolvers are defined.")
12-
public class GraphQLAnnotationsErrorMultipleQueryResolvers {
12+
class GraphQLAnnotationsErrorMultipleQueryResolversTest {
1313

1414
@Test
1515
@DisplayName("Assert that MultipleQueryResolversException is thrown when multiple query resolvers are found.")
16-
public void testMultipleQueryResolversExceptionIsThrown() {
16+
void testMultipleQueryResolversExceptionIsThrown() {
1717
// GIVEN
1818
final SpringApplication app = new SpringApplication(TestApplication.class);
1919
app.setAdditionalProfiles("test", "test-multiple-query-resolvers-exception");
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
import org.springframework.context.ApplicationContextException;
1010

1111
@DisplayName("Test exception if multiple subscription resolvers are defined.")
12-
public class GraphQLAnnotationsErrorMultipleSubscriptionResolvers {
12+
class GraphQLAnnotationsErrorMultipleSubscriptionResolversTest {
1313

1414
@Test
1515
@DisplayName("Assert that MultipleSubscriptionResolversException is thrown when multiple subscription resolvers are found.")
16-
public void testMultipleSubscriptionResolversExceptionIsThrown() {
16+
void testMultipleSubscriptionResolversExceptionIsThrown() {
1717
// GIVEN
1818
final SpringApplication app = new SpringApplication(TestApplication.class);
1919
app.setAdditionalProfiles("test", "test-multiple-subscription-resolvers-exception");
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dependencies {
2+
compileOnly "org.springframework.boot:spring-boot-starter-web"
3+
}
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package graphql.kickstart.altair.boot;
1+
package graphql.kickstart.util;
22

33
import java.util.Arrays;
44
import java.util.Iterator;
@@ -12,18 +12,18 @@
1212
import org.springframework.core.env.Environment;
1313
import org.springframework.core.env.PropertySource;
1414

15-
class PropertyGroupReader {
15+
public class PropertyGroupReader {
1616

1717
private final Environment environment;
1818
private final String prefix;
1919
private Properties props;
2020

21-
PropertyGroupReader(Environment environment, String prefix) {
21+
public PropertyGroupReader(Environment environment, String prefix) {
2222
this.environment = Objects.requireNonNull(environment);
2323
this.prefix = Optional.ofNullable(prefix).orElse("");
2424
}
2525

26-
Properties load() {
26+
public Properties load() {
2727
if (props == null) {
2828
props = new Properties();
2929
loadProps();
@@ -46,7 +46,7 @@ private Stream<EnumerablePropertySource<Object>> streamOfPropertySources() {
4646
Iterable<PropertySource<?>> iterable = () -> iterator;
4747
return StreamSupport.stream(iterable.spliterator(), false)
4848
.filter(EnumerablePropertySource.class::isInstance)
49-
.map(it -> (EnumerablePropertySource<Object>) it);
49+
.map(EnumerablePropertySource.class::cast);
5050
}
5151
return Stream.empty();
5252
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package graphql.kickstart.altair.boot;
1+
package graphql.kickstart.util;
22

33
import com.fasterxml.jackson.databind.ObjectMapper;
44
import java.io.IOException;
@@ -12,20 +12,20 @@
1212
import org.springframework.core.io.Resource;
1313
import org.springframework.util.StreamUtils;
1414

15-
class PropsLoader {
16-
17-
private static final String ALTAIR_PROPS_PREFIX = "altair.props.";
18-
private static final String ALTAIR_PROPS_RESOURCES_PREFIX = ALTAIR_PROPS_PREFIX + "resources.";
19-
private static final String ALTAIR_PROPS_VALUES_PREFIX = ALTAIR_PROPS_PREFIX + "values.";
15+
public class PropsLoader {
2016

2117
private final Environment environment;
18+
private final String resourcesPrefix;
19+
private final String valuesPrefix;
2220

23-
PropsLoader(Environment environment) {
21+
public PropsLoader(Environment environment, String resourcesPrefix, String valuesPrefix) {
2422
this.environment = environment;
23+
this.resourcesPrefix = resourcesPrefix;
24+
this.valuesPrefix = valuesPrefix;
2525
}
2626

27-
String load() throws IOException {
28-
PropertyGroupReader reader = new PropertyGroupReader(environment, ALTAIR_PROPS_VALUES_PREFIX);
27+
public String load() throws IOException {
28+
PropertyGroupReader reader = new PropertyGroupReader(environment, valuesPrefix);
2929
Properties props = reader.load();
3030

3131
ObjectMapper objectMapper = new ObjectMapper();
@@ -36,7 +36,7 @@ String load() throws IOException {
3636
}
3737

3838
private Optional<String> loadPropFromResource(String prop) {
39-
String property = ALTAIR_PROPS_RESOURCES_PREFIX + prop;
39+
String property = resourcesPrefix + prop;
4040
return Optional.ofNullable(environment.getProperty(property))
4141
.map(ClassPathResource::new)
4242
.map(this::loadResource);

graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLFieldAssertAsJavaTypeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import org.junit.jupiter.api.Test;
1414
import org.mockito.Mock;
1515

16-
public class GraphQLFieldAssertAsJavaTypeTest extends GraphQLFieldAssertTestBase {
16+
class GraphQLFieldAssertAsJavaTypeTest extends GraphQLFieldAssertTestBase {
1717

1818
private static final JavaType FOO_TYPE = TypeFactory.defaultInstance().constructType(Foo.class);
1919

graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLFieldAssertAsListTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
import org.junit.jupiter.api.Test;
1414
import org.mockito.Mock;
1515

16-
public class GraphQLFieldAssertAsListTest extends GraphQLFieldAssertTestBase {
16+
class GraphQLFieldAssertAsListTest extends GraphQLFieldAssertTestBase {
1717

1818
@Test
1919
@DisplayName("Should return a String list assertion (value at specific path is valid list).")

0 commit comments

Comments
 (0)