Skip to content

Commit

Permalink
Merge pull request #112 from modersohn/fix/TransactionsQueryWithNonHo…
Browse files Browse the repository at this point in the history
…stedGraph

Fix Invalid query error when using non-hosted graph
  • Loading branch information
fudgebucket27 authored Apr 20, 2022
2 parents 8a6274b + 6b16378 commit 5dfefad
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Lexplorer/Pages/BlockDetails.razor
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
isTransactionLoading = true;
string transactionDatacacheKey = $"blockDetailTransactions-{blockId}-page{gotoPage}";
var transactionData = await AppCache.GetOrAddAsyncNonNull(transactionDatacacheKey,
async () => await LoopringGraphQLService.GetTransactions((gotoPage - 1) * pageSize, pageSize, blockNumber, cancellationToken: localCTS.Token),
async () => await LoopringGraphQLService.GetTransactions((gotoPage - 1) * pageSize, pageSize, blockId: blockNumber, cancellationToken: localCTS.Token),
DateTimeOffset.UtcNow.AddMinutes(5));
transactions = transactionData?.data?.transactions ?? new List<Transaction>();
isTransactionLoading = false;
Expand Down
16 changes: 10 additions & 6 deletions Shared/Services/LoopringGraphQLService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ query transactions(
$orderBy: Transaction_orderBy
$orderDirection: OrderDirection
$block: Block_height
$where: Transaction_filter
$whereFilter: Transaction_filter
) {
proxy(id: 0) {
transactionCount
Expand All @@ -334,7 +334,7 @@ query transactions(
orderBy: $orderBy
orderDirection: $orderDirection
block: $block
where: $where
where: $whereFilter
) {
id
internalID
Expand Down Expand Up @@ -415,7 +415,7 @@ query transactions(
orderBy = "internalID",
orderDirection = "desc"
,
where = new
whereFilter = new
{
block = blockId
}
Expand All @@ -432,9 +432,8 @@ query transactions(
skip = skip,
first = first,
orderBy = "internalID",
orderDirection = "desc"
,
where = new
orderDirection = "desc",
whereFilter = new
{
typename = typeName
}
Expand All @@ -443,6 +442,11 @@ query transactions(
}
else
{
//remove unused parameter to fix "Invalid query" error with non-hosted graph
//split and re-join all lines which don't contain the word "whereFilter"
transactionsQuery = String.Join(Environment.NewLine,
transactionsQuery.Split(Environment.NewLine).Where(
(a) => !(a.Contains("whereFilter"))));
request.AddJsonBody(new
{
query = transactionsQuery,
Expand Down
26 changes: 26 additions & 0 deletions xUnitTests/LoopringGraphTests/TestTransaction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,32 @@ public async void TestGetTransaction()
Assert.NotNull(transaction);
Assert.Equal(testID, transaction!.id);
}

[Theory]
[InlineData(null)]
[InlineData("Swap")]
public async void TestGetTransations(string? typeName)
{
var transactions = await service.GetTransactions(0, 5, typeName: typeName);
Assert.NotNull(transactions);
Assert.NotEmpty(transactions?.data?.transactions);
if (!String.IsNullOrEmpty(typeName))
{
foreach (var transaction in transactions?.data?.transactions!)
{
Assert.Equal(typeName, transaction.typeName);
}
}
}

[Theory]
[InlineData("19527")]
public async void TestGetBlockTransations(string? blockId)
{
var transactions = await service.GetTransactions(0, 5, blockId: blockId);
Assert.NotNull(transactions);
Assert.NotEmpty(transactions?.data?.transactions);
}
}
}

0 comments on commit 5dfefad

Please sign in to comment.