Skip to content
13 changes: 13 additions & 0 deletions src/Core/Resolvers/QueryExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,12 @@ internal int StreamCharData(DbDataReader dbDataReader, long availableSize, Strin
// else we throw exception.
ValidateSize(availableSize, resultFieldSize);

// If the cell is empty, don't append anything to the resultJsonString and return 0.
if (resultFieldSize == 0)
{
return 0;
}

char[] buffer = new char[resultFieldSize];

// read entire field into buffer and reduce available size.
Expand All @@ -766,6 +772,13 @@ internal int StreamByteData(DbDataReader dbDataReader, long availableSize, int o
// else we throw exception.
ValidateSize(availableSize, resultFieldSize);

// If the cell is empty, set resultBytes to an empty array and return 0.
if (resultFieldSize == 0)
{
resultBytes = Array.Empty<byte>();
return 0;
}

resultBytes = new byte[resultFieldSize];

dbDataReader.GetBytes(ordinal: ordinal, dataOffset: 0, buffer: resultBytes, bufferOffset: 0, length: resultBytes.Length);
Expand Down
3 changes: 2 additions & 1 deletion src/Service.Tests/DatabaseSchema-MsSql.sql
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,8 @@ VALUES (1, 'Awesome book', 1234),
(17, 'CONN%_CONN', 1234),
(18, '[Special Book]', 1234),
(19, 'ME\YOU', 1234),
(20, 'C:\\LIFE', 1234);
(20, 'C:\\LIFE', 1234),
(21, '', 1234);
SET IDENTITY_INSERT books OFF

SET IDENTITY_INSERT books_mm ON
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public async Task TestStoredProcedureMutationForInsertion(string dbQuery)
/// <code>Check: </code> If the intended book is deleted from the DB and
/// verifies the response.
/// </summary>
public async Task TestStoredProcedureMutationForDeletion(string dbQueryToVerifyDeletion)
public async Task TestStoredProcedureMutationForDeletion(string dbQueryToVerifyDeletion, int expectedOriginalMaxId, int expectedFinalMaxId)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Touching existing tests might be hard to track. It might be useful to keep the tests and the concerns separate

{
string graphQLMutationName = "executeDeleteLastInsertedBook";
string graphQLMutation = @"
Expand All @@ -257,7 +257,7 @@ public async Task TestStoredProcedureMutationForDeletion(string dbQueryToVerifyD

string currentDbResponse = await GetDatabaseResultAsync(dbQueryToVerifyDeletion);
JsonDocument currentResult = JsonDocument.Parse(currentDbResponse);
Assert.AreEqual(currentResult.RootElement.GetProperty("maxId").GetInt64(), 20);
Assert.AreEqual(currentResult.RootElement.GetProperty("maxId").GetInt64(), expectedOriginalMaxId);
JsonElement graphQLResponse = await ExecuteGraphQLRequestAsync(graphQLMutation, graphQLMutationName, isAuthenticated: true);

// Stored Procedure didn't return anything
Expand All @@ -266,7 +266,7 @@ public async Task TestStoredProcedureMutationForDeletion(string dbQueryToVerifyD
// check to verify new element is inserted
string updatedDbResponse = await GetDatabaseResultAsync(dbQueryToVerifyDeletion);
JsonDocument updatedResult = JsonDocument.Parse(updatedDbResponse);
Assert.AreEqual(updatedResult.RootElement.GetProperty("maxId").GetInt64(), 19);
Assert.AreEqual(updatedResult.RootElement.GetProperty("maxId").GetInt64(), expectedFinalMaxId);
}

public async Task InsertMutationOnTableWithTriggerWithNonAutoGenPK(string dbQuery)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ FROM [books] AS [table0]
WITHOUT_ARRAY_WRAPPER
";

await TestStoredProcedureMutationForDeletion(dbQueryToVerifyDeletion);
await TestStoredProcedureMutationForDeletion(dbQueryToVerifyDeletion, 21, 20);
}

/// <summary>
Expand Down
Loading
Loading