@@ -108,8 +108,8 @@ LIMIT 100
108108 ) AS subq5
109109 " ;
110110
111- string expected = await GetGraphQLResultAsync ( graphQLQuery , graphQLQueryName ) ;
112- string actual = await GetDatabaseResultAsync ( postgresQuery ) ;
111+ string actual = await GetGraphQLResultAsync ( graphQLQuery , graphQLQueryName ) ;
112+ string expected = await GetDatabaseResultAsync ( postgresQuery ) ;
113113
114114 SqlTestHelper . PerformTestEqualJsonStrings ( expected , actual ) ;
115115 }
@@ -205,6 +205,73 @@ LIMIT 100
205205 SqlTestHelper . PerformTestEqualJsonStrings ( expected , actual ) ;
206206 }
207207
208+ [ TestMethod ]
209+ public async Task QueryWithSingleColumnPrimaryKey ( )
210+ {
211+ string graphQLQueryName = "getBook" ;
212+ string graphQLQuery = @"{
213+ getBook(id: 2) {
214+ title
215+ }
216+ }" ;
217+ string postgresQuery = @"
218+ SELECT to_jsonb(subq) AS data
219+ FROM (
220+ SELECT table0.title AS title
221+ FROM books AS table0
222+ WHERE id = 2
223+ ORDER BY id
224+ LIMIT 1
225+ ) AS subq
226+ " ;
227+
228+ string actual = await GetGraphQLResultAsync ( graphQLQuery , graphQLQueryName ) ;
229+ string expected = await GetDatabaseResultAsync ( postgresQuery ) ;
230+
231+ SqlTestHelper . PerformTestEqualJsonStrings ( expected , actual ) ;
232+ }
233+
234+ [ TestMethod ]
235+ public async Task QueryWithMultileColumnPrimaryKey ( )
236+ {
237+ string graphQLQueryName = "getReview" ;
238+ string graphQLQuery = @"{
239+ getReview(id: 568, book_id: 1) {
240+ content
241+ }
242+ }" ;
243+ string postgresQuery = @"
244+ SELECT to_jsonb(subq) AS data
245+ FROM (
246+ SELECT table0.content AS content
247+ FROM reviews AS table0
248+ WHERE id = 568 AND book_id = 1
249+ ORDER BY id, book_id
250+ LIMIT 1
251+ ) AS subq
252+ " ;
253+
254+ string actual = await GetGraphQLResultAsync ( graphQLQuery , graphQLQueryName ) ;
255+ string expected = await GetDatabaseResultAsync ( postgresQuery ) ;
256+
257+ SqlTestHelper . PerformTestEqualJsonStrings ( expected , actual ) ;
258+ }
259+
260+ [ TestMethod ]
261+ public async Task QueryWithNullResult ( )
262+ {
263+ string graphQLQueryName = "getBook" ;
264+ string graphQLQuery = @"{
265+ getBook(id: -9999) {
266+ title
267+ }
268+ }" ;
269+
270+ string actual = await GetGraphQLResultAsync ( graphQLQuery , graphQLQueryName ) ;
271+
272+ SqlTestHelper . PerformTestEqualJsonStrings ( "null" , actual ) ;
273+ }
274+
208275 #endregion
209276
210277 #region Query Test Helper Functions
@@ -228,7 +295,9 @@ public static async Task<string> GetGraphQLResultAsync(string graphQLQuery, stri
228295 JsonDocument graphQLResult = await _graphQLController . PostAsync ( ) ;
229296 Console . WriteLine ( graphQLResult . RootElement . ToString ( ) ) ;
230297 JsonElement graphQLResultData = graphQLResult . RootElement . GetProperty ( "data" ) . GetProperty ( graphQLQueryName ) ;
231- return graphQLResultData . ToString ( ) ;
298+
299+ // JsonElement.ToString() prints null values as empty strings instead of "null"
300+ return graphQLResultData . GetRawText ( ) ;
232301 }
233302
234303 #endregion
0 commit comments