32
32
import org .springframework .boot .autoconfigure .SpringBootApplication ;
33
33
import org .springframework .boot .test .context .SpringBootTest ;
34
34
import org .springframework .context .annotation .Bean ;
35
+ import org .springframework .transaction .PlatformTransactionManager ;
36
+ import org .springframework .transaction .support .TransactionTemplate ;
35
37
36
38
import com .introproventures .graphql .jpa .query .AbstractSpringBootTestSupport ;
37
39
import com .introproventures .graphql .jpa .query .schema .impl .GraphQLJpaExecutor ;
38
40
import com .introproventures .graphql .jpa .query .schema .impl .GraphQLJpaSchemaBuilder ;
39
41
import com .introproventures .graphql .jpa .query .schema .model .starwars .Character ;
40
42
import com .introproventures .graphql .jpa .query .schema .model .starwars .Droid ;
43
+ import com .introproventures .graphql .jpa .query .schema .model .starwars .Human ;
41
44
42
45
@ SpringBootTest
43
- @ Transactional
44
46
public class StarwarsQueryExecutorTests extends AbstractSpringBootTestSupport {
45
47
46
48
@ SpringBootApplication
@@ -66,6 +68,9 @@ public GraphQLSchemaBuilder graphQLSchemaBuilder(final EntityManager entityManag
66
68
67
69
@ Autowired
68
70
private EntityManager em ;
71
+
72
+ @ Autowired
73
+ private PlatformTransactionManager txManager ;
69
74
70
75
@ Test
71
76
public void contextLoads () {
@@ -2118,4 +2123,86 @@ public void queryWithInLineExplicitOptionalFalseForSingularAttributeAndWhereSear
2118
2123
assertThat (result .toString ()).isEqualTo (expected );
2119
2124
}
2120
2125
2126
+ // https://github.com/introproventures/graphql-jpa-query/issues/273
2127
+ @ Test
2128
+ public void testGH273Plural () {
2129
+
2130
+ //given:
2131
+ String query = "{" +
2132
+ " Humans(where: {id: {EQ: \" 1000\" }}) {" +
2133
+ " select {" +
2134
+ " id" +
2135
+ " name" +
2136
+ " }" +
2137
+ " }" +
2138
+ "}" ;
2139
+
2140
+ // given
2141
+ new TransactionTemplate (txManager ).executeWithoutResult ((txStatus ) -> {
2142
+ Object result = executor .execute (query ).getData ();
2143
+
2144
+ String expected = "{Humans={select=[{id=1000, name=Luke Skywalker}]}}" ;
2145
+
2146
+ assertThat (result .toString ()).isEqualTo (expected );
2147
+
2148
+ Human human = em .find (Human .class , "1000" );
2149
+
2150
+ human .setName ("Luky Skywalker" );
2151
+ });
2152
+
2153
+ // when
2154
+ new TransactionTemplate (txManager ).executeWithoutResult ((txStatus ) -> {
2155
+ // then
2156
+ Object result = executor .execute (query ).getData ();
2157
+
2158
+ String updated = "{Humans={select=[{id=1000, name=Luky Skywalker}]}}" ;;
2159
+
2160
+ assertThat (result .toString ()).isEqualTo (updated );
2161
+
2162
+ Human human = em .find (Human .class , "1000" );
2163
+
2164
+ human .setName ("Luke Skywalker" );
2165
+ });
2166
+ }
2167
+
2168
+ // https://github.com/introproventures/graphql-jpa-query/issues/273
2169
+ @ Test
2170
+ public void testGH273Singular () {
2171
+
2172
+ //given:
2173
+ String query = "{" +
2174
+ " Human(id: \" 1000\" ) {" +
2175
+ " id" +
2176
+ " name" +
2177
+ " }" +
2178
+ " " +
2179
+ "}" ;
2180
+
2181
+ // given
2182
+ new TransactionTemplate (txManager ).executeWithoutResult ((txStatus ) -> {
2183
+ Object result = executor .execute (query ).getData ();
2184
+
2185
+ String expected = "{Human={id=1000, name=Luke Skywalker}}" ;
2186
+
2187
+ assertThat (result .toString ()).isEqualTo (expected );
2188
+
2189
+ Human human = em .find (Human .class , "1000" );
2190
+
2191
+ human .setName ("Luky Skywalker" );
2192
+ });
2193
+
2194
+ // when
2195
+ new TransactionTemplate (txManager ).executeWithoutResult ((txStatus ) -> {
2196
+ // then
2197
+ Object result = executor .execute (query ).getData ();
2198
+
2199
+ String updated = "{Human={id=1000, name=Luky Skywalker}}" ;
2200
+
2201
+ assertThat (result .toString ()).isEqualTo (updated );
2202
+
2203
+ Human human = em .find (Human .class , "1000" );
2204
+
2205
+ human .setName ("Luke Skywalker" );
2206
+ });
2207
+ }
2121
2208
}
0 commit comments