Skip to content

Commit 5fa42bb

Browse files
authored
Merge pull request #5 from introproventures/master
merge master
2 parents 3185087 + 1955ab6 commit 5fa42bb

File tree

18 files changed

+265
-20
lines changed

18 files changed

+265
-20
lines changed

CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Change Log
22

3-
## 0.3.18-SNAPSHOT
3+
## 0.3.20-SNAPSHOT
4+
* feat: support enum variable bindings in queries (#109) [5dd999a](https://github.com/introproventures/graphql-jpa-query/commit/5dd999a1107899ce6bfe08aceb37ed2fb057aac6)
5+
* Update README to add PWD shortcut in the title [8e9d409](https://github.com/introproventures/graphql-jpa-query/commit/8e9d409b4a193dde823991a9945d29f0163234a8)
6+
* #102 fix NullPointerException when searching for Transient annotation (#106) [fb45d23](https://github.com/introproventures/graphql-jpa-query/commit/fb45d2329d8d02abc687e3db3cb2faafa4d91659)
47
* chore: enable Docker build by default [ec3f1a6](https://github.com/introproventures/graphql-jpa-query/commit/ec3f1a6c5daa3390fd738e2d2cef4f7a58b24e2d)
58
* fix: use bean naming convention for property names [6df3c30](https://github.com/introproventures/graphql-jpa-query/commit/6df3c30d1a16681da07d81d7ca64fed9d885ac57)
69
* distinct sql and ignore field in filters and sorting (#95) [bde04d5](https://github.com/introproventures/graphql-jpa-query/commit/bde04d5702943cd7d5e70d071e8a49df4ef8ad9f)

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
GraphQL Query Api for JPA Entity Models
1+
GraphQL Query Api for JPA Entity Models [![Try in PWD](https://cdn.rawgit.com/play-with-docker/stacks/cff22438/assets/images/button.png)](http://play-with-docker.com/?stack=https://raw.githubusercontent.com/introproventures/graphql-jpa-query/master/graphql-jpa-query-example/docker-compose.yml&stack_name=graphhql)
22
===============
33

44
[![Build Status](https://travis-ci.org/introproventures/graphql-jpa-query.svg?branch=master)](https://travis-ci.org/introproventures/graphql-jpa-query)
55
[![codecov](https://codecov.io/gh/introproventures/graphql-jpa-query/branch/master/graph/badge.svg)](https://codecov.io/gh/introproventures/graphql-jpa-query)
66
[![Maven Central](https://img.shields.io/maven-central/v/com.introproventures/graphql-jpa-query.svg)](https://mvnrepository.com/artifact/com.introproventures/graphql-jpa-query)
7-
[![Jitpack.io](https://jitpack.io/v/introproventures/graphql-jpa-query.svg)](https://jitpack.io/#introproventures/graphql-jpa-query)
7+
[![Jitpack.io](https://jitpack.io/v/introproventures/graphql-jpa-query.svg)](https://jitpack.io/#introproventures/graphql-jpa-query)
88

99
GraphQL is a query language for Web APIs implemented by GraphQL Java [graphql-java 11.0](https://github.com/andimarek/graphql-java) runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.
1010

graphql-jpa-query-annotations/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>com.introproventures</groupId>
88
<artifactId>graphql-jpa-query-dependencies</artifactId>
9-
<version>0.3.18-SNAPSHOT</version>
9+
<version>0.3.20-SNAPSHOT</version>
1010
<relativePath>../graphql-jpa-query-dependencies</relativePath>
1111
</parent>
1212

graphql-jpa-query-autoconfigure/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>com.introproventures</groupId>
55
<artifactId>graphql-jpa-query-build</artifactId>
6-
<version>0.3.18-SNAPSHOT</version>
6+
<version>0.3.20-SNAPSHOT</version>
77
<relativePath>../graphql-jpa-query-build</relativePath>
88
</parent>
99
<artifactId>graphql-jpa-query-autoconfigure</artifactId>

graphql-jpa-query-boot-starter/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.introproventures</groupId>
99
<artifactId>graphql-jpa-query-build</artifactId>
10-
<version>0.3.18-SNAPSHOT</version>
10+
<version>0.3.20-SNAPSHOT</version>
1111
<relativePath>../graphql-jpa-query-build</relativePath>
1212
</parent>
1313

graphql-jpa-query-build/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>com.introproventures</groupId>
55
<artifactId>graphql-jpa-query-dependencies</artifactId>
6-
<version>0.3.18-SNAPSHOT</version>
6+
<version>0.3.20-SNAPSHOT</version>
77
<relativePath>../graphql-jpa-query-dependencies</relativePath>
88
</parent>
99
<artifactId>graphql-jpa-query-build</artifactId>

graphql-jpa-query-dependencies/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>com.introproventures</groupId>
55
<artifactId>graphql-jpa-query</artifactId>
6-
<version>0.3.18-SNAPSHOT</version>
6+
<version>0.3.20-SNAPSHOT</version>
77
<relativePath>..</relativePath>
88
</parent>
99
<artifactId>graphql-jpa-query-dependencies</artifactId>

graphql-jpa-query-example-merge/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.introproventures</groupId>
99
<artifactId>graphql-jpa-query-build</artifactId>
10-
<version>0.3.18-SNAPSHOT</version>
10+
<version>0.3.20-SNAPSHOT</version>
1111
<relativePath>../graphql-jpa-query-build</relativePath>
1212
</parent>
1313

graphql-jpa-query-example/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<parent>
88
<groupId>com.introproventures</groupId>
99
<artifactId>graphql-jpa-query-build</artifactId>
10-
<version>0.3.18-SNAPSHOT</version>
10+
<version>0.3.20-SNAPSHOT</version>
1111
<relativePath>../graphql-jpa-query-build</relativePath>
1212
</parent>
1313

graphql-jpa-query-schema/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>com.introproventures</groupId>
77
<artifactId>graphql-jpa-query-build</artifactId>
8-
<version>0.3.18-SNAPSHOT</version>
8+
<version>0.3.20-SNAPSHOT</version>
99
<relativePath>../graphql-jpa-query-build</relativePath>
1010
</parent>
1111

graphql-jpa-query-schema/src/main/java/com/introproventures/graphql/jpa/query/schema/impl/IntrospectionUtils.java

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public boolean isAnnotationPresent(Class<? extends Annotation> annotation) {
8484
.isAnnotationPresent(annotation);
8585

8686
} catch (NoSuchFieldException e) {
87+
if(delegate.getReadMethod() == null) return false;
8788
answer = delegate.getReadMethod()
8889
.isAnnotationPresent(annotation);
8990
}

graphql-jpa-query-schema/src/main/java/com/introproventures/graphql/jpa/query/schema/impl/QraphQLJpaBaseDataFetcher.java

+20-5
Original file line numberDiff line numberDiff line change
@@ -540,12 +540,27 @@ protected Object convertValue(DataFetchingEnvironment environment, Argument argu
540540
return ((StringValue) value).getValue();
541541
}
542542
}
543-
else if (value instanceof VariableReference)
544-
// Get resolved variable in environment arguments
545-
return environment.getArguments().get(argument.getName());
546-
else if (value instanceof ArrayValue) {
543+
else if (value instanceof VariableReference) {
544+
Class javaType = getJavaType(environment, argument);
545+
Object argumentValue = environment.getArguments().get(argument.getName());
546+
if(javaType.isEnum()) {
547+
if(argumentValue instanceof Collection) {
548+
List<Enum> values = new ArrayList<>();
549+
550+
Collection.class.cast(argumentValue)
551+
.forEach(it -> values.add(Enum.valueOf(javaType, it.toString())));
552+
return values;
553+
} else {
554+
return Enum.valueOf(javaType, argumentValue.toString());
555+
}
556+
}
557+
else {
558+
// Get resolved variable in environment arguments
559+
return argumentValue;
560+
}
561+
} else if (value instanceof ArrayValue) {
547562
Object convertedValue = environment.getArgument(argument.getName());
548-
if (convertedValue != null) {
563+
if (convertedValue != null && !getJavaType(environment, argument).isEnum()) {
549564
// unwrap [[EnumValue{name='value'}]]
550565
if(convertedValue instanceof Collection
551566
&& ((Collection) convertedValue).stream().allMatch(it->it instanceof Collection)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,208 @@
1+
/*
2+
* Copyright 2017 IntroPro Ventures Inc. and/or its affiliates.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.introproventures.graphql.jpa.query.schema;
18+
19+
import static org.assertj.core.api.Assertions.assertThat;
20+
21+
import java.util.Arrays;
22+
import java.util.HashMap;
23+
import java.util.Map;
24+
25+
import javax.persistence.EntityManager;
26+
27+
import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaExecutor;
28+
import com.introproventures.graphql.jpa.query.schema.impl.GraphQLJpaSchemaBuilder;
29+
import org.junit.Test;
30+
import org.junit.runner.RunWith;
31+
import org.springframework.beans.factory.annotation.Autowired;
32+
import org.springframework.boot.autoconfigure.SpringBootApplication;
33+
import org.springframework.boot.test.context.SpringBootTest;
34+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
35+
import org.springframework.context.annotation.Bean;
36+
import org.springframework.test.context.TestPropertySource;
37+
import org.springframework.test.context.junit4.SpringRunner;
38+
39+
40+
@RunWith(SpringRunner.class)
41+
@SpringBootTest(webEnvironment=WebEnvironment.NONE)
42+
@TestPropertySource({"classpath:hibernate.properties"})
43+
public class GraphQLEnumVariableBindingsTests {
44+
45+
@SpringBootApplication
46+
static class Application {
47+
@Bean
48+
public GraphQLExecutor graphQLExecutor(final GraphQLSchemaBuilder graphQLSchemaBuilder) {
49+
return new GraphQLJpaExecutor(graphQLSchemaBuilder.build());
50+
}
51+
52+
@Bean
53+
public GraphQLSchemaBuilder graphQLSchemaBuilder(final EntityManager entityManager) {
54+
55+
return new GraphQLJpaSchemaBuilder(entityManager)
56+
.name("GraphQLBooks")
57+
.description("Books JPA test schema");
58+
}
59+
60+
}
61+
62+
@Autowired
63+
private GraphQLExecutor executor;
64+
65+
66+
@Test
67+
public void queryEnumSimpleVariableBinding() {
68+
//given
69+
String query = "query($genre: Genre) {" +
70+
" Books(where: {" +
71+
" genre: {EQ: $genre}" +
72+
" }) {" +
73+
" select {" +
74+
" id" +
75+
" title" +
76+
" genre" +
77+
" }" +
78+
" }" +
79+
"}";
80+
81+
Map<String, Object> variables = new HashMap<String, Object>() {{
82+
put("genre", "NOVEL");
83+
}};
84+
85+
86+
String expected = "{Books={select=["
87+
+ "{id=2, title=War and Peace, genre=NOVEL}, "
88+
+ "{id=3, title=Anna Karenina, genre=NOVEL}"
89+
+ "]}}";
90+
91+
//when
92+
Object result = executor.execute(query, variables).getData();
93+
94+
// then
95+
assertThat(result.toString()).isEqualTo(expected);
96+
}
97+
98+
@Test
99+
public void queryEnumSimpleArrayVariableBinding() {
100+
//given
101+
String query = "query($genre: Genre) {" +
102+
" Books(where: {" +
103+
" genre: {IN: [$genre]}" +
104+
" }) {" +
105+
" select {" +
106+
" id" +
107+
" title" +
108+
" genre" +
109+
" }" +
110+
" }" +
111+
"}";
112+
113+
Map<String, Object> variables = new HashMap<String, Object>() {{
114+
put("genre", "NOVEL");
115+
}};
116+
117+
118+
String expected = "{Books={select=["
119+
+ "{id=2, title=War and Peace, genre=NOVEL}, "
120+
+ "{id=3, title=Anna Karenina, genre=NOVEL}"
121+
+ "]}}";
122+
123+
//when
124+
Object result = executor.execute(query, variables).getData();
125+
126+
// then
127+
assertThat(result.toString()).isEqualTo(expected);
128+
}
129+
130+
@Test
131+
public void queryEnumArrayVariableBindingInNestedRelation() {
132+
//given
133+
String query = "query($genres: [Genre!]) {" +
134+
" Authors(where: {" +
135+
" books: {" +
136+
" genre: {IN: $genres}" +
137+
" }" +
138+
" }) {" +
139+
" select {" +
140+
" id" +
141+
" name" +
142+
" books {" +
143+
" id" +
144+
" title" +
145+
" genre" +
146+
" }" +
147+
" }" +
148+
" }" +
149+
"}";
150+
151+
Map<String, Object> variables = new HashMap<String, Object>() {{
152+
put("genres", Arrays.asList("NOVEL"));
153+
}};
154+
155+
156+
String expected = "{Authors={select=[{"
157+
+ "id=1, name=Leo Tolstoy, books=["
158+
+ "{id=2, title=War and Peace, genre=NOVEL}, "
159+
+ "{id=3, title=Anna Karenina, genre=NOVEL}"
160+
+ "]}"
161+
+ "]}}";
162+
163+
//when
164+
Object result = executor.execute(query, variables).getData();
165+
166+
// then
167+
assertThat(result.toString()).isEqualTo(expected);
168+
}
169+
170+
@Test
171+
public void queryEnumArrayVariableBindingInEmbeddedRelation() {
172+
//given
173+
String query = "query($genres: [Genre!]) {" +
174+
" Authors {" +
175+
" select {" +
176+
" id" +
177+
" name" +
178+
" books(where: {" +
179+
" genre: {IN: $genres}" +
180+
" }) {" +
181+
" id" +
182+
" title" +
183+
" genre" +
184+
" }" +
185+
" }" +
186+
" } " +
187+
"}";
188+
189+
Map<String, Object> variables = new HashMap<String, Object>() {{
190+
put("genres", Arrays.asList("NOVEL"));
191+
}};
192+
193+
194+
String expected = "{Authors={select=["
195+
+ "{id=1, name=Leo Tolstoy, books=["
196+
+ "{id=2, title=War and Peace, genre=NOVEL}, "
197+
+ "{id=3, title=Anna Karenina, genre=NOVEL}"
198+
+ "]}, "
199+
+ "{id=4, name=Anton Chekhov, books=[]}"
200+
+ "]}}";
201+
202+
//when
203+
Object result = executor.execute(query, variables).getData();
204+
205+
// then
206+
assertThat(result.toString()).isEqualTo(expected);
207+
}
208+
}

graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/schema/StarwarsSchemaBuildTest.java

+9
Original file line numberDiff line numberDiff line change
@@ -182,5 +182,14 @@ public void correctlyDerivesSchemaDescriptionsFromGivenEntities() {
182182
.describedAs( "Ensure that CodeList.parent has the expected description")
183183
.isEqualTo("The CodeList's parent CodeList");
184184
}
185+
186+
@Test
187+
public void testBuildSchema(){
188+
//given
189+
GraphQLSchema schema = builder.build();
190+
191+
//then
192+
assertThat(schema).isNotNull();
193+
}
185194

186195
}

graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/schema/impl/IntrospectionUtilsTest.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ public void testNotTransientFields() throws Exception {
5050
assertThat(IntrospectionUtils.isTransient(entity, "info")).isFalse();
5151
assertThat(IntrospectionUtils.isTransient(entity, "title")).isFalse();
5252
}
53-
54-
53+
54+
@Test
55+
public void testByPassSetMethod() throws Exception {
56+
// given
57+
Class<CalculatedEntity> entity = CalculatedEntity.class;
58+
59+
// then
60+
assertThat(IntrospectionUtils.isTransient(entity,"something")).isFalse();
61+
}
5562
}

graphql-jpa-query-schema/src/test/java/com/introproventures/graphql/jpa/query/schema/model/calculated/CalculatedEntity.java

+2
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,6 @@ public boolean isCustomLogic() {
4545
public String getHideFieldFunction() {
4646
return "getHideFieldFunction";
4747
}
48+
49+
public void setSomething(int a){}
4850
}

graphql-jpa-query-web/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<parent>
44
<groupId>com.introproventures</groupId>
55
<artifactId>graphql-jpa-query-build</artifactId>
6-
<version>0.3.18-SNAPSHOT</version>
6+
<version>0.3.20-SNAPSHOT</version>
77
<relativePath>../graphql-jpa-query-build</relativePath>
88
</parent>
99
<artifactId>graphql-jpa-query-web</artifactId>

0 commit comments

Comments
 (0)